Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/AccentedAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/AccentedAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/AccentedAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,209 @@ +/* AccentedAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing another atom with an accent symbol above it. + */ +public class AccentedAtom extends Atom { + + // accent symbol + private final SymbolAtom accent; + private boolean acc = false; + private boolean changeSize = true; + + // base atom + protected Atom base = null; + protected Atom underbase = null; + + public AccentedAtom(Atom base, Atom accent) throws InvalidSymbolTypeException { + this.base = base; + if (base instanceof AccentedAtom) + underbase = ((AccentedAtom)base).underbase; + else + underbase = base; + + if (!(accent instanceof SymbolAtom)) + throw new InvalidSymbolTypeException("Invalid accent"); + + this.accent = (SymbolAtom)accent; + this.acc = true; + } + + public AccentedAtom(Atom base, Atom accent, boolean changeSize) throws InvalidSymbolTypeException { + this(base, accent); + this.changeSize = changeSize; + } + + /** + * Creates an AccentedAtom from a base atom and an accent symbol defined by its name + * + * @param base base atom + * @param accentName name of the accent symbol to be put over the base atom + * @throws InvalidSymbolTypeException if the symbol is not defined as an accent ('acc') + * @throws SymbolNotFoundException if there's no symbol defined with the given name + */ + public AccentedAtom(Atom base, String accentName) + throws InvalidSymbolTypeException, SymbolNotFoundException { + accent = SymbolAtom.get(accentName); + if (accent.type == TeXConstants.TYPE_ACCENT) { + this.base = base; + if (base instanceof AccentedAtom) + underbase = ((AccentedAtom)base).underbase; + else + underbase = base; + } + else + throw new InvalidSymbolTypeException("The symbol with the name '" + + accentName + "' is not defined as an accent (" + + TeXSymbolParser.TYPE_ATTR + "='acc') in '" + + TeXSymbolParser.RESOURCE_NAME + "'!"); + } + + /** + * Creates an AccentedAtom from a base atom and an accent symbol defined as a TeXFormula. + * This is used for parsing MathML. + * + * @param base base atom + * @param acc TeXFormula representing an accent (SymbolAtom) + * @throws InvalidTeXFormulaException if the given TeXFormula does not represent a + * single SymbolAtom (type "TeXConstants.TYPE_ACCENT") + * @throws InvalidSymbolTypeException if the symbol is not defined as an accent ('acc') + */ + public AccentedAtom(Atom base, TeXFormula acc) + throws InvalidTeXFormulaException, InvalidSymbolTypeException { + if (acc == null) + throw new InvalidTeXFormulaException( + "The accent TeXFormula can't be null!"); + else { + Atom root = acc.root; + if (root instanceof SymbolAtom) { + accent = (SymbolAtom) root; + if (accent.type == TeXConstants.TYPE_ACCENT) + this.base = base; + else + throw new InvalidSymbolTypeException( + "The accent TeXFormula represents a single symbol with the name '" + + accent.getName() + + "', but this symbol is not defined as an accent (" + + TeXSymbolParser.TYPE_ATTR + "='acc') in '" + + TeXSymbolParser.RESOURCE_NAME + "'!"); + } else + throw new InvalidTeXFormulaException( + "The accent TeXFormula does not represent a single symbol!"); + } + } + + public Box createBox(TeXEnvironment env) { + TeXFont tf = env.getTeXFont(); + int style = env.getStyle(); + + // set base in cramped style + Box b = (base == null ? new StrutBox(0, 0, 0, 0) : base.createBox(env.crampStyle())); + + float u = b.getWidth(); + float s = 0; + if (underbase instanceof CharSymbol) + s = tf.getSkew(((CharSymbol) underbase).getCharFont(tf), style); + + // retrieve best Char from the accent symbol + Char ch = tf.getChar(accent.getName(), style); + while (tf.hasNextLarger(ch)) { + Char larger = tf.getNextLarger(ch, style); + if (larger.getWidth() <= u) + ch = larger; + else + break; + } + + // calculate delta + float ec = -SpaceAtom.getFactor(TeXConstants.UNIT_MU, env); + float delta = acc ? ec : Math.min(b.getHeight(), tf.getXHeight(style, ch.getFontCode())); + + // create vertical box + VerticalBox vBox = new VerticalBox(); + + // accent + Box y; + float italic = ch.getItalic(); + Box cb = new CharBox(ch); + if (acc) + cb = accent.createBox(changeSize ? env.subStyle() : env); + + if (Math.abs(italic) > TeXFormula.PREC) { + y = new HorizontalBox(new StrutBox(-italic, 0, 0, 0)); + y.add(cb); + } else + y = cb; + + // if diff > 0, center accent, otherwise center base + float diff = (u - y.getWidth()) / 2; + y.setShift(s + (diff > 0 ? diff : 0)); + if (diff < 0) + b = new HorizontalBox(b, y.getWidth(), TeXConstants.ALIGN_CENTER); + vBox.add(y); + + // kern + vBox.add(new StrutBox(0, changeSize ? -delta : -b.getHeight(), 0, 0)); + // base + vBox.add(b); + + // set height and depth vertical box + float total = vBox.getHeight() + vBox.getDepth(), d = b.getDepth(); + vBox.setDepth(d); + vBox.setHeight(total - d); + + if (diff < 0) { + HorizontalBox hb = new HorizontalBox(new StrutBox(diff, 0, 0, 0)); + hb.add(vBox); + hb.setWidth(u); + return hb; + } + + return vBox; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/AlphabetRegistration.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/AlphabetRegistration.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/AlphabetRegistration.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,60 @@ +/* AlphabetRegistration.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.lang.Character.UnicodeBlock; + +public interface AlphabetRegistration { + + public static final Character.UnicodeBlock[] JLM_GREEK = new Character.UnicodeBlock[]{Character.UnicodeBlock.GREEK, Character.UnicodeBlock.GREEK_EXTENDED}; + public static final Character.UnicodeBlock[] JLM_CYRILLIC = new Character.UnicodeBlock[]{Character.UnicodeBlock.CYRILLIC}; + + public Character.UnicodeBlock[] getUnicodeBlock(); + + public Object getPackage() throws AlphabetRegistrationException; + + public String getTeXFontFileName(); +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/AlphabetRegistrationException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/AlphabetRegistrationException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/AlphabetRegistrationException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,56 @@ +/* AlphabetRegistrationException.java + * ========================================================================= + * This file is originally of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals that an error occured while registering an alphabet + */ +public class AlphabetRegistrationException extends Exception { + + protected AlphabetRegistrationException(String str) { + super(str); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ArrayOfAtoms.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ArrayOfAtoms.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ArrayOfAtoms.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,130 @@ +/* ArrayOfAtoms.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009-2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.util.BitSet; +import java.util.Map; +import java.util.LinkedList; + +public class ArrayOfAtoms extends TeXFormula { + + public LinkedList> array; + public int col, row; + + public ArrayOfAtoms() { + super(); + array = new LinkedList>(); + array.add(new LinkedList()); + row = 0; + } + + public void addCol() { + array.get(row).add(root); + root = null; + } + + public void addCol(int n) { + array.get(row).add(root); + for (int i = 1; i < n - 1; i++) { + array.get(row).add(null); + } + root = null; + } + + public void addRow() { + addCol(); + array.add(new LinkedList()); + row++; + } + + public int getRows() { + return row; + } + + public int getCols() { + return col; + } + + public VRowAtom getAsVRow() { + VRowAtom vr = new VRowAtom(); + vr.setAddInterline(true); + for (LinkedList r : array) { + for (Atom a : r) { + vr.append(a); + } + } + + return vr; + } + + public void checkDimensions() { + if (array.getLast().size() != 0) + addRow(); + else if (root != null) + addRow(); + + row = array.size() - 1; + col = array.get(0).size(); + + for (int i = 1; i < row; i++) { + if (array.get(i).size() > col) { + col = array.get(i).size(); + } + } + + /* Thanks to Juan Enrique Escobar Robles for this patch + which let the user have empty columns */ + for (int i = 0; i < row; i++) { + int j = array.get(i).size(); + if (j != col && array.get(i).get(0) != null && array.get(i).get(0).type != TeXConstants.TYPE_INTERTEXT) { + LinkedList r = array.get(i); + for(; j < col; j++) { + r.add(null); + } + } + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Atom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Atom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Atom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,120 @@ +/* Atom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet */ + +package org.scilab.forge.jlatexmath; + +/** + * An abstract superclass for all logical mathematical constructions that can be + * a part of a TeXFormula. All subclasses must implement the abstract + * {@link #createBox(TeXEnvironment)} method that transforms this logical unit into + * a concrete box (that can be painted). They also must define their type, used for + * determining what glue to use between adjacent atoms in a "row construction". That can + * be one single type by asigning one of the type constants to the {@link #type} field. + * But they can also be defined as having two types: a "left type" and a "right type". + * This can be done by implementing the methods {@link #getLeftType()} and + * {@link #getRightType()}. + * The left type will then be used for determining the glue between this atom and the + * previous one (in a row, if any) and the right type for the glue between this atom and + * the following one (in a row, if any). + * + * @author Kurt Vermeulen + */ +public abstract class Atom implements Cloneable { + + /** + * The type of the atom (default value: ordinary atom) + */ + public int type = TeXConstants.TYPE_ORDINARY; + + public int type_limits = TeXConstants.SCRIPT_NOLIMITS; + + public int alignment = -1; + + /** + * Convert this atom into a {@link Box}, using properties set by "parent" + * atoms, like the TeX style, the last used font, color settings, ... + * + * @param env the current environment settings + * @return the resulting box. + */ + public abstract Box createBox(TeXEnvironment env); + + /** + * Get the type of the leftermost child atom. Most atoms have no child atoms, + * so the "left type" and the "right type" are the same: the atom's type. This + * also is the default implementation. + * But Some atoms are composed of child atoms put one after another in a + * horizontal row. These atoms must override this method. + * + * @return the type of the leftermost child atom + */ + public int getLeftType() { + return type; + } + + /** + * Get the type of the rightermost child atom. Most atoms have no child atoms, + * so the "left type" and the "right type" are the same: the atom's type. This + * also is the default implementation. + * But Some atoms are composed of child atoms put one after another in a + * horizontal row. These atoms must override this method. + * + * @return the type of the rightermost child atom + */ + public int getRightType() { + return type; + } + + public Atom clone() { + try { + return (Atom)super.clone(); + } catch (Exception e) { + return null; + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BigDelimiterAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BigDelimiterAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BigDelimiterAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,71 @@ +/* BigDelimiterAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a big delimiter (for left and right commands). + */ +public class BigDelimiterAtom extends Atom { + + public SymbolAtom delim; + private int size; + + public BigDelimiterAtom(SymbolAtom delim, int size) { + this.delim = delim; + this.size = size; + } + + public Box createBox(TeXEnvironment env) { + Box b = DelimiterFactory.create(delim, env, size); + HorizontalBox hbox = new HorizontalBox(); + final float h = b.getHeight(); + final float total = h + b.getDepth(); + final float axis = env.getTeXFont().getAxisHeight(env.getStyle()); + b.setShift(-total / 2 + h - axis); + hbox.add(b); + return hbox; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BigOperatorAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BigOperatorAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BigOperatorAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,224 @@ +/* BigOperatorAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a "big operator" (or an atom that acts as one) together + * with its limits. + */ +public class BigOperatorAtom extends Atom { + + // limits + private Atom under = null, over = null; + + // atom representing a big operator + protected Atom base = null; + + // whether the "limits"-value should be taken into account + // (otherwise the default rules will be applied) + private boolean limitsSet = false; + + // whether limits should be drawn over and under the base (<-> as scripts) + private boolean limits = false; + + /** + * Creates a new BigOperatorAtom from the given atoms. + * The default rules the positioning of the limits will be applied. + * + * @param base atom representing the big operator + * @param under atom representing the under limit + * @param over atom representing the over limit + */ + public BigOperatorAtom(Atom base, Atom under, Atom over) { + this.base = base; + this.under = under; + this.over = over; + type = TeXConstants.TYPE_BIG_OPERATOR; + } + + /** + * Creates a new BigOperatorAtom from the given atoms. + * Limits will be drawn according to the "limits"-value + * + * @param base atom representing the big operator + * @param under atom representing the under limit + * @param over atom representing the over limit + * @param limits whether limits should be drawn over and under the base (<-> as scripts) + */ + public BigOperatorAtom(Atom base, Atom under, Atom over, boolean limits) { + this(base, under, over); + this.limits = limits; + limitsSet = true; + } + + public Box createBox(TeXEnvironment env) { + TeXFont tf = env.getTeXFont(); + int style = env.getStyle(); + + Box y; + float delta; + + RowAtom bbase = null; + Atom Base = base; + if (base instanceof TypedAtom) { + Atom at = ((TypedAtom)base).getBase(); + if (at instanceof RowAtom && ((RowAtom)at).lookAtLastAtom && base.type_limits != TeXConstants.SCRIPT_LIMITS) { + base = ((RowAtom)at).getLastAtom(); + bbase = (RowAtom)at; + } + else + base = at; + } + + if ((limitsSet && !limits) + || (!limitsSet && style >= TeXConstants.STYLE_TEXT) + || (base.type_limits == TeXConstants.SCRIPT_NOLIMITS) + || (base.type_limits == TeXConstants.SCRIPT_NORMAL && style >= TeXConstants.STYLE_TEXT)) { + // if explicitly set to not display as limits or if not set and style + // is not display, then attach over and under as regular sub- en + // superscript + if (bbase != null) { + bbase.add(new ScriptsAtom(base, under, over)); + Box b = bbase.createBox(env); + bbase.getLastAtom(); + bbase.add(base); + base = Base; + return b; + } + return new ScriptsAtom(base, under, over).createBox(env); + } else { + if (base instanceof SymbolAtom + && base.type == TeXConstants.TYPE_BIG_OPERATOR) { // single + // bigop + // symbol + Char c = tf.getChar(((SymbolAtom) base).getName(), style); + y = base.createBox(env); + + // include delta in width + delta = c.getItalic(); + } else { // formula + delta = 0; + y = new HorizontalBox(base == null ? new StrutBox(0, 0, 0, 0) + : base.createBox(env)); + } + + // limits + Box x = null, z = null; + if (over != null) + x = over.createBox(env.supStyle()); + if (under != null) + z = under.createBox(env.subStyle()); + + // make boxes equally wide + float maxWidth = Math.max(Math.max(x == null ? 0 : x.getWidth(), y + .getWidth()), z == null ? 0 : z.getWidth()); + x = changeWidth(x, maxWidth); + y = changeWidth(y, maxWidth); + z = changeWidth(z, maxWidth); + + // build vertical box + VerticalBox vBox = new VerticalBox(); + + float bigop5 = tf.getBigOpSpacing5(style), kern = 0; + float xh = 0; // TODO: check why this is not used // NOPMD + + // over + if (over != null) { + vBox.add(new StrutBox(0, bigop5, 0, 0)); + x.setShift(delta / 2); + vBox.add(x); + kern = Math.max(tf.getBigOpSpacing1(style), tf + .getBigOpSpacing3(style) + - x.getDepth()); + vBox.add(new StrutBox(0, kern, 0, 0)); + xh = vBox.getHeight() + vBox.getDepth(); + } + + // base + vBox.add(y); + + // under + if (under != null) { + float k = Math.max(tf.getBigOpSpacing2(style), tf + .getBigOpSpacing4(style) + - z.getHeight()); + vBox.add(new StrutBox(0, k, 0, 0)); + z.setShift(-delta / 2); + vBox.add(z); + vBox.add(new StrutBox(0, bigop5, 0, 0)); + } + + // set height and depth vertical box and return it + float h = y.getHeight(), total = vBox.getHeight() + vBox.getDepth(); + if (x != null) + h += bigop5 + kern + x.getHeight() + x.getDepth(); + vBox.setHeight(h); + vBox.setDepth(total - h); + + if (bbase != null) { + HorizontalBox hb = new HorizontalBox(bbase.createBox(env));bbase.add(base); + hb.add(vBox); + base = Base; + return hb; + } + + return vBox; + } + } + + /* + * Centers the given box in a new box that has the given width + */ + private static Box changeWidth(Box b, float maxWidth) { + if (b != null && Math.abs(maxWidth - b.getWidth()) > TeXFormula.PREC) + return new HorizontalBox(b, maxWidth, TeXConstants.ALIGN_CENTER); + else + return b; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BoldAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BoldAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BoldAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,71 @@ +/* BoldAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a bold atom. + */ +public class BoldAtom extends Atom { + + private Atom base; + + public BoldAtom(Atom base) { + this.base = base; + } + + public Box createBox(TeXEnvironment env) { + Box box; + if (base != null) { + env = env.copy(env.getTeXFont().copy()); + env.getTeXFont().setBold(true); + box = base.createBox(env); + } else { + box = new StrutBox(0, 0, 0, 0); + } + + return box; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Box.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Box.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Box.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,350 @@ +/* Box.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; +import java.awt.Stroke; +import java.awt.BasicStroke; +import java.util.LinkedList; +import java.util.List; + +/** + * An abstract graphical representation of a formula, that can be painted. All characters, font + * sizes, positions are fixed. Only special Glue boxes could possibly stretch or shrink. + * A box has 3 dimensions (width, height and depth), can be composed of other child boxes + * that can possibly be shifted (up, down, left or right). Child boxes can also be positioned + * outside their parent's box (defined by it's dimensions). + *

+ * Subclasses must implement the abstract {@link #draw(Graphics2D, float, float)} method + * (that paints the box). This implementation must start with calling the method + * {@link #startDraw(Graphics2D, float, float)} and end with calling the method + * {@link #endDraw(Graphics2D)} to set and restore the color's that must be used for + * painting the box and to draw the background! They must also implement the abstract + * {@link #getLastFontId()} method (the last font + * that will be used when this box will be painted). + */ +public abstract class Box { + + public static boolean DEBUG = false; + + /** + * The foreground color of the whole box. Child boxes can override this color. + * If it's null and it has a parent box, the foreground color of the parent will + * be used. If it has no parent, the foreground color of the component on which it + * will be painted, will be used. + */ + protected Color foreground; + + /** + * The background color of the whole box. Child boxes can paint a background on top of + * this background. If it's null, no background will be painted. + */ + protected Color background; + + private Color prevColor; // used temporarily in startDraw and endDraw + + /** + * The width of this box, i.e. the value that will be used for further + * calculations. + */ + protected float width = 0; + + /** + * The height of this box, i.e. the value that will be used for further + * calculations. + */ + protected float height = 0; + + /** + * The depth of this box, i.e. the value that will be used for further + * calculations. + */ + protected float depth = 0; + + /** + * The shift amount: the meaning depends on the particular kind of box + * (up, down, left, right) + */ + protected float shift = 0; + + protected int type = -1; + + /** + * List of child boxes + */ + protected LinkedList children = new LinkedList(); + protected Box parent; + protected Box elderParent; + protected Color markForDEBUG; + + /** + * Inserts the given box at the end of the list of child boxes. + * + * @param b the box to be inserted + */ + public void add(Box b) { + children.add(b); + b.parent = this; + b.elderParent = elderParent; + } + + /** + * Inserts the given box at the given position in the list of child boxes. + * + * @param pos the position at which to insert the given box + * @param b the box to be inserted + */ + public void add(int pos, Box b) { + children.add(pos, b); + b.parent = this; + b.elderParent = elderParent; + } + + /** + * Creates an empty box (no children) with all dimensions set to 0 and no + * foreground and background color set (default values will be used: null) + */ + protected Box() { + this(null, null); + } + + /** + * Creates an empty box (no children) with all dimensions set to 0 and sets + * the foreground and background color of the box. + * + * @param fg the foreground color + * @param bg the background color + */ + protected Box(Color fg, Color bg) { + foreground = fg; + background = bg; + } + + public void setParent(Box parent) { + this.parent = parent; + } + + public Box getParent() { + return parent; + } + + public void setElderParent(Box elderParent) { + this.elderParent = elderParent; + } + + public Box getElderParent() { + return elderParent; + } + + /** + * Get the width of this box. + * + * @return the width of this box + */ + public float getWidth() { + return width; + } + + public void negWidth() { + width = -width; + } + + /** + * Get the height of this box. + * + * @return the height of this box + */ + public float getHeight() { + return height; + } + + /** + * Get the depth of this box. + * + * @return the depth of this box + */ + public float getDepth() { + return depth; + } + + /** + * Get the shift amount for this box. + * + * @return the shift amount + */ + public float getShift() { + return shift; + } + + /** + * Set the width for this box. + * + * @param w the width + */ + public void setWidth(float w) { + width = w; + } + + /** + * Set the depth for this box. + * + * @param d the depth + */ + public void setDepth(float d) { + depth = d; + } + + /** + * Set the height for this box. + * + * @param h the height + */ + public void setHeight(float h) { + height = h; + } + + /** + * Set the shift amount for this box. + * + * @param s the shift amount + */ + public void setShift(float s) { + shift = s; + } + + /** + * Paints this box at the given coordinates using the given graphics context. + * + * @param g2 the graphics (2D) context to use for painting + * @param x the x-coordinate + * @param y the y-coordinate + */ + public abstract void draw(Graphics2D g2, float x, float y); + + /** + * Get the id of the font that will be used the last when this box will be painted. + * + * @return the id of the last font that will be used. + */ + public abstract int getLastFontId(); + + /** + * Stores the old color setting, draws the background of the box (if not null) + * and sets the foreground color (if not null). + * + * @param g2 the graphics (2D) context + * @param x the x-coordinate + * @param y the y-coordinate + */ + protected void startDraw(Graphics2D g2, float x, float y) { + // old color + prevColor = g2.getColor(); + if (background != null) { // draw background + g2.setColor(background); + g2.fill(new Rectangle2D.Float(x, y - height, width, height + depth)); + } + if (foreground == null) { + g2.setColor(prevColor); // old foreground color + } else { + g2.setColor(foreground); // overriding foreground color + } + drawDebug(g2, x, y); + } + + protected void drawDebug(Graphics2D g2, float x, float y, boolean showDepth) { + if (DEBUG) { + Stroke st = g2.getStroke(); + if (markForDEBUG != null) { + Color c = g2.getColor(); + g2.setColor(markForDEBUG); + g2.fill(new Rectangle2D.Float(x, y - height, width, height + depth)); + g2.setColor(c); + } + g2.setStroke(new BasicStroke((float) (Math.abs(1 / g2.getTransform().getScaleX())), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); + if (width < 0) { + x += width; + width = -width; + } + g2.draw(new Rectangle2D.Float(x, y - height, width, height + depth)); + if (showDepth) { + Color c = g2.getColor(); + g2.setColor(Color.RED); + if (depth > 0) { + g2.fill(new Rectangle2D.Float(x, y, width, depth)); + g2.setColor(c); + g2.draw(new Rectangle2D.Float(x, y, width, depth)); + } else if (depth < 0) { + g2.fill(new Rectangle2D.Float(x, y + depth, width, -depth)); + g2.setColor(c); + g2.draw(new Rectangle2D.Float(x, y + depth, width, -depth)); + } else { + g2.setColor(c); + } + } + g2.setStroke(st); + } + } + + protected void drawDebug(Graphics2D g2, float x, float y) { + if (DEBUG) { + drawDebug(g2, x, y, true); + } + } + + /** + * Restores the previous color setting. + * + * @param g2 the graphics (2D) context + */ + protected void endDraw(Graphics2D g2) { + g2.setColor(prevColor); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BreakFormula.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BreakFormula.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BreakFormula.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,164 @@ +/* BreakFormula.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2011 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.util.List; +import java.util.Stack; + +public final class BreakFormula { + + public static Box split(Box box, float width, float interline) { + if (box instanceof HorizontalBox) { + return split((HorizontalBox) box, width, interline); + } else if (box instanceof VerticalBox) { + return split((VerticalBox) box, width, interline); + } else { + return box; + } + } + + public static Box split(HorizontalBox hbox, float width, float interline) { + VerticalBox vbox = new VerticalBox(); + HorizontalBox first; + HorizontalBox second = null; + Stack positions = new Stack(); + float w = -1; + while (hbox.width > width && (w = canBreak(positions, hbox, width)) != hbox.width) { + Position pos = positions.pop(); + HorizontalBox[] hboxes = pos.hbox.split(pos.index - 1); + first = hboxes[0]; + second = hboxes[1]; + while (!positions.isEmpty()) { + pos = positions.pop(); + hboxes = pos.hbox.splitRemove(pos.index); + hboxes[0].add(first); + hboxes[1].add(0, second); + first = hboxes[0]; + second = hboxes[1]; + } + vbox.add(first, interline); + hbox = second; + } + + if (second != null) { + vbox.add(second, interline); + return vbox; + } + + return hbox; + } + + private static Box split(VerticalBox vbox, float width, float interline) { + VerticalBox newBox = new VerticalBox(); + for (Box box:vbox.children) { + newBox.add(split(box, width, interline)); + } + + return newBox; + } + + private static float canBreak(Stack stack, HorizontalBox hbox, float width) { + List children = hbox.children; + float[] cumWidth = new float[children.size() + 1]; + cumWidth[0] = 0; + for (int i = 0; i < children.size(); i++) { + Box box = children.get(i); + cumWidth[i + 1] = cumWidth[i] + box.width; + if (cumWidth[i + 1] > width) { + int pos = getBreakPosition(hbox, i); + if (box instanceof HorizontalBox) { + Stack newStack = new Stack(); + float w = canBreak(newStack, (HorizontalBox) box, width - cumWidth[i]); + if (w != box.width && (cumWidth[i] + w <= width || pos == -1)) { + stack.push(new Position(i - 1, hbox)); + stack.addAll(newStack); + return cumWidth[i] + w; + } + } + + if (pos != -1) { + stack.push(new Position(pos, hbox)); + return cumWidth[pos]; + } + } + } + + return hbox.width; + } + + private static int getBreakPosition(HorizontalBox hb, int i) { + if (hb.breakPositions == null) { + return -1; + } + + if (hb.breakPositions.size() == 1 && hb.breakPositions.get(0) <= i) { + return hb.breakPositions.get(0); + } + + int pos = 0; + for (; pos < hb.breakPositions.size(); pos++) { + if (hb.breakPositions.get(pos) > i) { + if (pos == 0) { + return -1; + } + return hb.breakPositions.get(pos - 1); + } + } + + return hb.breakPositions.get(pos - 1); + } + + private static class Position { + + int index; + HorizontalBox hbox; + + Position(int index, HorizontalBox hbox) { + this.index = index; + this.hbox = hbox; + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BreakMarkAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BreakMarkAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/BreakMarkAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,58 @@ +/* BreakMarkAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An empty atom just to add a mark. + */ +public class BreakMarkAtom extends Atom { + + public BreakMarkAtom() { } + + public Box createBox(TeXEnvironment env) { + return new StrutBox(0, 0, 0, 0); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CedillaAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CedillaAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CedillaAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,83 @@ +/* CedillaAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom with a cedilla. + */ +public class CedillaAtom extends Atom { + + private Atom base; + + public CedillaAtom(Atom base) { + this.base = base; + } + + public Box createBox(TeXEnvironment env) { + Box b = base.createBox(env); + VerticalBox vb = new VerticalBox(); + vb.add(b); + Char ch = env.getTeXFont().getChar("jlatexmathcedilla", env.getStyle()); + float italic = ch.getItalic(); + Box cedilla = new CharBox(ch); + Box y; + if (Math.abs(italic) > TeXFormula.PREC) { + y = new HorizontalBox(new StrutBox(-italic, 0, 0, 0)); + y.add(cedilla); + } else { + y = cedilla; + } + + Box ce = new HorizontalBox(y, b.getWidth(), TeXConstants.ALIGN_CENTER); + float x = 0.4f * SpaceAtom.getFactor(TeXConstants.UNIT_MU, env); + vb.add(new StrutBox(0, -x, 0, 0)); + vb.add(ce); + float f = vb.getHeight() + vb.getDepth(); + vb.setHeight(b.getHeight()); + vb.setDepth(f - b.getHeight()); + return vb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Char.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Char.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Char.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,103 @@ +/* Char.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Font; + +/** + * Represents a character together with its font, font ID and metric information. + */ +public class Char { + + private final char c; + private final Font font; + private final Metrics m; + private final int fontCode; + + public Char(char c, Font f, int fc, Metrics m) { + font = f; + fontCode = fc; + this.c = c; + this.m = m; + } + + public CharFont getCharFont() { + return new CharFont(c, fontCode); + } + + public char getChar() { + return c; + } + + public Font getFont() { + return font; + } + + public int getFontCode() { + return fontCode; + } + + public float getWidth() { + return m.getWidth(); + } + + public float getItalic() { + return m.getItalic(); + } + + public float getHeight() { + return m.getHeight(); + } + + public float getDepth() { + return m.getDepth(); + } + + public Metrics getMetrics() { + return m; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CharAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CharAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CharAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,129 @@ +/* CharAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing exactly one alphanumeric character and the text style in which + * it should be drawn. + */ +public class CharAtom extends CharSymbol { + + // alphanumeric character + private final char c; + + // text style (null means the default text style) + private String textStyle; + private boolean mathMode; + + /** + * Creates a CharAtom that will represent the given character in the given text style. + * Null for the text style means the default text style. + * + * @param c the alphanumeric character + * @param textStyle the text style in which the character should be drawn + */ + public CharAtom(char c, String textStyle, boolean mathMode) { + this.c = c; + this.textStyle = textStyle; + this.mathMode = mathMode; + } + + public CharAtom(char c, String textStyle) { + this(c, textStyle, false); + } + + public boolean isMathMode() { + return mathMode; + } + + public Box createBox(TeXEnvironment env) { + if (textStyle == null) { + String ts = env.getTextStyle(); + if (ts != null) { + textStyle = ts; + } + } + boolean smallCap = env.getSmallCap(); + Char ch = getChar(env.getTeXFont(), env.getStyle(), smallCap); + Box box = new CharBox(ch); + if (smallCap && Character.isLowerCase(c)) { + // We have a small capital + box = new ScaleBox(box, 0.8f, 0.8f); + } + + return box; + } + + public char getCharacter() { + return c; + } + + /* + * Get the Char-object representing this character ("c") in the right text style + */ + private Char getChar(TeXFont tf, int style, boolean smallCap) { + char chr = c; + if (smallCap) { + if (Character.isLowerCase(c)) { + chr = Character.toUpperCase(c); + } + } + if (textStyle == null) { + return tf.getDefaultChar(chr, style); + } else { + return tf.getChar(chr, textStyle, style); + } + } + + public CharFont getCharFont(TeXFont tf) { + return getChar(tf, TeXConstants.STYLE_DISPLAY, false).getCharFont(); + } + + public String toString() { + return "CharAtom: \'" + c + "\'"; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CharBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CharBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CharBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,110 @@ +/* CharBox.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.awt.Stroke; +import java.awt.BasicStroke; + +/** + * A box representing a single character. + */ +public class CharBox extends Box { + + private final CharFont cf; + private final float size; + private float italic; + + private final char[] arr = new char[1]; + + /** + * Create a new CharBox that will represent the character defined by the given + * Char-object. + * + * @param c a Char-object containing the character's font information. + */ + public CharBox(Char c) { + cf = c.getCharFont(); + size = c.getMetrics().getSize(); + width = c.getWidth(); + height = c.getHeight(); + depth = c.getDepth(); + italic = c.getItalic(); + } + + public void addItalicCorrectionToWidth() { + width += italic; + italic = 0; + } + + public void draw(Graphics2D g2, float x, float y) { + drawDebug(g2, x, y); + AffineTransform at = g2.getTransform(); + g2.translate(x, y); + Font font = FontInfo.getFont(cf.fontId); + if (size != 1) { + g2.scale(size, size); + } + if (g2.getFont() != font) { + g2.setFont(font); + } + arr[0] = cf.c; + g2.drawChars(arr, 0, 1, 0, 0); + g2.setTransform(at); + } + + public int getLastFontId() { + return cf.fontId; + } + + public String toString() { + return super.toString() + "=" + cf.c; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CharFont.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CharFont.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CharFont.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,67 @@ +/* CharFont.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Represents a specific character in a specific font (identified by its font ID). + */ +public class CharFont { + + public char c; + public int fontId; + public int boldFontId; + + public CharFont(char ch, int f) { + this(ch, f, f); + } + + public CharFont(char ch, int f, int bf) { + c = ch; + fontId = f; + boldFontId = bf; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CharSymbol.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CharSymbol.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CharSymbol.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,92 @@ +/* CharSymbol.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An common superclass for atoms that represent one single character + * and access the font information. + */ +public abstract class CharSymbol extends Atom { + + /** + * Mrow will mark certain CharSymbol atoms as a text symbol. + * Msubsup wil use this property for a certain spacing rule. + */ + private boolean textSymbol = false; + + /** + * Mark as text symbol (used by Dummy) + */ + public void markAsTextSymbol() { + textSymbol = true; + } + + /** + * Remove the mark so the atom remains unchanged (used by Dummy) + */ + public void removeMark() { + textSymbol = false; + } + + /** + * Tests if this atom is marked as a text symbol (used by Msubsup) + * + * @return whether this CharSymbol is marked as a text symbol + */ + public boolean isMarkedAsTextSymbol() { + return textSymbol; + } + + /** + * Get the CharFont-object that uniquely identifies the character that is represented + * by this atom. + * + * @param tf the TeXFont containing all font related information + * @return a CharFont + */ + public abstract CharFont getCharFont(TeXFont tf); +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ColorAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ColorAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ColorAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,275 @@ +/* ColorAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Color; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +/** + * An atom representing the foreground and background color of an other atom. + */ +public class ColorAtom extends Atom implements Row { + + public static Map Colors = new HashMap(); + + // background color + private final Color background; + + // foreground color + private final Color color; + + // RowAtom for which the colorsettings apply + private final RowAtom elements; + + static { + initColors(); + } + + /** + * Creates a new ColorAtom that sets the given colors for the given atom. + * Null for a color means: no specific color set for this atom. + * + * @param atom the atom for which the given colors have to be set + * @param bg the background color + * @param c the foreground color + */ + public ColorAtom(Atom atom, Color bg, Color c) { + elements = new RowAtom(atom); + background = bg; + color = c; + } + + /** + * Creates a ColorAtom that overrides the colors of the given ColorAtom if the given + * colors are not null. If they're null, the old values are used. + * + * @param bg the background color + * @param c the foreground color + * @param old the ColorAtom for which the colorsettings should be overriden with the + * given colors. + */ + public ColorAtom(Color bg, Color c, ColorAtom old) { + elements = new RowAtom(old.elements); + background = (bg == null ? old.background : bg); + color = (c == null ? old.color : c); + } + + public Box createBox(TeXEnvironment env) { + env.isColored = true; + TeXEnvironment copy = env.copy(); + if (background != null) + copy.setBackground(background); + if (color != null) + copy.setColor(color); + return elements.createBox(copy); + } + + public int getLeftType() { + return elements.getLeftType(); + } + + public int getRightType() { + return elements.getRightType(); + } + + public void setPreviousAtom(Dummy prev) { + elements.setPreviousAtom(prev); + } + + public static Color getColor(String s) { + if (s != null) { + s = s.trim(); + if (s.length() >= 1) { + if (s.charAt(0) == '#') { + return Color.decode(s); + } else if (s.indexOf(',') != -1 || s.indexOf(';') != -1) { + StringTokenizer toks = new StringTokenizer(s, ";,"); + int n = toks.countTokens(); + if (n == 3) { + // RGB model + try { + String R = toks.nextToken().trim(); + String G = toks.nextToken().trim(); + String B = toks.nextToken().trim(); + + float r = Float.parseFloat(R); + float g = Float.parseFloat(G); + float b = Float.parseFloat(B); + + if (r == (int) r && g == (int) g && b == (int) b && R.indexOf('.') == -1 && G.indexOf('.') == -1 && B.indexOf('.') == -1) { + int ir = (int) Math.min(255, Math.max(0, r)); + int ig = (int) Math.min(255, Math.max(0, g)); + int ib = (int) Math.min(255, Math.max(0, b)); + return new Color(ir, ig, ib); + } else { + r = (float) Math.min(1, Math.max(0, r)); + g = (float) Math.min(1, Math.max(0, g)); + b = (float) Math.min(1, Math.max(0, b)); + return new Color(r, g, b); + } + } catch (NumberFormatException e) { + return Color.black; + } + } else if (n == 4) { + // CMYK model + try { + float c = Float.parseFloat(toks.nextToken().trim()); + float m = Float.parseFloat(toks.nextToken().trim()); + float y = Float.parseFloat(toks.nextToken().trim()); + float k = Float.parseFloat(toks.nextToken().trim()); + + c = (float) Math.min(1, Math.max(0, c)); + m = (float) Math.min(1, Math.max(0, m)); + y = (float) Math.min(1, Math.max(0, y)); + k = (float) Math.min(1, Math.max(0, k)); + + return convColor(c, m, y, k); + } catch (NumberFormatException e) { + return Color.black; + } + } + } + + Color c = Colors.get(s.toLowerCase()); + if (c != null) { + return c; + } else { + if (s.indexOf('.') != -1) { + try { + float g = (float) Math.min(1, Math.max(Float.parseFloat(s), 0)); + + return new Color(g, g, g); + } catch (NumberFormatException e) { } + } + + return Color.decode("#" + s); + } + } + } + + return Color.black; + } + + private static void initColors() { + Colors.put("black", Color.black); + Colors.put("white", Color.white); + Colors.put("red", Color.red); + Colors.put("green", Color.green); + Colors.put("blue", Color.blue); + Colors.put("cyan", Color.cyan); + Colors.put("magenta", Color.magenta); + Colors.put("yellow", Color.yellow); + Colors.put("greenyellow", convColor(0.15f, 0f, 0.69f, 0f)); + Colors.put("goldenrod", convColor(0f, 0.10f, 0.84f, 0f)); + Colors.put("dandelion", convColor(0f, 0.29f, 0.84f, 0f)); + Colors.put("apricot", convColor(0f, 0.32f, 0.52f, 0f)); + Colors.put("peach", convColor(0f, 0.50f, 0.70f, 0f)); + Colors.put("melon", convColor(0f, 0.46f, 0.50f, 0f)); + Colors.put("yelloworange", convColor(0f, 0.42f, 1f, 0f)); + Colors.put("orange", convColor(0f, 0.61f, 0.87f, 0f)); + Colors.put("burntorange", convColor(0f, 0.51f, 1f, 0f)); + Colors.put("bittersweet", convColor(0f, 0.75f, 1f, 0.24f)); + Colors.put("redorange", convColor(0f, 0.77f, 0.87f, 0f)); + Colors.put("mahogany", convColor(0f, 0.85f, 0.87f, 0.35f)); + Colors.put("maroon", convColor(0f, 0.87f, 0.68f, 0.32f)); + Colors.put("brickred", convColor(0f, 0.89f, 0.94f, 0.28f)); + Colors.put("orangered", convColor(0f, 1f, 0.50f, 0f)); + Colors.put("rubinered", convColor(0f, 1f, 0.13f, 0f)); + Colors.put("wildstrawberry", convColor(0f, 0.96f, 0.39f, 0f)); + Colors.put("salmon", convColor(0f, 0.53f, 0.38f, 0f)); + Colors.put("carnationpink", convColor(0f, 0.63f, 0f, 0f)); + Colors.put("magenta", convColor(0f, 1f, 0f, 0f)); + Colors.put("violetred", convColor(0f, 0.81f, 0f, 0f)); + Colors.put("rhodamine", convColor(0f, 0.82f, 0f, 0f)); + Colors.put("mulberry", convColor(0.34f, 0.90f, 0f, 0.02f)); + Colors.put("redviolet", convColor(0.07f, 0.90f, 0f, 0.34f)); + Colors.put("fuchsia", convColor(0.47f, 0.91f, 0f, 0.08f)); + Colors.put("lavender", convColor(0f, 0.48f, 0f, 0f)); + Colors.put("thistle", convColor(0.12f, 0.59f, 0f, 0f)); + Colors.put("orchid", convColor(0.32f, 0.64f, 0f, 0f)); + Colors.put("darkorchid", convColor(0.40f, 0.80f, 0.20f, 0f)); + Colors.put("purple", convColor(0.45f, 0.86f, 0f, 0f)); + Colors.put("plum", convColor(0.50f, 1f, 0f, 0f)); + Colors.put("violet", convColor(0.79f, 0.88f, 0f, 0f)); + Colors.put("royalpurple", convColor(0.75f, 0.90f, 0f, 0f)); + Colors.put("blueviolet", convColor(0.86f, 0.91f, 0f, 0.04f)); + Colors.put("periwinkle", convColor(0.57f, 0.55f, 0f, 0f)); + Colors.put("cadetblue", convColor(0.62f, 0.57f, 0.23f, 0f)); + Colors.put("cornflowerblue", convColor(0.65f, 0.13f, 0f, 0f)); + Colors.put("midnightblue", convColor(0.98f, 0.13f, 0f, 0.43f)); + Colors.put("navyblue", convColor(0.94f, 0.54f, 0f, 0f)); + Colors.put("royalblue", convColor(1f, 0.50f, 0f, 0f)); + Colors.put("cerulean", convColor(0.94f, 0.11f, 0f, 0f)); + Colors.put("processblue", convColor(0.96f, 0f, 0f, 0f)); + Colors.put("skyblue", convColor(0.62f, 0f, 0.12f, 0f)); + Colors.put("turquoise", convColor(0.85f, 0f, 0.20f, 0f)); + Colors.put("tealblue", convColor(0.86f, 0f, 0.34f, 0.02f)); + Colors.put("aquamarine", convColor(0.82f, 0f, 0.30f, 0f)); + Colors.put("bluegreen", convColor(0.85f, 0f, 0.33f, 0f)); + Colors.put("emerald", convColor(1f, 0f, 0.50f, 0f)); + Colors.put("junglegreen", convColor(0.99f, 0f, 0.52f, 0f)); + Colors.put("seagreen", convColor(0.69f, 0f, 0.50f, 0f)); + Colors.put("forestgreen", convColor(0.91f, 0f, 0.88f, 0.12f)); + Colors.put("pinegreen", convColor(0.92f, 0f, 0.59f, 0.25f)); + Colors.put("limegreen", convColor(0.50f, 0f, 1f, 0f)); + Colors.put("yellowgreen", convColor(0.44f, 0f, 0.74f, 0f)); + Colors.put("springgreen", convColor(0.26f, 0f, 0.76f, 0f)); + Colors.put("olivegreen", convColor(0.64f, 0f, 0.95f, 0.40f)); + Colors.put("rawsienna", convColor(0f, 0.72f, 1f, 0.45f)); + Colors.put("sepia", convColor(0f, 0.83f, 1f, 0.70f)); + Colors.put("brown", convColor(0f, 0.81f, 1f, 0.60f)); + Colors.put("tan", convColor(0.14f, 0.42f, 0.56f, 0f)); + Colors.put("gray", convColor(0f, 0f, 0f, 0.50f)); + } + + private static Color convColor(final float c, final float m, final float y, final float k) { + final float kk = 1f - k; + return new Color(kk * (1f - c), kk * (1f - m), kk * (1f - y)); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CumulativeScriptsAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CumulativeScriptsAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/CumulativeScriptsAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,80 @@ +/* ReflectAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a reflected Atom. + */ +public class CumulativeScriptsAtom extends Atom { + + private Atom base; + private RowAtom sup; + private RowAtom sub; + + public CumulativeScriptsAtom(Atom base, Atom sub, Atom sup) { + super(); + if (base instanceof CumulativeScriptsAtom) { + CumulativeScriptsAtom at = (CumulativeScriptsAtom) base; + this.base = at.base; + at.sup.add(sup); + at.sub.add(sub); + this.sup = at.sup; + this.sub = at.sub; + } else { + if (base == null) { + this.base = new PhantomAtom(new CharAtom('M', "mathnormal"), false, true, true); + } else { + this.base = base; + } + this.sup = new RowAtom(sup); + this.sub = new RowAtom(sub); + } + } + + public Box createBox(TeXEnvironment env) { + return new ScriptsAtom(base, sub, sup).createBox(env); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DdotsAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DdotsAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DdotsAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,77 @@ +/* DdotsAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing ddots. + */ +public class DdotsAtom extends Atom { + + public DdotsAtom() { + } + + public Box createBox(TeXEnvironment env) { + Box ldots = TeXFormula.get("ldots").root.createBox(env); + float w = ldots.getWidth(); + Box dot = SymbolAtom.get("ldotp").createBox(env); + HorizontalBox hb1 = new HorizontalBox(dot, w, TeXConstants.ALIGN_LEFT); + HorizontalBox hb2 = new HorizontalBox(dot, w, TeXConstants.ALIGN_CENTER); + HorizontalBox hb3 = new HorizontalBox(dot, w, TeXConstants.ALIGN_RIGHT); + Box pt4 = new SpaceAtom(TeXConstants.UNIT_MU, 0, 4, 0).createBox(env); + VerticalBox vb = new VerticalBox(); + vb.add(hb1); + vb.add(pt4); + vb.add(hb2); + vb.add(pt4); + vb.add(hb3); + + float h = vb.getHeight() + vb.getDepth(); + vb.setHeight(h); + vb.setDepth(0); + + return vb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DefaultTeXFont.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DefaultTeXFont.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DefaultTeXFont.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,587 @@ +/* DefaultTeXFont.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Font; +import java.util.Map; +import java.util.HashMap; +import java.util.List; +import java.util.ArrayList; +import java.lang.Character.UnicodeBlock; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.FileNotFoundException; + +/** + * The default implementation of the TeXFont-interface. All font information is read + * from an xml-file. + */ +public class DefaultTeXFont implements TeXFont { + + private static String[] defaultTextStyleMappings; + + /** + * No extension part for that kind (TOP,MID,REP or BOT) + */ + protected static final int NONE = -1; + + protected final static int NUMBERS = 0; + protected final static int CAPITALS = 1; + protected final static int SMALL = 2; + protected final static int UNICODE = 3; + + /** + * Number of font ids in a single font description file. + */ + private static final int NUMBER_OF_FONT_IDS = 256; + + private static Map textStyleMappings; + private static Map symbolMappings; + private static FontInfo[] fontInfo = new FontInfo[0]; + private static Map parameters; + private static Map generalSettings; + + private static boolean magnificationEnable = true; + + protected static final int TOP = 0, MID = 1, REP = 2, BOT = 3; + + protected static final int WIDTH = 0, HEIGHT = 1, DEPTH = 2, IT = 3; + + public static List loadedAlphabets = new ArrayList(); + public static Map registeredAlphabets = new HashMap(); + + protected float factor = 1f; + + public boolean isBold = false; + public boolean isRoman = false; + public boolean isSs = false; + public boolean isTt = false; + public boolean isIt = false; + + static { + DefaultTeXFontParser parser = new DefaultTeXFontParser(); + //load LATIN block + loadedAlphabets.add(Character.UnicodeBlock.of('a')); + // fonts + font descriptions + fontInfo = parser.parseFontDescriptions(fontInfo); + // general font parameters + parameters = parser.parseParameters(); + // text style mappings + textStyleMappings = parser.parseTextStyleMappings(); + // default text style : style mappings + defaultTextStyleMappings = parser.parseDefaultTextStyleMappings(); + // symbol mappings + symbolMappings = parser.parseSymbolMappings(); + // general settings + generalSettings = parser.parseGeneralSettings(); + generalSettings.put("textfactor", 1); + + // check if mufontid exists + int muFontId = generalSettings.get(DefaultTeXFontParser.MUFONTID_ATTR).intValue(); + if (muFontId < 0 || muFontId >= fontInfo.length || fontInfo[muFontId] == null) + throw new XMLResourceParseException( + DefaultTeXFontParser.RESOURCE_NAME, + DefaultTeXFontParser.GEN_SET_EL, + DefaultTeXFontParser.MUFONTID_ATTR, + "contains an unknown font id!"); + } + + private final float size; // standard size + + public DefaultTeXFont(float pointSize) { + size = pointSize; + } + + public DefaultTeXFont(float pointSize, boolean b, boolean rm, boolean ss, boolean tt, boolean it) { + this(pointSize, 1, b, rm, ss, tt, it); + } + + public DefaultTeXFont(float pointSize, float f, boolean b, boolean rm, boolean ss, boolean tt, boolean it) { + size = pointSize; + factor = f; + isBold = b; + isRoman = rm; + isSs = ss; + isTt = tt; + isIt = it; + } + + public static void addTeXFontDescription(String file) throws ResourceParseException { + FileInputStream in; + try { + in = new FileInputStream(file); + } catch (FileNotFoundException e) { + throw new ResourceParseException(file, e); + } + addTeXFontDescription(in, file); + } + + public static void addTeXFontDescription(InputStream in, String name) throws ResourceParseException { + DefaultTeXFontParser dtfp = new DefaultTeXFontParser(in, name); + fontInfo = dtfp.parseFontDescriptions(fontInfo); + textStyleMappings.putAll(dtfp.parseTextStyleMappings()); + symbolMappings.putAll(dtfp.parseSymbolMappings()); + } + + public static void addTeXFontDescription(Object base, InputStream in, String name) throws ResourceParseException { + DefaultTeXFontParser dtfp = new DefaultTeXFontParser(base, in, name); + fontInfo = dtfp.parseFontDescriptions(fontInfo); + dtfp.parseExtraPath(); + textStyleMappings.putAll(dtfp.parseTextStyleMappings()); + symbolMappings.putAll(dtfp.parseSymbolMappings()); + } + + public static void addAlphabet(Character.UnicodeBlock alphabet, InputStream inlanguage, String language, InputStream insymbols, String symbols, InputStream inmappings, String mappings) throws ResourceParseException { + if (!loadedAlphabets.contains(alphabet)) { + addTeXFontDescription(inlanguage, language); + SymbolAtom.addSymbolAtom(insymbols, symbols); + TeXFormula.addSymbolMappings(inmappings, mappings); + loadedAlphabets.add(alphabet); + } + } + + public static void addAlphabet(Object base, Character.UnicodeBlock[] alphabet, String language) throws ResourceParseException { + boolean b = false; + for (int i = 0; !b && i < alphabet.length; i++) { + b = loadedAlphabets.contains(alphabet[i]) || b; + } + if (!b) { + TeXParser.isLoading = true; + addTeXFontDescription(base, base.getClass().getResourceAsStream(language), language); + for (int i = 0; i < alphabet.length; i++) { + loadedAlphabets.add(alphabet[i]); + } + TeXParser.isLoading = false; + } + } + + public static void addAlphabet(Character.UnicodeBlock alphabet, String name) { + String lg = "fonts/" + name + "/language_" + name+ ".xml"; + String sym = "fonts/" + name + "/symbols_" + name+ ".xml"; + String map = "fonts/" + name + "/mappings_" + name+ ".xml"; + + try { + DefaultTeXFont.addAlphabet(alphabet, TeXFormula.class.getResourceAsStream(lg), lg, TeXFormula.class.getResourceAsStream(sym), sym, TeXFormula.class.getResourceAsStream(map), map); + } catch (FontAlreadyLoadedException e) { } + } + + public static void addAlphabet(AlphabetRegistration reg) { + try { + if (reg != null) { + DefaultTeXFont.addAlphabet(reg.getPackage(), reg.getUnicodeBlock(), reg.getTeXFontFileName()); + } + } catch (FontAlreadyLoadedException e) { + } catch (AlphabetRegistrationException e) { + System.err.println(e.toString()); + } + } + + public static void registerAlphabet(AlphabetRegistration reg) { + Character.UnicodeBlock[] blocks = reg.getUnicodeBlock(); + for (int i = 0; i < blocks.length; i++) { + registeredAlphabets.put(blocks[i], reg); + } + } + + public TeXFont copy() { + return new DefaultTeXFont(size, factor, isBold, isRoman, isSs, isTt, isIt); + } + + public TeXFont deriveFont(float size) { + return new DefaultTeXFont(size, factor, isBold, isRoman, isSs, isTt, isIt); + } + + public TeXFont scaleFont(float factor) { + return new DefaultTeXFont(size, factor, isBold, isRoman, isSs, isTt, isIt); + } + + public float getScaleFactor() { + return factor; + } + + public float getAxisHeight(int style) { + return getParameter("axisheight") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getBigOpSpacing1(int style) { + return getParameter("bigopspacing1") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getBigOpSpacing2(int style) { + return getParameter("bigopspacing2") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getBigOpSpacing3(int style) { + return getParameter("bigopspacing3") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getBigOpSpacing4(int style) { + return getParameter("bigopspacing4") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getBigOpSpacing5(int style) { + return getParameter("bigopspacing5") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + private Char getChar(char c, CharFont[] cf, int style) { + int kind, offset; + if (c >= '0' && c <= '9') { + kind = NUMBERS; + offset = c - '0'; + } else if (c >= 'a' && c <= 'z') { + kind = SMALL; + offset = c - 'a'; + } else if (c >= 'A' && c <= 'Z') { + kind = CAPITALS; + offset = c - 'A'; + } else { + kind = UNICODE; + offset = c; + } + + // if the mapping for the character's range, then use the default style + if (cf[kind] == null) + return getDefaultChar(c, style); + else + return getChar(new CharFont((char) (cf[kind].c + offset), cf[kind].fontId), style); + } + + public Char getChar(char c, String textStyle, int style) throws TextStyleMappingNotFoundException { + Object mapping = textStyleMappings.get(textStyle); + if (mapping == null) // text style mapping not found + throw new TextStyleMappingNotFoundException(textStyle); + else + return getChar(c, (CharFont[]) mapping, style); + } + + public Char getChar(CharFont cf, int style) { + float fsize = getSizeFactor(style); + int id = isBold ? cf.boldFontId : cf.fontId; + FontInfo info = fontInfo[id]; + if (isBold && cf.fontId == cf.boldFontId) { + id = info.getBoldId(); + info = fontInfo[id]; + cf = new CharFont(cf.c, id, style); + } + if (isRoman) { + id = info.getRomanId(); + info = fontInfo[id]; + cf = new CharFont(cf.c, id, style); + } + if (isSs) { + id = info.getSsId(); + info = fontInfo[id]; + cf = new CharFont(cf.c, id, style); + } + if (isTt) { + id = info.getTtId(); + info = fontInfo[id]; + cf = new CharFont(cf.c, id, style); + } + if (isIt) { + id = info.getItId(); + info = fontInfo[id]; + cf = new CharFont(cf.c, id, style); + } + Font font = info.getFont(); + return new Char(cf.c, font, id, getMetrics(cf, factor * fsize)); + } + + public Char getChar(String symbolName, int style) throws SymbolMappingNotFoundException { + Object obj = symbolMappings.get(symbolName); + if (obj == null) {// no symbol mapping found! + throw new SymbolMappingNotFoundException(symbolName); + } else { + return getChar((CharFont) obj, style); + } + } + + public Char getDefaultChar(char c, int style) { + // these default text style mappings will allways exist, + // because it's checked during parsing + if (c >= '0' && c <= '9') { + return getChar(c, defaultTextStyleMappings[NUMBERS], style); + } else if (c >= 'a' && c <= 'z') { + return getChar(c, defaultTextStyleMappings[SMALL], style); + } else { + return getChar(c, defaultTextStyleMappings[CAPITALS], style); + } + } + + public float getDefaultRuleThickness(int style) { + return getParameter("defaultrulethickness") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getDenom1(int style) { + return getParameter("denom1") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getDenom2(int style) { + return getParameter("denom2") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public Extension getExtension(Char c, int style) { + Font f = c.getFont(); + int fc = c.getFontCode(); + float s = getSizeFactor(style); + + // construct Char for every part + FontInfo info = fontInfo[fc]; + int[] ext = info.getExtension(c.getChar()); + Char[] parts = new Char[ext.length]; + for (int i = 0; i < ext.length; i++) { + if (ext[i] == NONE) { + parts[i] = null; + } else { + parts[i] = new Char((char) ext[i], f, fc, getMetrics(new CharFont((char) ext[i], fc), s)); + } + } + + return new Extension(parts[TOP], parts[MID], parts[REP], parts[BOT]); + } + + public float getKern(CharFont left, CharFont right, int style) { + if (left.fontId == right.fontId){ + FontInfo info = fontInfo[left.fontId]; + return info.getKern(left.c, right.c, getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT); + } else { + return 0; + } + } + + public CharFont getLigature(CharFont left, CharFont right) { + if (left.fontId == right.fontId) { + FontInfo info = fontInfo[left.fontId]; + return info.getLigature(left.c, right.c); + } else { + return null; + } + } + + private Metrics getMetrics(CharFont cf, float size) { + FontInfo info = fontInfo[cf.fontId]; + float[] m = info.getMetrics(cf.c); + return new Metrics(m[WIDTH], m[HEIGHT], m[DEPTH], m[IT], size * TeXFormula.PIXELS_PER_POINT, size); + } + + public int getMuFontId() { + return generalSettings.get(DefaultTeXFontParser.MUFONTID_ATTR).intValue(); + } + + public Char getNextLarger(Char c, int style) { + FontInfo info = fontInfo[c.getFontCode()]; + CharFont ch = info.getNextLarger(c.getChar()); + FontInfo newInfo = fontInfo[ch.fontId]; + return new Char(ch.c, newInfo.getFont(), ch.fontId, getMetrics(ch, getSizeFactor(style))); + } + + public float getNum1(int style) { + return getParameter("num1") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getNum2(int style) { + return getParameter("num2") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getNum3(int style) { + return getParameter("num3") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getQuad(int style, int fontCode) { + FontInfo info = fontInfo[fontCode]; + return info.getQuad(getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT); + } + + public float getSize() { + return size; + } + + public float getSkew(CharFont cf, int style) { + FontInfo info = fontInfo[cf.fontId]; + char skew = info.getSkewChar(); + if (skew == -1) + return 0; + else + return getKern(cf, new CharFont(skew, cf.fontId), style); + } + + public float getSpace(int style) { + int spaceFontId = generalSettings.get(DefaultTeXFontParser.SPACEFONTID_ATTR).intValue(); + FontInfo info = fontInfo[spaceFontId]; + return info.getSpace(getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT); + } + + public float getSub1(int style) { + return getParameter("sub1") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getSub2(int style) { + return getParameter("sub2") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getSubDrop(int style) { + return getParameter("subdrop") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getSup1(int style) { + return getParameter("sup1") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getSup2(int style) { + return getParameter("sup2") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getSup3(int style) { + return getParameter("sup3") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getSupDrop(int style) { + return getParameter("supdrop") * getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public float getXHeight(int style, int fontCode) { + FontInfo info = fontInfo[fontCode]; + return info.getXHeight(getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT); + } + + public float getEM(int style) { + return getSizeFactor(style) * TeXFormula.PIXELS_PER_POINT; + } + + public boolean hasNextLarger(Char c) { + FontInfo info = fontInfo[c.getFontCode()]; + return (info.getNextLarger(c.getChar()) != null); + } + + public void setBold(boolean bold) { + isBold = bold; + } + + public boolean getBold() { + return isBold; + } + + public void setRoman(boolean rm) { + isRoman = rm; + } + + public boolean getRoman() { + return isRoman; + } + + public void setTt(boolean tt) { + isTt = tt; + } + + public boolean getTt() { + return isTt; + } + + public void setIt(boolean it) { + isIt = it; + } + + public boolean getIt() { + return isIt; + } + + public void setSs(boolean ss) { + isSs = ss; + } + + public boolean getSs() { + return isSs; + } + + public boolean hasSpace(int font) { + FontInfo info = fontInfo[font]; + return info.hasSpace(); + } + + public boolean isExtensionChar(Char c) { + FontInfo info = fontInfo[c.getFontCode()]; + return info.getExtension(c.getChar()) != null; + } + + public static void setMathSizes(float ds, float ts, float ss, float sss) { + if (magnificationEnable) { + generalSettings.put("scriptfactor", Math.abs(ss / ds)); + generalSettings.put("scriptscriptfactor", Math.abs(sss / ds)); + generalSettings.put("textfactor", Math.abs(ts / ds)); + TeXIcon.defaultSize = Math.abs(ds); + } + } + + public static void setMagnification(float mag) { + if (magnificationEnable) { + TeXIcon.magFactor = mag / 1000f; + } + } + + public static void enableMagnification(boolean b) { + magnificationEnable = b; + } + + private static float getParameter(String parameterName) { + Object param = parameters.get(parameterName); + if (param == null) + return 0; + else + return ((Float) param).floatValue(); + } + + public static float getSizeFactor(int style) { + if (style < TeXConstants.STYLE_TEXT) + return 1; + else if (style < TeXConstants.STYLE_SCRIPT) + return generalSettings.get("textfactor").floatValue(); + else if (style < TeXConstants.STYLE_SCRIPT_SCRIPT) + return generalSettings.get("scriptfactor").floatValue(); + else + return generalSettings.get("scriptscriptfactor").floatValue(); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DefaultTeXFontParser.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DefaultTeXFontParser.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DefaultTeXFontParser.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,668 @@ +/* DefaultTeXFontParser.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet */ + +package org.scilab.forge.jlatexmath; + +import java.lang.reflect.Method; + +import java.awt.Font; +import java.io.IOException; +import java.io.InputStream; +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; +import java.awt.GraphicsEnvironment; + +import javax.xml.parsers.DocumentBuilderFactory; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Attr; +import org.w3c.dom.Node; + + +/** + * Parses the font information from an XML-file. + */ +public class DefaultTeXFontParser { + + /** + * if the register font cannot be found, we display an error message + * but we do it only once + */ + private static boolean registerFontExceptionDisplayed = false; + private static boolean shouldRegisterFonts = true; + private static DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + private static interface CharChildParser { // NOPMD + public void parse(Element el, char ch, FontInfo info) throws XMLResourceParseException; + } + + private static class ExtensionParser implements CharChildParser { + + ExtensionParser() { + // avoid generation of access class + } + + public void parse(Element el, char ch, FontInfo info) throws ResourceParseException { + int[] extensionChars = new int[4]; + // get required integer attributes + extensionChars[DefaultTeXFont.REP] = DefaultTeXFontParser + .getIntAndCheck("rep", el); + // get optional integer attributes + extensionChars[DefaultTeXFont.TOP] = DefaultTeXFontParser + .getOptionalInt("top", el, DefaultTeXFont.NONE); + extensionChars[DefaultTeXFont.MID] = DefaultTeXFontParser + .getOptionalInt("mid", el, DefaultTeXFont.NONE); + extensionChars[DefaultTeXFont.BOT] = DefaultTeXFontParser + .getOptionalInt("bot", el, DefaultTeXFont.NONE); + + // parsing OK, add extension info + info.setExtension(ch, extensionChars); + } + } + + private static class KernParser implements CharChildParser { + + KernParser() { + // avoid generation of access class + } + + public void parse(Element el, char ch, FontInfo info) throws ResourceParseException { + // get required integer attribute + int code = DefaultTeXFontParser.getIntAndCheck("code", el); + // get required float attribute + float kernAmount = DefaultTeXFontParser.getFloatAndCheck("val", el); + + // parsing OK, add kern info + info.addKern(ch, (char) code, kernAmount); + } + } + + private static class LigParser implements CharChildParser { + + LigParser() { + // avoid generation of access class + } + + public void parse(Element el, char ch, FontInfo info) throws ResourceParseException { + // get required integer attributes + int code = DefaultTeXFontParser.getIntAndCheck("code", el); + int ligCode = DefaultTeXFontParser.getIntAndCheck("ligCode", el); + + // parsing OK, add ligature info + info.addLigature(ch, (char) code, (char) ligCode); + } + } + + private static class NextLargerParser implements CharChildParser { + + NextLargerParser() { + // avoid generation of access class + } + + public void parse(Element el, char ch, FontInfo info) throws ResourceParseException { + // get required integer attributes + String fontId = DefaultTeXFontParser.getAttrValueAndCheckIfNotNull("fontId", el); + int code = DefaultTeXFontParser.getIntAndCheck("code", el); + + // parsing OK, add "next larger" info + info.setNextLarger(ch, (char) code, Font_ID.indexOf(fontId)); + } + } + + public static final String RESOURCE_NAME = "DefaultTeXFont.xml"; + + public static final String STYLE_MAPPING_EL = "TextStyleMapping"; + public static final String SYMBOL_MAPPING_EL = "SymbolMapping"; + public static final String GEN_SET_EL = "GeneralSettings"; + public static final String MUFONTID_ATTR = "mufontid"; + public static final String SPACEFONTID_ATTR = "spacefontid"; + + protected static ArrayList Font_ID = new ArrayList(); + private static Map rangeTypeMappings = new HashMap(); + private static Map charChildParsers = new HashMap(); + + private Map parsedTextStyles; + + private Element root; + private Object base = null; + + static { + // string-to-constant mappings + setRangeTypeMappings(); + // parsers for the child elements of a "Char"-element + setCharChildParsers(); + } + + public DefaultTeXFontParser() throws ResourceParseException { + this(DefaultTeXFontParser.class.getResourceAsStream(RESOURCE_NAME), RESOURCE_NAME); + } + + public DefaultTeXFontParser(InputStream file, String name) throws ResourceParseException { + factory.setIgnoringElementContentWhitespace(true); + factory.setIgnoringComments(true); + try { + root = factory.newDocumentBuilder().parse(file).getDocumentElement(); + } catch (Exception e) { // JDOMException or IOException + throw new XMLResourceParseException(name, e); + } + } + + public DefaultTeXFontParser(Object base , InputStream file, String name) throws ResourceParseException { + this.base = base; + factory.setIgnoringElementContentWhitespace(true); + factory.setIgnoringComments(true); + try { + root = factory.newDocumentBuilder().parse(file).getDocumentElement(); + } catch (Exception e) { // JDOMException or IOException + throw new XMLResourceParseException(name, e); + } + } + + private static void setCharChildParsers() { + charChildParsers.put("Kern", new KernParser()); + charChildParsers.put("Lig", new LigParser()); + charChildParsers.put("NextLarger", new NextLargerParser()); + charChildParsers.put("Extension", new ExtensionParser()); + } + + public FontInfo[] parseFontDescriptions(FontInfo[] fi, InputStream file, String name) throws ResourceParseException { + if (file == null) { + return fi; + } + ArrayList res = new ArrayList(Arrays.asList(fi)); + Element font; + try { + font = factory.newDocumentBuilder().parse(file).getDocumentElement(); + } catch (Exception e) { + throw new XMLResourceParseException("Cannot find the file " + name + "!" + e.toString()); + } + + String fontName = getAttrValueAndCheckIfNotNull("name", font); + // get required integer attribute + String fontId = getAttrValueAndCheckIfNotNull("id", font); + if (Font_ID.indexOf(fontId) < 0) + Font_ID.add(fontId); + else throw new FontAlreadyLoadedException("Font " + fontId + " is already loaded !"); + // get required real attributes + float space = getFloatAndCheck("space", font); + float xHeight = getFloatAndCheck("xHeight", font); + float quad = getFloatAndCheck("quad", font); + + // get optional integer attribute + int skewChar = getOptionalInt("skewChar", font, -1); + + // get optional boolean for unicode + int unicode = getOptionalInt("unicode", font, 0); + + // get different versions of a font + String bold = null; + try { + bold = getAttrValueAndCheckIfNotNull("boldVersion", font); + } catch (ResourceParseException e) {} + String roman = null; + try { + roman = getAttrValueAndCheckIfNotNull("romanVersion", font); + } catch (ResourceParseException e) {} + String ss = null; + try { + ss = getAttrValueAndCheckIfNotNull("ssVersion", font); + } catch (ResourceParseException e) {} + String tt = null; + try { + tt = getAttrValueAndCheckIfNotNull("ttVersion", font); + } catch (ResourceParseException e) {} + String it = null; + try { + it = getAttrValueAndCheckIfNotNull("itVersion", font); + } catch (ResourceParseException e) {} + + String path = name.substring(0, name.lastIndexOf("/") + 1) + fontName; + + // create FontInfo-object + FontInfo info = new FontInfo(Font_ID.indexOf(fontId), base, path, fontName, unicode, xHeight, space, quad, bold, roman, ss, tt, it); + + if (skewChar != -1) // attribute set + info.setSkewChar((char) skewChar); + + // process all "Char"-elements + NodeList listF = font.getElementsByTagName("Char"); + for (int j = 0; j < listF.getLength(); j++) + processCharElement((Element) listF.item(j), info); + + // parsing OK, add to table + res.add(info); + + for (int i = 0; i < res.size(); i++) { + FontInfo fin = res.get(i); + fin.setBoldId(Font_ID.indexOf(fin.boldVersion)); + fin.setRomanId(Font_ID.indexOf(fin.romanVersion)); + fin.setSsId(Font_ID.indexOf(fin.ssVersion)); + fin.setTtId(Font_ID.indexOf(fin.ttVersion)); + fin.setItId(Font_ID.indexOf(fin.itVersion)); + } + + parsedTextStyles = parseStyleMappings(); + return res.toArray(fi); + } + + public FontInfo[] parseFontDescriptions(FontInfo[] fi) throws ResourceParseException { + Element fontDescriptions = (Element)root.getElementsByTagName("FontDescriptions").item(0); + if (fontDescriptions != null) { // element present + NodeList list = fontDescriptions.getElementsByTagName("Metrics"); + for (int i = 0; i < list.getLength(); i++) { + // get required string attribute + String include = getAttrValueAndCheckIfNotNull("include", (Element)list.item(i)); + if (base == null) { + fi = parseFontDescriptions(fi, DefaultTeXFontParser.class.getResourceAsStream(include), include); + } else { + fi = parseFontDescriptions(fi, base.getClass().getResourceAsStream(include), include); + } + } + } + return fi; + } + + protected void parseExtraPath() throws ResourceParseException { + Element syms = (Element)root.getElementsByTagName("TeXSymbols").item(0); + if (syms != null) { // element present + // get required string attribute + String include = getAttrValueAndCheckIfNotNull("include", syms); + SymbolAtom.addSymbolAtom(base.getClass().getResourceAsStream(include), include); + } + Element settings = (Element)root.getElementsByTagName("FormulaSettings").item(0); + if (settings != null) { // element present + // get required string attribute + String include = getAttrValueAndCheckIfNotNull("include", settings); + TeXFormula.addSymbolMappings(base.getClass().getResourceAsStream(include), include); + } + } + + private static void processCharElement(Element charElement, FontInfo info) + throws ResourceParseException { + // retrieve required integer attribute + char ch = (char) getIntAndCheck("code", charElement); + // retrieve optional float attributes + float[] metrics = new float[4]; + metrics[DefaultTeXFont.WIDTH] = getOptionalFloat("width", charElement, 0); + metrics[DefaultTeXFont.HEIGHT] = getOptionalFloat("height", charElement, 0); + metrics[DefaultTeXFont.DEPTH] = getOptionalFloat("depth", charElement, 0); + metrics[DefaultTeXFont.IT] = getOptionalFloat("italic", charElement, 0); + // set metrics + info.setMetrics(ch, metrics); + + // process children + NodeList list = charElement.getChildNodes(); + for (int i = 0; i < list.getLength(); i++) { + Node node = list.item(i); + if (node.getNodeType() != Node.TEXT_NODE) { + Element el = (Element)node; + Object parser = charChildParsers.get(el.getTagName()); + if (parser == null) // unknown element + throw new XMLResourceParseException(RESOURCE_NAME + + ": a -element has an unknown child element '" + + el.getTagName() + "'!"); + else + // process the child element + ((CharChildParser) parser).parse(el, ch, info); + } + } + } + + public static void registerFonts(boolean b) { + shouldRegisterFonts = b; + } + + public static Font createFont(String name) throws ResourceParseException { + return createFont(DefaultTeXFontParser.class.getResourceAsStream(name), name); + } + + public static Font createFont(InputStream fontIn, String name) throws ResourceParseException { + try { + Font f = Font.createFont(Font.TRUETYPE_FONT, fontIn).deriveFont(TeXFormula.PIXELS_PER_POINT); + GraphicsEnvironment graphicEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); + /** + * The following fails under java 1.5 + * graphicEnv.registerFont(f); + * dynamic load then + */ + if (shouldRegisterFonts) { + try { + Method registerFontMethod = graphicEnv.getClass().getMethod("registerFont", new Class[] { Font.class }); + if ((Boolean) registerFontMethod.invoke(graphicEnv, new Object[] { f }) == Boolean.FALSE) { + System.err.println("Cannot register the font " + f.getFontName()); + } + } catch (Exception ex) { + if (!registerFontExceptionDisplayed) { + System.err.println("Warning: Jlatexmath: Could not access to registerFont. Please update to java 6"); + registerFontExceptionDisplayed = true; + } + } + } + return f; + } catch (Exception e) { + throw new XMLResourceParseException(RESOURCE_NAME + + ": error reading font '" + name + "'. Error message: " + + e.getMessage()); + } finally { + try { + if (fontIn != null) + fontIn.close(); + } catch (IOException ioex) { + throw new RuntimeException("Close threw exception", ioex); + } + } + } + + public Map parseSymbolMappings() throws ResourceParseException { + Map res = new HashMap(); + Element symbolMappings = (Element)root.getElementsByTagName("SymbolMappings").item(0); + if (symbolMappings == null) + // "SymbolMappings" is required! + throw new XMLResourceParseException(RESOURCE_NAME, "SymbolMappings"); + else { // element present + // iterate all mappings + NodeList list = symbolMappings.getElementsByTagName("Mapping"); + for (int i = 0; i < list.getLength(); i++) { + String include = getAttrValueAndCheckIfNotNull("include", (Element)list.item(i)); + Element map; + try { + if (base == null) { + map = factory.newDocumentBuilder().parse(DefaultTeXFontParser.class.getResourceAsStream(include)).getDocumentElement(); + } else { + map = factory.newDocumentBuilder().parse(base.getClass().getResourceAsStream(include)).getDocumentElement(); + } + } catch (Exception e) { + throw new XMLResourceParseException("Cannot find the file " + include + "!"); + } + NodeList listM = map.getElementsByTagName(SYMBOL_MAPPING_EL); + for (int j = 0; j < listM.getLength(); j++) { + Element mapping = (Element)listM.item(j); + // get string attribute + String symbolName = getAttrValueAndCheckIfNotNull("name", mapping); + // get integer attributes + int ch = getIntAndCheck("ch", mapping); + String fontId = getAttrValueAndCheckIfNotNull("fontId", mapping); + // put mapping in table + String boldFontId = null; + try { + boldFontId = getAttrValueAndCheckIfNotNull("boldId", mapping); + } + catch (ResourceParseException e) {} + + if (boldFontId == null) { + res.put(symbolName, new CharFont((char) ch, Font_ID.indexOf(fontId))); + } else { + res.put(symbolName, new CharFont((char) ch, Font_ID.indexOf(fontId), Font_ID.indexOf(boldFontId))); + } + } + } + + return res; + } + } + + public String[] parseDefaultTextStyleMappings() + throws ResourceParseException { + String[] res = new String[4]; + Element defaultTextStyleMappings = (Element)root + .getElementsByTagName("DefaultTextStyleMapping").item(0); + if (defaultTextStyleMappings == null) + return res; + else { // element present + // iterate all mappings + NodeList list = defaultTextStyleMappings.getElementsByTagName("MapStyle"); + for (int i = 0; i < list.getLength(); i++) { + Element mapping = (Element)list.item(i); + // get range name and check if it's valid + String code = getAttrValueAndCheckIfNotNull("code", mapping); + Object codeMapping = rangeTypeMappings.get(code); + if (codeMapping == null) // unknown range name + throw new XMLResourceParseException(RESOURCE_NAME, "MapStyle", + "code", "contains an unknown \"range name\" '" + code + + "'!"); + // get mapped style and check if it exists + String textStyleName = getAttrValueAndCheckIfNotNull("textStyle", + mapping); + Object styleMapping = parsedTextStyles.get(textStyleName); + if (styleMapping == null) // unknown text style + throw new XMLResourceParseException(RESOURCE_NAME, "MapStyle", + "textStyle", "contains an unknown text style '" + + textStyleName + "'!"); + // now check if the range is defined within the mapped text style + CharFont[] charFonts = parsedTextStyles.get(textStyleName); + int index = ((Integer) codeMapping).intValue(); + if (charFonts[index] == null) // range not defined + throw new XMLResourceParseException(RESOURCE_NAME + + ": the default text style mapping '" + textStyleName + + "' for the range '" + code + + "' contains no mapping for that range!"); + else + // everything OK, put mapping in table + res[index] = textStyleName; + } + } + return res; + } + + public Map parseParameters() throws ResourceParseException { + Map res = new HashMap(); + Element parameters = (Element)root.getElementsByTagName("Parameters").item(0); + if (parameters == null) + // "Parameters" is required! + throw new XMLResourceParseException(RESOURCE_NAME, "Parameters"); + else { // element present + // iterate all attributes + NamedNodeMap list = parameters.getAttributes(); + for (int i = 0; i < list.getLength(); i++) { + String name = ((Attr)list.item(i)).getName(); + // set float value (if valid) + res.put(name, new Float(getFloatAndCheck(name, parameters))); + } + return res; + } + } + + public Map parseGeneralSettings() throws ResourceParseException { + Map res = new HashMap(); + // TODO: must this be 'Number' ? + Element generalSettings = (Element)root.getElementsByTagName("GeneralSettings").item(0); + if (generalSettings == null) + // "GeneralSettings" is required! + throw new XMLResourceParseException(RESOURCE_NAME, "GeneralSettings"); + else { // element present + // set required int values (if valid) + res.put(MUFONTID_ATTR, Font_ID.indexOf(getAttrValueAndCheckIfNotNull(MUFONTID_ATTR, generalSettings))); // autoboxing + res.put(SPACEFONTID_ATTR, Font_ID.indexOf(getAttrValueAndCheckIfNotNull(SPACEFONTID_ATTR, generalSettings))); // autoboxing + // set required float values (if valid) + res.put("scriptfactor", getFloatAndCheck("scriptfactor", + generalSettings)); // autoboxing + res.put("scriptscriptfactor", getFloatAndCheck( + "scriptscriptfactor", generalSettings)); // autoboxing + + } + return res; + } + + public Map parseTextStyleMappings() { + return parsedTextStyles; + } + + private Map parseStyleMappings() throws ResourceParseException { + Map res = new HashMap(); + Element textStyleMappings = (Element)root.getElementsByTagName("TextStyleMappings").item(0); + if (textStyleMappings == null) + return res; + else { // element present + // iterate all mappings + NodeList list = textStyleMappings.getElementsByTagName(STYLE_MAPPING_EL); + for (int i = 0; i < list.getLength(); i++) { + Element mapping = (Element)list.item(i); + // get required string attribute + String textStyleName = getAttrValueAndCheckIfNotNull("name", + mapping); + String boldFontId = null; + try { + boldFontId = getAttrValueAndCheckIfNotNull("bold", mapping); + } + catch (ResourceParseException e) {} + + NodeList mapRangeList = mapping.getElementsByTagName("MapRange"); + // iterate all mapping ranges + CharFont[] charFonts = new CharFont[4]; + for (int j = 0; j < mapRangeList.getLength(); j++) { + Element mapRange = (Element)mapRangeList.item(j); + // get required integer attributes + String fontId = getAttrValueAndCheckIfNotNull("fontId", mapRange); + int ch = getIntAndCheck("start", mapRange); + // get required string attribute and check if it's a known range + String code = getAttrValueAndCheckIfNotNull("code", mapRange); + Object codeMapping = rangeTypeMappings.get(code); + if (codeMapping == null) + throw new XMLResourceParseException(RESOURCE_NAME, + "MapRange", "code", + "contains an unknown \"range name\" '" + code + "'!"); + else if (boldFontId == null) + charFonts[((Integer) codeMapping).intValue()] = new CharFont((char) ch, Font_ID.indexOf(fontId)); + else charFonts[((Integer) codeMapping).intValue()] = new CharFont((char) ch, Font_ID.indexOf(fontId), Font_ID.indexOf(boldFontId)); + } + res.put(textStyleName, charFonts); + } + } + return res; + } + + private static void setRangeTypeMappings() { + rangeTypeMappings.put("numbers", DefaultTeXFont.NUMBERS); // autoboxing + rangeTypeMappings.put("capitals", DefaultTeXFont.CAPITALS); // autoboxing + rangeTypeMappings.put("small", DefaultTeXFont.SMALL); // autoboxing + rangeTypeMappings.put("unicode", DefaultTeXFont.UNICODE); // autoboxing + } + + private static String getAttrValueAndCheckIfNotNull(String attrName, + Element element) throws ResourceParseException { + String attrValue = element.getAttribute(attrName); + if (attrValue.equals("")) + throw new XMLResourceParseException(RESOURCE_NAME, element.getTagName(), + attrName, null); + return attrValue; + } + + public static float getFloatAndCheck(String attrName, Element element) + throws ResourceParseException { + String attrValue = getAttrValueAndCheckIfNotNull(attrName, element); + + // try parsing string to float value + float res = 0; + try { + res = (float) Double.parseDouble(attrValue); + } catch (NumberFormatException e) { + throw new XMLResourceParseException(RESOURCE_NAME, element.getTagName(), + attrName, "has an invalid real value!"); + } + // parsing OK + return res; + } + + public static int getIntAndCheck(String attrName, Element element) + throws ResourceParseException { + String attrValue = getAttrValueAndCheckIfNotNull(attrName, element); + + // try parsing string to integer value + int res = 0; + try { + res = Integer.parseInt(attrValue); + } catch (NumberFormatException e) { + throw new XMLResourceParseException(RESOURCE_NAME, element.getTagName(), + attrName, "has an invalid integer value!"); + } + // parsing OK + return res; + } + + public static int getOptionalInt(String attrName, Element element, + int defaultValue) throws ResourceParseException { + String attrValue = element.getAttribute(attrName); + if (attrValue.equals("")) // attribute not present + return defaultValue; + else { + // try parsing string to integer value + int res = 0; + try { + res = Integer.parseInt(attrValue); + } catch (NumberFormatException e) { + throw new XMLResourceParseException(RESOURCE_NAME, element + .getTagName(), attrName, "has an invalid integer value!"); + } + // parsing OK + return res; + } + } + + public static float getOptionalFloat(String attrName, Element element, + float defaultValue) throws ResourceParseException { + String attrValue = element.getAttribute(attrName); + if (attrValue.equals("")) // attribute not present + return defaultValue; + else { + // try parsing string to float value + float res = 0; + try { + res = (float) Double.parseDouble(attrValue); + } catch (NumberFormatException e) { + throw new XMLResourceParseException(RESOURCE_NAME, element + .getTagName(), attrName, "has an invalid float value!"); + } + // parsing OK + return res; + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DelimiterFactory.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DelimiterFactory.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DelimiterFactory.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,144 @@ +/* DelimiterFactory.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet */ + +package org.scilab.forge.jlatexmath; // NOPMD + +/** + * Responsible for creating a box containing a delimiter symbol that exists + * in different sizes. + */ +public class DelimiterFactory { + + public static Box create(SymbolAtom symbol, TeXEnvironment env, int size) { + if (size > 4) + return symbol.createBox(env); + + TeXFont tf = env.getTeXFont(); + int style = env.getStyle(); + Char c = tf.getChar(symbol.getName(), style); + int i; + + for (i = 1; i <= size && tf.hasNextLarger(c); i++) + c = tf.getNextLarger(c, style); + + if (i <= size && !tf.hasNextLarger(c)) { + CharBox A = new CharBox(tf.getChar('A', "mathnormal", style)); + Box b = create(symbol.getName(), env, size*(A.getHeight() + A.getDepth())); + return b; + } + + return new CharBox(c); + } + + /** + * + * @param symbol the name of the delimiter symbol + * @param env the TeXEnvironment in which to create the delimiter box + * @param minHeight the minimum required total height of the box (height + depth). + * @return the box representing the delimiter variant that fits best according to + * the required minimum size. + */ + public static Box create(String symbol, TeXEnvironment env, float minHeight) { + TeXFont tf = env.getTeXFont(); + int style = env.getStyle(); + Char c = tf.getChar(symbol, style); + + // start with smallest character + Metrics m = c.getMetrics(); + float total = m.getHeight() + m.getDepth(); + + // try larger versions of the same character until minHeight has been + // reached + while (total < minHeight && tf.hasNextLarger(c)) { + c = tf.getNextLarger(c, style); + m = c.getMetrics(); + total = m.getHeight() + m.getDepth(); + } + if (total >= minHeight) { // tall enough character found + return new CharBox(c); + } else if (tf.isExtensionChar(c)) { + // construct tall enough vertical box + VerticalBox vBox = new VerticalBox(); + Extension ext = tf.getExtension(c, style); // extension info + + if (ext.hasTop()) { // insert top part + c = ext.getTop(); + vBox.add(new CharBox(c)); + } + + boolean middle = ext.hasMiddle(); + if (middle) { // insert middle part + c = ext.getMiddle(); + vBox.add(new CharBox(c)); + } + + if (ext.hasBottom()) { // insert bottom part + c = ext.getBottom(); + vBox.add(new CharBox(c)); + } + + // insert repeatable part until tall enough + c = ext.getRepeat(); + CharBox rep = new CharBox(c); + while (vBox.getHeight() + vBox.getDepth() <= minHeight) { + if (ext.hasTop() && ext.hasBottom()) { + vBox.add(1, rep); + if (middle) + vBox.add(vBox.getSize() - 1, rep); + } else if (ext.hasBottom()) + vBox.add(0, rep); + else + vBox.add(rep); + } + + return vBox; + } else + // no extensions, so return tallest possible character + return new CharBox(c); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DelimiterMappingNotFoundException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DelimiterMappingNotFoundException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DelimiterMappingNotFoundException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,61 @@ +/* DelimiterMappingNotFoundException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals a missing character-to-delimiter mapping. + * + * @author Kurt Vermeulen + */ +public class DelimiterMappingNotFoundException extends JMathTeXException { + + protected DelimiterMappingNotFoundException(char delimiter) { + super("No mapping found for the character '" + delimiter + "'! " + + "Insert a <" + TeXFormulaSettingsParser.CHARTODEL_MAPPING_EL + + ">-element in '" + TeXFormulaSettingsParser.RESOURCE_NAME + "'."); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DoubleFramedAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DoubleFramedAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/DoubleFramedAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,66 @@ +/* FBoxAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Color; + +/** + * An atom representing a boxed base atom. + */ +public class DoubleFramedAtom extends FBoxAtom { + + public DoubleFramedAtom(Atom base) { + super(base); + } + + public Box createBox(TeXEnvironment env) { + Box bbase = base.createBox(env); + float drt = env.getTeXFont().getDefaultRuleThickness(env.getStyle()); + float space = INTERSPACE * SpaceAtom.getFactor(TeXConstants.UNIT_EM, env); + float sspace = 1.5f * drt + 0.5f * SpaceAtom.getFactor(TeXConstants.UNIT_POINT, env); + return new FramedBox(new FramedBox(bbase, 0.75f * drt, space), 1.5f * drt, sspace); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Dummy.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Dummy.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Dummy.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,156 @@ +/* Dummy.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Used by RowAtom. The "textSymbol"-property and the type of an atom can change + * (according to the TeX-algorithms used). Or this atom can be replaced by a ligature, + * (if it was a CharAtom). But atoms cannot be changed, otherwise + * different boxes could be made from the same TeXFormula, and that is not desired! + * This "dummy atom" makes sure that changes to an atom (during the createBox-method of + * a RowAtom) will be reset. + */ +public class Dummy { + + private Atom el; + + private boolean textSymbol = false; + + private int type = -1; + + /** + * Creates a new Dummy for the given atom. + * + * @param a an atom + */ + public Dummy(Atom a) { + el = a; + } + + /** + * Changes the type of the atom + * + * @param t the new type + */ + public void setType(int t) { + type = t; + } + + /** + * Changes the type of the atom + * + * @param t the new type + */ + public int getType() { + return type; + } + + /** + * + * @return the changed type, or the old left type if it hasn't been changed + */ + public int getLeftType() { + return (type >= 0 ? type : el.getLeftType()); + } + + /** + * + * @return the changed type, or the old right type if it hasn't been changed + */ + public int getRightType() { + return (type >= 0 ? type : el.getRightType()); + } + + public boolean isCharSymbol() { + return el instanceof CharSymbol; + } + + public boolean isCharInMathMode() { + return el instanceof CharAtom && ((CharAtom) el).isMathMode(); + } + + /** + * This method will only be called if isCharSymbol returns true. + */ + public CharFont getCharFont(TeXFont tf) { + return ((CharSymbol) el).getCharFont(tf); + } + + /** + * Changes this atom into the given "ligature atom". + * + * @param a the ligature atom + */ + public void changeAtom(FixedCharAtom a) { + textSymbol = false; + type = -1; + el = a; + } + + public Box createBox(TeXEnvironment rs) { + if (textSymbol) + ((CharSymbol) el).markAsTextSymbol(); + Box b = el.createBox(rs); + if (textSymbol) + ((CharSymbol) el).removeMark(); // atom remains unchanged! + return b; + } + + public void markAsTextSymbol() { + textSymbol = true; + } + + public boolean isKern() { + return el instanceof SpaceAtom; + } + + // only for Row-elements + public void setPreviousAtom(Dummy prev) { + if (el instanceof Row) + ((Row) el).setPreviousAtom(prev); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/EmptyAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/EmptyAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/EmptyAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,58 @@ +/* EmptyAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An empty atom. + */ +public class EmptyAtom extends Atom { + + public EmptyAtom() { } + + public Box createBox(TeXEnvironment env) { + return new StrutBox(0, 0, 0, 0); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/EmptyFormulaException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/EmptyFormulaException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/EmptyFormulaException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,54 @@ +/* EmptyFormulaException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +public class EmptyFormulaException extends Exception { + + public EmptyFormulaException() { + super("Illegal operation with an empty Formula!"); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Extension.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Extension.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Extension.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,95 @@ +/* Extension.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Represents an extension character that is defined by Char-objects of it's 4 + * possible parts (null means part not present). + */ +public class Extension { + + // there ALLWAYS is a repeat character! (check TFM.isExtensionChar()) + private final Char top; + private final Char middle; + private final Char bottom; + private final Char repeat; + + public Extension(Char t, Char m, Char r, Char b) { + top = t; + middle = m; + repeat = r; + bottom = b; + } + + public boolean hasTop() { + return top != null; + } + + public boolean hasMiddle() { + return middle != null; + } + + public boolean hasBottom() { + return bottom != null; + } + + public Char getTop() { + return top; + } + + public Char getMiddle() { + return middle; + } + + public Char getRepeat() { + return repeat; + } + + public Char getBottom() { + return bottom; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FBoxAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FBoxAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FBoxAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,87 @@ +/* FBoxAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Color; + +/** + * An atom representing a boxed base atom. + */ +public class FBoxAtom extends Atom { + + public float INTERSPACE = 0.65f; + + // base atom + protected final Atom base; + protected Color bg = null, line = null; + + public FBoxAtom(Atom base) { + if (base == null) + this.base = new RowAtom(); // empty base + else { + this.base = base; + this.type = base.type; + } + } + + public FBoxAtom(Atom base, Color bg, Color line) { + this(base); + this.bg = bg; + this.line = line; + } + + public Box createBox(TeXEnvironment env) { + Box bbase = base.createBox(env); + float drt = env.getTeXFont().getDefaultRuleThickness(env.getStyle()); + float space = INTERSPACE * SpaceAtom.getFactor(TeXConstants.UNIT_EM, env); + if (bg == null) { + return new FramedBox(bbase, drt, space); + } else { + env.isColored = true; + return new FramedBox(bbase, drt, space, line, bg); + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FcscoreAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FcscoreAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FcscoreAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,72 @@ +/* FcscoreAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2013 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom with representing an L with a caron. + */ +public class FcscoreAtom extends Atom { + + private int N; + + public FcscoreAtom(int N) { + this.N = N; + } + + public int getLeftType() { + return TeXConstants.TYPE_ORDINARY; + } + + public int getRightType() { + return TeXConstants.TYPE_ORDINARY; + } + + public Box createBox(TeXEnvironment env) { + final float factor = 12 * SpaceAtom.getFactor(TeXConstants.UNIT_MU, env); + + return new FcscoreBox(N == 5 ? 4 : N, factor * 1f, factor * 0.07f, factor * 0.125f, N == 5); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FcscoreBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FcscoreBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FcscoreBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,117 @@ +/* FcscoreBox.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2013 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Graphics2D; +import java.awt.Stroke; +import java.awt.BasicStroke; +import java.awt.geom.AffineTransform; +import java.awt.geom.Line2D; + +/** + * A box representing glue. + */ +public class FcscoreBox extends Box { + + private int N; + private boolean strike; + private float space; + private float thickness; + + public FcscoreBox(int N, float h, float thickness, float space, boolean strike) { + this.N = N; + this.width = N * (thickness + space) + 2 * space; + this.height = h; + this.depth = 0; + this.strike = strike; + this.space = space; + this.thickness = thickness; + } + + public void draw(Graphics2D g2, float x, float y) { + AffineTransform transf = g2.getTransform(); + Stroke oldStroke = g2.getStroke(); + + final double sx = transf.getScaleX(); + final double sy = transf.getScaleY(); + double s = 1; + if (sx == sy) { + // There are rounding problems due to scale factor: lines could have different + // spacing... + // So the increment (space+thickness) is done in using integer. + s = sx; + AffineTransform t = (AffineTransform) transf.clone(); + t.scale(1 / sx, 1 / sy); + g2.setTransform(t); + } + + g2.setStroke(new BasicStroke((float) (s * thickness), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); + float th = thickness / 2.f; + final Line2D.Float line = new Line2D.Float(); + float xx = x + space; + xx = (float) (xx * s + (space / 2.f) * s); + final int inc = (int) Math.round((space + thickness) * s); + + for (int i = 0; i < N; i++) { + line.setLine(xx + th * s, (y - height) * s, xx + th * s, y * s); + g2.draw(line); + xx += inc; + } + + if (strike) { + + line.setLine((x + space) * s, (y - height / 2.f) * s, xx - s * space / 2, (y - height / 2.f) * s); + g2.draw(line); + } + + g2.setTransform(transf); + g2.setStroke(oldStroke); + } + + public int getLastFontId() { + return TeXFont.NO_FONT; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FencedAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FencedAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FencedAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,171 @@ +/* FencedAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet */ + +package org.scilab.forge.jlatexmath; + +import java.util.List; + +/** + * An atom representing a base atom surrounded with delimiters that change their size + * according to the height of the base. + */ +public class FencedAtom extends Atom { + + // parameters used in the TeX algorithm + private static final int DELIMITER_FACTOR = 901; + + private static final float DELIMITER_SHORTFALL = 5f; + + // base atom + private final Atom base; + + // delimiters + private SymbolAtom left = null; + private SymbolAtom right = null; + private final List middle; + + /** + * Creates a new FencedAtom from the given base and delimiters + * + * @param base the base to be surrounded with delimiters + * @param l the left delimiter + * @param r the right delimiter + */ + public FencedAtom(Atom base, SymbolAtom l, SymbolAtom r) { + this(base, l, null, r); + } + + public FencedAtom(Atom base, SymbolAtom l, List m, SymbolAtom r) { + if (base == null) + this.base = new RowAtom(); // empty base + else + this.base = base; + if (l == null || !l.getName().equals("normaldot")) { + left = l; + } + if (r == null || !r.getName().equals("normaldot")) { + right = r; + } + middle = m; + } + + public int getLeftType() { + return TeXConstants.TYPE_INNER; + } + + public int getRightType() { + return TeXConstants.TYPE_INNER; + } + + /** + * Centers the given box with resprect to the given axis, by setting an appropriate + * shift value. + * + * @param box + * box to be vertically centered with respect to the axis + */ + private static void center(Box box, float axis) { + float h = box.getHeight(), total = h + box.getDepth(); + box.setShift(-(total / 2 - h) - axis); + } + + public Box createBox(TeXEnvironment env) { + TeXFont tf = env.getTeXFont(); + Box content = base.createBox(env); + float shortfall = DELIMITER_SHORTFALL * SpaceAtom.getFactor(TeXConstants.UNIT_POINT, env); + float axis = tf.getAxisHeight(env.getStyle()); + float delta = Math.max(content.getHeight() - axis, content.getDepth() + axis); + float minHeight = Math.max((delta / 500) * DELIMITER_FACTOR, 2 * delta - shortfall); + + // construct box + HorizontalBox hBox = new HorizontalBox(); + + if (middle != null) { + for (int i = 0; i < middle.size(); i++) { + MiddleAtom at = middle.get(i); + if (at.base instanceof SymbolAtom) { + Box b = DelimiterFactory.create(((SymbolAtom) at.base).getName(), env, minHeight); + center(b, axis); + at.box = b; + } + } + if (middle.size() != 0) { + content = base.createBox(env); + } + } + + // left delimiter + if (left != null) { + Box b = DelimiterFactory.create(left.getName(), env, minHeight); + center(b, axis); + hBox.add(b); + } + + // glue between left delimiter and content (if not whitespace) + if (!(base instanceof SpaceAtom)) { + hBox.add(Glue.get(TeXConstants.TYPE_OPENING, base.getLeftType(), env)); + } + + // add content + hBox.add(content); + + // glue between right delimiter and content (if not whitespace) + if (!(base instanceof SpaceAtom)) { + hBox.add(Glue.get(base.getRightType(), TeXConstants.TYPE_CLOSING, env)); + } + + // right delimiter + if (right != null) { + Box b = DelimiterFactory.create(right.getName(), env, minHeight); + center(b, axis); + hBox.add(b); + } + + return hBox; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FixedCharAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FixedCharAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FixedCharAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,70 @@ +/* FixedCharAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a fixed character (not depending on a text style). + */ +public class FixedCharAtom extends CharSymbol { + + private final CharFont cf; + + public FixedCharAtom(CharFont c) { + cf = c; + } + + public CharFont getCharFont(TeXFont tf) { + return cf; + } + + public Box createBox(TeXEnvironment env) { + TeXFont tf = env.getTeXFont(); + Char c = tf.getChar(cf, env.getStyle()); + return new CharBox(c); + } + +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FontAlreadyLoadedException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FontAlreadyLoadedException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FontAlreadyLoadedException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,54 @@ +/* FontAlreadyLoadedException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +public class FontAlreadyLoadedException extends XMLResourceParseException { + + public FontAlreadyLoadedException(String msg) { + super(msg); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FontInfo.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FontInfo.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FontInfo.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,321 @@ +/* FontInfo.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Font; +import java.util.HashMap; +import java.util.Map; + +/** + * Contains all the font information for 1 font. + */ +public class FontInfo { + + /** + * Maximum number of character codes in a TeX font. + */ + public static final int NUMBER_OF_CHAR_CODES = 256; + + private static Map fonts = new HashMap(); + + private class CharCouple { + + private final char left, right; + + CharCouple(char l, char r) { + left = l; + right = r; + } + + public boolean equals(Object o) { + CharCouple lig = (CharCouple) o; + return left == lig.left && right == lig.right; + } + + public int hashCode() { + return (left + right) % 128; + } + } + + // ID + private final int fontId; + + // font + private Font font; + private final Object base; + private final String path; + private final String fontName; + + private final Map lig = new HashMap (); + private final Map kern = new HashMap(); + private float[][] metrics; + private CharFont[] nextLarger; + private int[][] extensions; + private HashMap unicode = null; + + // skew character of the font (used for positioning accents) + private char skewChar = (char) -1; + + // general parameters for this font + private final float xHeight; + private final float space; + private final float quad; + private int boldId; + private int romanId; + private int ssId; + private int ttId; + private int itId; + protected final String boldVersion; + protected final String romanVersion; + protected final String ssVersion; + protected final String ttVersion; + protected final String itVersion; + + public FontInfo(int fontId, Object base, String path, String fontName, int unicode, float xHeight, float space, float quad, String boldVersion, String romanVersion, String ssVersion, String ttVersion, String itVersion) { + this.fontId = fontId; + this.base = base; + this.path = path; + this.fontName = fontName; + this.xHeight = xHeight; + this.space = space; + this.quad = quad; + this.boldVersion = boldVersion; + this.romanVersion = romanVersion; + this.ssVersion = ssVersion; + this.ttVersion = ttVersion; + this.itVersion = itVersion; + int num = NUMBER_OF_CHAR_CODES; + if (unicode != 0) { + this.unicode = new HashMap(unicode); + num = unicode; + } + metrics = new float[num][]; + nextLarger = new CharFont[num]; + extensions = new int[num][]; + fonts.put(fontId, this); + } + + /** + * + * @param left + * left character + * @param right + * right character + * @param k + * kern value + */ + public void addKern(char left, char right, float k) { + kern.put(new CharCouple(left, right), new Float(k)); + } + + /** + * @param left + * left character + * @param right + * right character + * @param ligChar + * ligature to replace left and right character + */ + public void addLigature(char left, char right, char ligChar) { + lig.put(new CharCouple(left, right), new Character(ligChar)); + } + + public int[] getExtension(char ch) { + if (unicode == null) + return extensions[ch]; + return extensions[unicode.get(ch)]; + } + + public float getKern(char left, char right, float factor) { + Object obj = kern.get(new CharCouple(left, right)); + if (obj == null) + return 0; + else + return ((Float) obj).floatValue() * factor; + } + + public CharFont getLigature(char left, char right) { + Object obj = lig.get(new CharCouple(left, right)); + if (obj == null) + return null; + else + return new CharFont(((Character) obj).charValue(), fontId); + } + + public float[] getMetrics(char c) { + if (unicode == null) + return metrics[c]; + return metrics[unicode.get(c)]; + } + + public CharFont getNextLarger(char ch) { + if (unicode == null) + return nextLarger[ch]; + return nextLarger[unicode.get(ch)]; + } + + public float getQuad(float factor) { + return quad * factor; + } + + /** + * @return the skew character of the font (for the correct positioning of + * accents) + */ + public char getSkewChar() { + return skewChar; + } + + public float getSpace(float factor) { + return space * factor; + } + + public float getXHeight(float factor) { + return xHeight * factor; + } + + public boolean hasSpace() { + return space > TeXFormula.PREC; + } + + public void setExtension(char ch, int[] ext) { + if (unicode == null) + extensions[ch] = ext; + else if (!unicode.containsKey(ch)) { + char s = (char)unicode.size(); + unicode.put(ch, s); + extensions[s] = ext; + } else + extensions[unicode.get(ch)] = ext; + } + + public void setMetrics(char c, float[] arr) { + if (unicode == null) + metrics[c] = arr; + else if (!unicode.containsKey(c)) { + char s = (char)unicode.size(); + unicode.put(c, s); + metrics[s] = arr; + } else + metrics[unicode.get(c)] = arr; + } + + public void setNextLarger(char ch, char larger, int fontLarger) { + if (unicode == null) + nextLarger[ch] = new CharFont(larger, fontLarger); + else if (!unicode.containsKey(ch)) { + char s = (char)unicode.size(); + unicode.put(ch, s); + nextLarger[s] = new CharFont(larger, fontLarger); + } else + nextLarger[unicode.get(ch)] = new CharFont(larger, fontLarger); + } + + public void setSkewChar(char c) { + skewChar = c; + } + + public int getId() { + return fontId; + } + + public int getBoldId() { + return boldId; + } + + public int getRomanId() { + return romanId; + } + + public int getTtId() { + return ttId; + } + + public int getItId() { + return itId; + } + + public int getSsId() { + return ssId; + } + + public void setSsId(int id) { + ssId = id == -1 ? fontId : id; + } + + public void setTtId(int id) { + ttId = id == -1 ? fontId : id; + } + + public void setItId(int id) { + itId = id == -1 ? fontId : id; + } + + public void setRomanId(int id) { + romanId = id == -1 ? fontId : id; + } + + public void setBoldId(int id) { + boldId = id == -1 ? fontId : id; + } + + public Font getFont() { + if (font == null) { + if (base == null) { + font = DefaultTeXFontParser.createFont(path); + } else { + font = DefaultTeXFontParser.createFont(base.getClass().getResourceAsStream(path), fontName); + } + } + return font; + } + + public static Font getFont(int id) { + return fonts.get(id).getFont(); + } +} + Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FormulaNotFoundException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FormulaNotFoundException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FormulaNotFoundException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,61 @@ +/* FormulaNotFoundException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals that unknown predefined TeXFormula name was used. + * + * @author Kurt Vermeulen + */ +public class FormulaNotFoundException extends JMathTeXException { + + protected FormulaNotFoundException(String name) { + super("There's no predefined TeXFormula with the name '" + name + + "' defined in '" + PredefinedTeXFormulaParser.RESOURCE_NAME + + "'!"); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FractionAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FractionAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FractionAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,293 @@ +/* FractionAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a fraction. + */ +public class FractionAtom extends Atom { + + // whether the default thickness should not be used for the fraction line + private boolean noDefault = false; + + // unit used for the thickness of the fraction line + private int unit; + + // alignment settings for the numerator and denominator + private int numAlign = TeXConstants.ALIGN_CENTER, + denomAlign = TeXConstants.ALIGN_CENTER; + + // the atoms representing the numerator and denominator + private Atom numerator, denominator; + + // thickness of the fraction line + private float thickness; + + // thickness of the fraction line relative to the default thickness + private float defFactor; + + // whether the "defFactor" value should be used + private boolean defFactorSet = false; + + /** + * Uses the default thickness for the fraction line + * + * @param num the numerator + * @param den the denominator + */ + public FractionAtom(Atom num, Atom den) { + this(num, den, true); + } + + /** + * Uses the default thickness for the fraction line + * + * @param num the numerator + * @param den the denominator + * @param rule whether the fraction line should be drawn + */ + public FractionAtom(Atom num, Atom den, boolean rule) { + this(num, den, !rule, TeXConstants.UNIT_PIXEL, 0f); + } + + /** + * Depending on noDef, the given thickness and unit will be used (<-> the default + * thickness). + * + * @param num the numerator + * @param den the denominator + * @param noDef whether the default thickness should not be used for the fraction line + * @param unit a unit constant for the line thickness + * @param t the thickness of the fraction line (in the given unit) + * @throws InvalidUnitException if the given integer is not a valid unit constant + */ + public FractionAtom(Atom num, Atom den, boolean noDef, int unit, float t) + throws InvalidUnitException { + // check unit + SpaceAtom.checkUnit(unit); + + // unit ok + numerator = num; + denominator = den; + noDefault = noDef; + thickness = t; + this.unit = unit; + type = TeXConstants.TYPE_INNER; + } + + /** + * Uses the default thickness for the fraction line. + * + * @param num the numerator + * @param den the denominator + * @param rule whether the fraction line should be drawn + * @param numAlign alignment of the numerator + * @param denomAlign alignment of the denominator + */ + public FractionAtom(Atom num, Atom den, boolean rule, int numAlign, + int denomAlign) { + this(num, den, rule); + this.numAlign = checkAlignment(numAlign); + this.denomAlign = checkAlignment(denomAlign); + } + + /** + * The thickness of the fraction line will be "defFactor" times the default thickness. + * + * @param num the numerator + * @param den the denominator + * @param defFactor the thickness of the fraction line relative to the default thickness + * @param numAlign alignment of the numerator + * @param denomAlign alignment of the denominator + */ + public FractionAtom(Atom num, Atom den, float defFactor, int numAlign, + int denomAlign) { + this(num, den, true, numAlign, denomAlign); + this.defFactor = defFactor; + defFactorSet = true; + } + + /** + * The thickness of the fraction line is determined by the given value "t" in the + * given unit. + * + * @param num the numerator + * @param den the denominator + * @param unit a unit constant for the line thickness + * @param t the thickness of the fraction line (in the given unit) + * @param numAlign alignment of the numerator + * @param denomAlign alignment of the denominator + */ + public FractionAtom(Atom num, Atom den, int unit, float t, int numAlign, + int denomAlign) { + this(num, den, unit, t); + this.numAlign = checkAlignment(numAlign); + this.denomAlign = checkAlignment(denomAlign); + } + + /** + * The thickness of the fraction line is determined by the given value "t" in the + * given unit. + * + * @param num the numerator + * @param den the denominator + * @param unit a unit constant for the line thickness + * @param t the thickness of the fraction line (in the given unit) + */ + public FractionAtom(Atom num, Atom den, int unit, float t) { + this(num, den, true, unit, t); + } + + // Checks if the alignment constant is valid. + // If not, a default value will be used. + private int checkAlignment(int align) { + if (align == TeXConstants.ALIGN_LEFT || + align == TeXConstants.ALIGN_RIGHT) + return align; + else + return TeXConstants.ALIGN_CENTER; + } + + public Box createBox(TeXEnvironment env) { + TeXFont tf = env.getTeXFont(); + int style = env.getStyle(); + // set thickness to default if default value should be used + float drt = tf.getDefaultRuleThickness(style); + if (noDefault) + // convert the thickness to pixels + thickness *= SpaceAtom.getFactor(unit, env); + else + thickness = (defFactorSet ? defFactor * drt : drt); + + // create equal width boxes (in appropriate styles) + Box num = (numerator == null ? new StrutBox(0, 0, 0, 0) : numerator + .createBox(env.numStyle())); + Box denom = (denominator == null ? new StrutBox(0, 0, 0, 0) : denominator + .createBox(env.denomStyle())); + + if (num.getWidth() < denom.getWidth()) + num = new HorizontalBox(num, denom.getWidth(), numAlign); + else + denom = new HorizontalBox(denom, num.getWidth(), denomAlign); + + // calculate default shift amounts + float shiftUp, shiftDown; + if (style < TeXConstants.STYLE_TEXT) { + shiftUp = tf.getNum1(style); + shiftDown = tf.getDenom1(style); + } else { + shiftDown = tf.getDenom2(style); + if (thickness > 0) + shiftUp = tf.getNum2(style); + else + shiftUp = tf.getNum3(style); + } + + // upper part of vertical box = numerator + VerticalBox vBox = new VerticalBox(); + vBox.add(num); + + // calculate clearance clr, adjust shift amounts and create vertical box + float clr, delta, axis = tf.getAxisHeight(style); + + if (thickness > 0) { // WITH fraction rule + // clearance clr + if (style < TeXConstants.STYLE_TEXT) + clr = 3 * thickness; + else + clr = thickness; + + // adjust shift amounts + delta = thickness / 2; + float kern1 = shiftUp - num.getDepth() - (axis + delta), kern2 = axis + - delta - (denom.getHeight() - shiftDown); + float delta1 = clr - kern1, delta2 = clr - kern2; + if (delta1 > 0) { + shiftUp += delta1; + kern1 += delta1; + } + if (delta2 > 0) { + shiftDown += delta2; + kern2 += delta2; + } + + // fill vertical box + vBox.add(new StrutBox(0, kern1, 0, 0)); + vBox.add(new HorizontalRule(thickness, num.getWidth(), 0)); + vBox.add(new StrutBox(0, kern2, 0, 0)); + } else { // WITHOUT fraction rule + // clearance clr + if (style < TeXConstants.STYLE_TEXT) + clr = 7 * drt; + else + clr = 3 * drt; + + // adjust shift amounts + float kern = shiftUp - num.getDepth() + - (denom.getHeight() - shiftDown); + delta = (clr - kern) / 2; + if (delta > 0) { + shiftUp += delta; + shiftDown += delta; + kern += 2 * delta; + } + + // fill vertical box + vBox.add(new StrutBox(0, kern, 0, 0)); + } + + // finish vertical box + vBox.add(denom); + vBox.setHeight(shiftUp + num.getHeight()); + vBox.setDepth(shiftDown + denom.getDepth()); + + // \nulldelimiterspace is set by default to 1.2pt = 0.12em) + float f = new SpaceAtom(TeXConstants.UNIT_EM, 0.12f, 0, 0).createBox(env).getWidth(); + + return new HorizontalBox(vBox, vBox.getWidth() + 2 * f, TeXConstants.ALIGN_CENTER); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FramedBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FramedBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/FramedBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,107 @@ +/* FramedBox.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Graphics2D; +import java.awt.Stroke; +import java.awt.BasicStroke; +import java.awt.geom.Rectangle2D; +import java.awt.Color; + +/** + * A box representing a rotated box. + */ +public class FramedBox extends Box { + + protected Box box; + protected float thickness; + protected float space; + private Color line; + private Color bg; + + public FramedBox(Box box, float thickness, float space) { + this.box = box; + this.width = box.width + 2 * thickness + 2 * space; + this.height = box.height + thickness + space; + this.depth = box.depth + thickness + space; + this.shift = box.shift; + this.thickness = thickness; + this.space = space; + } + + public FramedBox(Box box, float thickness, float space, Color line, Color bg) { + this(box, thickness, space); + this.line = line; + this.bg = bg; + } + + public void draw(Graphics2D g2, float x, float y) { + Stroke st = g2.getStroke(); + g2.setStroke(new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); + float th = thickness / 2; + if (bg != null) { + Color prev = g2.getColor(); + g2.setColor(bg); + g2.fill(new Rectangle2D.Float(x + th, y - height + th, width - thickness, height + depth - thickness)); + g2.setColor(prev); + } + if (line != null) { + Color prev = g2.getColor(); + g2.setColor(line); + g2.draw(new Rectangle2D.Float(x + th, y - height + th, width - thickness, height + depth - thickness)); + g2.setColor(prev); + } else { + g2.draw(new Rectangle2D.Float(x + th, y - height + th, width - thickness, height + depth - thickness)); + } + //drawDebug(g2, x, y); + g2.setStroke(st); + box.draw(g2, x + space + thickness, y); + } + + public int getLastFontId() { + return box.getLastFontId(); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GeoGebraLogoAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GeoGebraLogoAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GeoGebraLogoAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,65 @@ +/* GeoGebraLogoAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +public class GeoGebraLogoAtom extends Atom { + + public GeoGebraLogoAtom() { + } + + public int getLeftType() { + return TeXConstants.TYPE_ORDINARY; + } + + public int getRightType() { + return TeXConstants.TYPE_ORDINARY; + } + + public Box createBox(TeXEnvironment env) { + CharBox o = new CharBox(env.getTeXFont().getDefaultChar('o', env.getStyle())); + return new GeoGebraLogoBox(o.width, o.height); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GeoGebraLogoBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GeoGebraLogoBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GeoGebraLogoBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,107 @@ +/* GraphicsBox.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Graphics2D; +import java.awt.Color; +import java.awt.BasicStroke; +import java.awt.Stroke; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; + +/** + * A box representing a box containing a graphics. + */ +public class GeoGebraLogoBox extends Box { + + private static final Color gray = new Color(102, 102, 102); + private static final Color blue = new Color(153, 153, 255); + + private static final BasicStroke st = new BasicStroke(3.79999995f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 4f); + private static final BasicStroke stC = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 4f); + + public GeoGebraLogoBox(float w, float h) { + this.depth = 0; + this.height = h; + this.width = w; + this.shift = 0; + } + + public void draw(Graphics2D g2, float x, float y) { + AffineTransform oldAt = g2.getTransform(); + Color oldC = g2.getColor(); + Stroke oldS = g2.getStroke(); + g2.translate(x + 0.25f * height / 2.15f, y - 1.75f / 2.15f * height); + g2.setColor(gray); + g2.setStroke(st); + g2.scale(0.05f * height / 2.15f, 0.05f * height / 2.15f); + g2.rotate(-26 * Math.PI / 180, 20.5, 17.5); + g2.drawArc(0, 0, 43, 32, 0, 360); + g2.rotate(26 * Math.PI / 180, 20.5, 17.5); + g2.setStroke(oldS); + drawCircle(g2, 16f, -5f); + drawCircle(g2, -1f, 7f); + drawCircle(g2, 5f, 28f); + drawCircle(g2, 27f, 24f); + drawCircle(g2, 36f, 3f); + g2.setStroke(oldS); + g2.setTransform(oldAt); + g2.setColor(oldC); + } + + private static void drawCircle(Graphics2D g2, float x, float y) { + g2.setColor(blue); + g2.translate(x, y); + g2.fillArc(0, 0, 8, 8, 0, 360); + g2.setColor(Color.BLACK); + g2.drawArc(0, 0, 8, 8, 0, 360); + g2.translate(-x, -y); + } + + public int getLastFontId() { + return 0; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Glue.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Glue.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Glue.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,114 @@ +/* Glue.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Represents glue by its 3 components. Contains the "glue rules". + */ +public class Glue { + + // the glue components + private final float space; + private final float stretch; + private final float shrink; + + private final String name; + + // contains the different glue types + private static Glue[] glueTypes; + + // the glue table representing the "glue rules" (as in TeX) + private static final int[][][] glueTable; + + static { + GlueSettingsParser parser = new GlueSettingsParser(); + glueTypes = parser.getGlueTypes(); + glueTable = parser.createGlueTable(); + } + + public Glue(float space, float stretch, float shrink, String name) { + this.space = space; + this.stretch = stretch; + this.shrink = shrink; + this.name = name; + } + + /** + * Name of this glue object. + */ + public String getName () { + return this.name; + } + + /** + * Creates a box representing the glue type according to the "glue rules" based + * on the atom types between which the glue must be inserted. + * + * @param lType left atom type + * @param rType right atom type + * @param env the TeXEnvironment + * @return a box containing representing the glue + */ + public static Box get(int lType, int rType, TeXEnvironment env) { + // types > INNER are considered of type ORD for glue calculations + int l = (lType > TeXConstants.TYPE_INNER ? TeXConstants.TYPE_ORDINARY : lType); + int r = (rType > TeXConstants.TYPE_INNER ? TeXConstants.TYPE_ORDINARY : rType); + + // search right glue-type in "glue-table" + int glueType = glueTable[l][r][env.getStyle() / 2]; + + return glueTypes[glueType].createBox(env); + } + + private Box createBox(TeXEnvironment env) { + TeXFont tf = env.getTeXFont(); + // use "quad" from a font marked as an "mu font" + float quad = tf.getQuad(env.getStyle(), tf.getMuFontId()); + + return new GlueBox((space / 18.0f) * quad, (stretch / 18.0f) * quad, (shrink / 18.0f) * quad); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GlueBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GlueBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GlueBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,71 @@ +/* GlueBox.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Graphics2D; + +/** + * A box representing glue. + */ +public class GlueBox extends Box { + + protected float stretch = 0, shrink = 0; + + public GlueBox(float space, float stretch, float shrink) { + this.width = space; + this.stretch = stretch; + this.shrink = shrink; + } + + public void draw(Graphics2D g2, float x, float y) { + // no visible effect + } + + public int getLastFontId() { + return TeXFont.NO_FONT; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GlueSettingsParser.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GlueSettingsParser.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GlueSettingsParser.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,219 @@ +/* GlueSettingsParser.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilderFactory; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * Parses the glue settings (different types and rules) from an XML-file. + */ +public class GlueSettingsParser { + + private static final String RESOURCE_NAME = "GlueSettings.xml"; + + private final Map typeMappings = new HashMap(); + private final Map glueTypeMappings = new HashMap(); + private Glue[] glueTypes; + + private final Map styleMappings = new HashMap(); + + private Element root; + + public GlueSettingsParser() throws ResourceParseException { + try { + setTypeMappings(); + setStyleMappings(); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setIgnoringElementContentWhitespace(true); + factory.setIgnoringComments(true); + root = factory.newDocumentBuilder().parse(GlueSettingsParser.class.getResourceAsStream(RESOURCE_NAME)).getDocumentElement(); + parseGlueTypes(); + } catch (Exception e) { // JDOMException or IOException + throw new XMLResourceParseException(RESOURCE_NAME, e); + } + } + + private void setStyleMappings() { + styleMappings.put("display", TeXConstants.STYLE_DISPLAY / 2); + styleMappings.put("text", TeXConstants.STYLE_TEXT / 2); + styleMappings.put("script", TeXConstants.STYLE_SCRIPT / 2); + styleMappings.put("script_script", TeXConstants.STYLE_SCRIPT_SCRIPT / 2); // autoboxing + } + + private void parseGlueTypes() throws ResourceParseException { + List glueTypesList = new ArrayList (); + Element types = (Element)root.getElementsByTagName("GlueTypes").item(0); + int defaultIndex = -1; + int index = 0; + if (types != null) { // element present + NodeList list = types.getElementsByTagName("GlueType"); + for (int i = 0; i < list.getLength(); i++) { + Element type = (Element)list.item(i); + // retrieve required attribute value, throw exception if not set + String name = getAttrValueAndCheckIfNotNull("name", type); + Glue glue = createGlue(type, name); + if (name.equalsIgnoreCase("default")) // default must have value + defaultIndex = index; + glueTypesList.add(glue); + index ++; + } + } + if (defaultIndex < 0) { + // create a default glue object if missing + defaultIndex = index; + glueTypesList.add(new Glue(0,0,0,"default")); + } + + glueTypes = glueTypesList.toArray(new Glue[glueTypesList.size()]); + + // make sure default glue is at the front + if (defaultIndex > 0) { + Glue tmp = glueTypes[defaultIndex]; + glueTypes[defaultIndex] = glueTypes[0]; + glueTypes[0] = tmp; + } + + // make reverse map + for (int i = 0; i < glueTypes.length; i++) { + glueTypeMappings.put(glueTypes[i].getName(), i); + } + } + + private Glue createGlue(Element type, String name) throws ResourceParseException { + final String[] names = { "space", "stretch", "shrink" }; + float[] values = new float[names.length]; + for (int i = 0; i < names.length; i++) { + double val = 0; // default value if attribute not present + String attrVal = null; + try { + attrVal = type.getAttribute(names[i]); + if (!attrVal.equals("")) // attribute present + val = Double.parseDouble(attrVal); + } catch (NumberFormatException e) { + throw new XMLResourceParseException(RESOURCE_NAME, "GlueType", + names[i], "has an invalid real value '" + attrVal + "'!"); + } + values[i] = (float) val; + } + return new Glue(values[0], values[1], values[2], name); + } + + private void setTypeMappings() { + typeMappings.put("ord", TeXConstants.TYPE_ORDINARY); + typeMappings.put("op", TeXConstants.TYPE_BIG_OPERATOR); + typeMappings.put("bin", TeXConstants.TYPE_BINARY_OPERATOR); + typeMappings.put("rel", TeXConstants.TYPE_RELATION); + typeMappings.put("open", TeXConstants.TYPE_OPENING); + typeMappings.put("close", TeXConstants.TYPE_CLOSING); + typeMappings.put("punct", TeXConstants.TYPE_PUNCTUATION); + typeMappings.put("inner", TeXConstants.TYPE_INNER); // autoboxing + } + + public Glue[] getGlueTypes() { + return glueTypes; + } + + public int[][][] createGlueTable() throws ResourceParseException { + int size = typeMappings.size(); + int[][][] table = new int[size][size][styleMappings.size()]; + Element glueTable = (Element)root.getElementsByTagName("GlueTable").item(0); + if (glueTable != null) { // element present + // iterate all the "Glue"-elements + NodeList list = glueTable.getElementsByTagName("Glue"); + for (int i = 0; i < list.getLength(); i++) { + Element glue = (Element)list.item(i); + // retrieve required attribute values and throw exception if they're not set + String left = getAttrValueAndCheckIfNotNull("lefttype", glue); + String right = getAttrValueAndCheckIfNotNull("righttype", glue); + String type = getAttrValueAndCheckIfNotNull("gluetype", glue); + // iterate all the "Style"-elements + NodeList listG = glue.getElementsByTagName("Style"); + for (int j = 0; j < listG.getLength(); j++) { + Element style = (Element)listG.item(j); + String styleName = getAttrValueAndCheckIfNotNull("name", style); + // retrieve mappings + Object l = typeMappings.get(left); + Object r = typeMappings.get(right); + Object st = styleMappings.get(styleName); + Object val = glueTypeMappings.get(type); + // throw exception if unknown value set + checkMapping(l, "Glue", "lefttype", left); + checkMapping(r, "Glue", "righttype", right); + checkMapping(val, "Glue", "gluetype", type); + checkMapping(st, "Style", "name", styleName); + // put value in table + table[((Integer) l).intValue()][((Integer) r).intValue()][((Integer) st).intValue()] = ((Integer) val).intValue(); + } + } + } + return table; + } + + private static void checkMapping(Object val, String elementName, + String attrName, String attrValue) throws ResourceParseException { + if (val == null) + throw new XMLResourceParseException(RESOURCE_NAME, elementName, + attrName, "has an unknown value '" + attrValue + "'!"); + } + + private static String getAttrValueAndCheckIfNotNull(String attrName, + Element element) throws ResourceParseException { + String attrValue = element.getAttribute(attrName); + if (attrValue.equals("")) + throw new XMLResourceParseException(RESOURCE_NAME, element.getTagName(), + attrName, null); + return attrValue; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GraphicsAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GraphicsAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GraphicsAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,152 @@ +/* GraphicsAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.image.ImageObserver; +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.awt.MediaTracker; +import java.awt.Label; +import java.awt.Graphics2D; +import java.awt.Toolkit; +import java.io.File; +import java.net.URL; +import java.net.MalformedURLException; +import java.util.Map; + +/** + * An atom representing an atom containing a graphic. + */ +public class GraphicsAtom extends Atom { + + private Image image = null; + private BufferedImage bimage; + private Label c; + private int w, h; + + private Atom base; + private boolean first = true; + private int interp = -1; + + public GraphicsAtom(String path, String option) { + File f = new File(path); + if (!f.exists()) { + try { + URL url = new URL(path); + image = Toolkit.getDefaultToolkit().getImage(url); + } catch (MalformedURLException e) { + image = null; + } + } else { + image = Toolkit.getDefaultToolkit().getImage(path); + } + + if (image != null) { + c = new Label(); + MediaTracker tracker = new MediaTracker(c); + tracker.addImage(image, 0); + try { + tracker.waitForID(0); + } catch (InterruptedException e) { + image = null; + } + } + draw(); + buildAtom(option); + } + + protected void buildAtom(String option) { + base = this; + Map options = ParseOption.parseMap(option); + if (options.containsKey("width") || options.containsKey("height")) { + base = new ResizeAtom(base, options.get("width"), options.get("height"), options.containsKey("keepaspectratio")); + } + if (options.containsKey("scale")) { + double scl = Double.parseDouble(options.get("scale")); + base = new ScaleAtom(base, scl, scl); + } + if (options.containsKey("angle") || options.containsKey("origin")) { + base = new RotateAtom(base, options.get("angle"), options.get("origin")); + } + if (options.containsKey("interpolation")) { + String meth = options.get("interpolation"); + if (meth.equalsIgnoreCase("bilinear")) { + interp = GraphicsBox.BILINEAR; + } else if (meth.equalsIgnoreCase("bicubic")) { + interp = GraphicsBox.BICUBIC; + } else if (meth.equalsIgnoreCase("nearest_neighbor")) { + interp = GraphicsBox.NEAREST_NEIGHBOR; + } + } + } + + public void draw() { + if (image != null) { + w = image.getWidth(c); + h = image.getHeight(c); + bimage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); + Graphics2D g2d = bimage.createGraphics(); + g2d.drawImage(image, 0, 0, null); + g2d.dispose(); + } + } + + public Box createBox(TeXEnvironment env) { + if (image != null) { + if (first) { + first = false; + return base.createBox(env); + } else { + env.isColored = true; + float width = w * SpaceAtom.getFactor(TeXConstants.UNIT_PIXEL, env); + float height = h * SpaceAtom.getFactor(TeXConstants.UNIT_PIXEL, env); + return new GraphicsBox(bimage, width, height, env.getSize(), interp); + } + } + + return new TeXFormula("\\text{ No such image file ! }").root.createBox(env); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GraphicsBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GraphicsBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/GraphicsBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,107 @@ +/* GraphicsBox.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; +import java.awt.RenderingHints; + +/** + * A box representing a box containing a graphics. + */ +public class GraphicsBox extends Box { + + public final static int BILINEAR = 0; + public final static int NEAREST_NEIGHBOR = 1; + public final static int BICUBIC = 2; + + private BufferedImage image; + private float scl; + private Object interp; + + public GraphicsBox(BufferedImage image, float width, float height, float size, int interpolation) { + this.image = image; + this.width = width; + this.height = height; + this.scl = 1 / size; + depth = 0; + shift = 0; + switch (interpolation) { + case BILINEAR : + interp = RenderingHints.VALUE_INTERPOLATION_BILINEAR; + break; + case NEAREST_NEIGHBOR : + interp = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; + break; + case BICUBIC : + interp = RenderingHints.VALUE_INTERPOLATION_BICUBIC; + break; + default : + interp = null; + } + } + + public void draw(Graphics2D g2, float x, float y) { + AffineTransform oldAt = g2.getTransform(); + Object oldKey = null; + if (interp != null) { + oldKey = g2.getRenderingHint(RenderingHints.KEY_INTERPOLATION); + g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, interp); + } + g2.translate(x, y - height); + g2.scale(scl, scl); + g2.drawImage(image, 0, 0, null); + g2.setTransform(oldAt); + if (oldKey != null) { + g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, oldKey); + } + } + + public int getLastFontId() { + return 0; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/HdotsforAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/HdotsforAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/HdotsforAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,82 @@ +/* HdotsforAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom used in array mode to write on several columns. + */ +public class HdotsforAtom extends MulticolumnAtom { + + private static final Atom ldotp = SymbolAtom.get("ldotp"); + private static final Atom thin = new SpaceAtom(TeXConstants.THINMUSKIP); + private float coeff; + + public HdotsforAtom(int n, float coeff) { + super(n, "c", ldotp); + this.coeff = coeff; + } + + public Box createBox(TeXEnvironment env) { + Box sp = new StrutBox(coeff * thin.createBox(env).getWidth(), 0, 0, 0); + HorizontalBox db = new HorizontalBox(sp); + db.add(ldotp.createBox(env)); + db.add(sp); + Box b; + if (w != 0) { + float dw = db.getWidth(); + b = new HorizontalBox(db); + while (b.getWidth() < w) { + b.add(db); + } + b = new HorizontalBox(b, w, TeXConstants.ALIGN_CENTER); + } else { + b = db; + } + + b.type = TeXConstants.TYPE_MULTICOLUMN; + return b; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/HlineAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/HlineAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/HlineAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,75 @@ +/* HlineAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a hline in array environment + */ +public class HlineAtom extends Atom { + + private float width; + private float shift; + + public HlineAtom() { + } + + public void setWidth(float width) { + this.width = width; + } + + public void setShift(float shift) { + this.shift = shift; + } + + public Box createBox(TeXEnvironment env) { + float drt = env.getTeXFont().getDefaultRuleThickness(env.getStyle()); + Box b = new HorizontalRule(drt, width, shift, false); + VerticalBox vb = new VerticalBox(); + vb.add(b); + vb.type = TeXConstants.TYPE_HLINE; + return vb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/HorizontalBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/HorizontalBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/HorizontalBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,190 @@ +/* HorizontalBox.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; + +/** + * A box composed of a horizontal row of child boxes. + */ +public class HorizontalBox extends Box { + + private float curPos = 0; // NOPMD + protected List breakPositions; + + public HorizontalBox(Box b, float w, int alignment) { + if (w != Float.POSITIVE_INFINITY) { + float rest = w - b.getWidth(); + if (rest > 0) { + if (alignment == TeXConstants.ALIGN_CENTER || alignment == TeXConstants.ALIGN_NONE) { + StrutBox s = new StrutBox(rest / 2, 0, 0, 0); + add(s); + add(b); + add(s); + } else if (alignment == TeXConstants.ALIGN_LEFT) { + add(b); + add(new StrutBox(rest, 0, 0, 0)); + } else if (alignment == TeXConstants.ALIGN_RIGHT) { + add(new StrutBox(rest, 0, 0, 0)); + add(b); + } else { + add(b); + } + } else { + add(b); + } + } else { + add(b); + } + } + + public HorizontalBox(Box b) { + add(b); + } + + public HorizontalBox() { + // basic horizontal box + } + + public HorizontalBox(Color fg, Color bg) { + super(fg, bg); + } + + public HorizontalBox cloneBox() { + HorizontalBox b = new HorizontalBox(foreground, background); + b.shift = shift; + + return b; + } + + public void draw(Graphics2D g2, float x, float y) { + startDraw(g2, x, y); + float xPos = x; + for (Box box: children) { + /*int i = children.indexOf(box); + if (breakPositions != null && breakPositions.indexOf(i) != -1) { + box.markForDEBUG = java.awt.Color.BLUE; + }*/ + + box.draw(g2, xPos, y + box.shift); + xPos += box.getWidth(); + } + endDraw(g2); + } + + public final void add(Box b) { + recalculate(b); + super.add(b); + } + + public final void add(int pos, Box b) { + recalculate(b); + super.add(pos, b); + } + + private void recalculate(Box b) { + // Commented for ticket 764 + // \left(\!\!\!\begin{array}{c}n\\\\r\end{array}\!\!\!\right)+123 + //curPos += b.getWidth(); + //width = Math.max(width, curPos); + width += b.getWidth(); + height = Math.max((children.size() == 0 ? Float.NEGATIVE_INFINITY : height), b.height - b.shift); + depth = Math.max((children.size() == 0 ? Float.NEGATIVE_INFINITY : depth), b.depth + b.shift); + } + + public int getLastFontId() { + // iterate from the last child box to the first untill a font id is found + // that's not equal to NO_FONT + int fontId = TeXFont.NO_FONT; + for (ListIterator it = children.listIterator(children.size()); fontId == TeXFont.NO_FONT && it.hasPrevious();) + fontId = ((Box) it.previous()).getLastFontId(); + + return fontId; + } + + public void addBreakPosition(int pos) { + if (breakPositions == null) { + breakPositions = new ArrayList(); + } + breakPositions.add(pos); + } + + protected HorizontalBox[] split(int position) { + return split(position, 1); + } + + protected HorizontalBox[] splitRemove(int position) { + return split(position, 2); + } + + private HorizontalBox[] split(int position, int shift) { + HorizontalBox hb1 = cloneBox(); + HorizontalBox hb2 = cloneBox(); + for (int i = 0; i <= position; i++) { + hb1.add(children.get(i)); + } + + for (int i = position + shift; i < children.size(); i++) { + hb2.add(children.get(i)); + } + + if (breakPositions != null) { + for (int i = 0; i < breakPositions.size(); i++) { + if (breakPositions.get(i) > position + 1) { + hb2.addBreakPosition(breakPositions.get(i) - position - 1); + } + } + } + + return new HorizontalBox[]{hb1, hb2}; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/HorizontalRule.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/HorizontalRule.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/HorizontalRule.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,101 @@ +/* HorizontalRule.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; +import java.awt.Color; + +/** + * A box representing a horizontal line. + */ +public class HorizontalRule extends Box { + + private Color color = null; + private float speShift = 0;; + + public HorizontalRule(float thickness, float width, float s) { + height = thickness; + this.width = width; + shift = s; + } + + public HorizontalRule(float thickness, float width, float s, boolean trueShift) { + height = thickness; + this.width = width; + if (trueShift) { + shift = s; + } else { + shift = 0; + speShift = s; + } + } + + public HorizontalRule(float thickness, float width, float s, Color c) { + height = thickness; + this.width = width; + color = c; + shift = s; + } + + public void draw(Graphics2D g2, float x, float y) { + Color old = g2.getColor(); + if (color != null) + g2.setColor(color); + + if (speShift == 0) { + g2.fill(new Rectangle2D.Float(x, y - height, width, height)); + } else { + g2.fill(new Rectangle2D.Float(x, y - height + speShift, width, height)); + } + g2.setColor(old); + } + + public int getLastFontId() { + return TeXFont.NO_FONT; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/IJAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/IJAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/IJAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,67 @@ +/* IJAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom with representing an IJ. + */ +public class IJAtom extends Atom { + + private boolean upper; + + public IJAtom(boolean upper) { + this.upper = upper; + } + + public Box createBox(TeXEnvironment env) { + CharBox I = new CharBox(env.getTeXFont().getChar(upper ? 'I' : 'i', "mathnormal", env.getStyle())); + CharBox J = new CharBox(env.getTeXFont().getChar(upper ? 'J' : 'j', "mathnormal", env.getStyle())); + HorizontalBox hb = new HorizontalBox(I); + hb.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.065f, 0, 0).createBox(env)); + hb.add(J); + return hb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/IddotsAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/IddotsAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/IddotsAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,76 @@ +/* IddotsAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing iddots. + */ +public class IddotsAtom extends Atom { + + public IddotsAtom() { } + + public Box createBox(TeXEnvironment env) { + Box ldots = TeXFormula.get("ldots").root.createBox(env); + float w = ldots.getWidth(); + Box dot = SymbolAtom.get("ldotp").createBox(env); + HorizontalBox hb1 = new HorizontalBox(dot, w, TeXConstants.ALIGN_RIGHT); + HorizontalBox hb2 = new HorizontalBox(dot, w, TeXConstants.ALIGN_CENTER); + HorizontalBox hb3 = new HorizontalBox(dot, w, TeXConstants.ALIGN_LEFT); + Box pt4 = new SpaceAtom(TeXConstants.UNIT_MU, 0, 4, 0).createBox(env); + VerticalBox vb = new VerticalBox(); + vb.add(hb1); + vb.add(pt4); + vb.add(hb2); + vb.add(pt4); + vb.add(hb3); + + float h = vb.getHeight() + vb.getDepth(); + vb.setHeight(h); + vb.setDepth(0); + + return vb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidAtomTypeException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidAtomTypeException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidAtomTypeException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,59 @@ +/* InvalidAtomTypeException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals that an unknown atom type constant was used. + * + * @author Kurt Vermeulen + */ +public class InvalidAtomTypeException extends JMathTeXException { + + protected InvalidAtomTypeException(String msg) { + super(msg); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidDelimiterException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidDelimiterException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidDelimiterException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,70 @@ +/* InvalidDelimiterException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals that a symbol, that was not defined as a delimiter, was used + * as a delimiter. + * + * @author Kurt Vermeulen + */ +public class InvalidDelimiterException extends JMathTeXException { + + protected InvalidDelimiterException(String symbolName) { + super("The symbol with the name '" + symbolName + + "' is not defined as a delimiter (" + + TeXSymbolParser.DELIMITER_ATTR + "='true') in '" + + TeXSymbolParser.RESOURCE_NAME + "'!"); + } + + protected InvalidDelimiterException(char ch, String symbolName) { + super("The character '" + ch + "' is mapped to a symbol with the name '" + + symbolName + "', but that symbol is not defined as a delimiter (" + + TeXSymbolParser.DELIMITER_ATTR + "='true') in '" + + TeXSymbolParser.RESOURCE_NAME + "'!"); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidDelimiterTypeException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidDelimiterTypeException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidDelimiterTypeException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,61 @@ +/* InvalidDelimiterTypeException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals that an unknown delimiter type constant was used. + * + * @author Kurt Vermeulen + */ +public class InvalidDelimiterTypeException extends JMathTeXException { + + protected InvalidDelimiterTypeException() { + super( + "The delimiter type was not valid! " + + "Use one of the delimiter type constants from the class 'TeXConstants'."); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidMatrixException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidMatrixException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidMatrixException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,59 @@ +/* InvalidMatrixException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals a problem of dimensions in the matrix. + * + * @author Calixte Denizet + */ +public class InvalidMatrixException extends JMathTeXException { + + protected InvalidMatrixException(String msg) { + super(msg); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidSymbolTypeException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidSymbolTypeException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidSymbolTypeException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,59 @@ +/* InvalidSymbolTypeException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals that an unknown symbol type constant or a symbol of the wrong type was used. + * + * @author Kurt Vermeulen + */ +public class InvalidSymbolTypeException extends JMathTeXException { + + protected InvalidSymbolTypeException(String msg) { + super(msg); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidTeXFormulaException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidTeXFormulaException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidTeXFormulaException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,59 @@ +/* InvalidTeXFormulaException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals that an invalid TeXFormula was used. + * + * @author Kurt Vermeulen + */ +public class InvalidTeXFormulaException extends JMathTeXException { + + protected InvalidTeXFormulaException(String msg) { + super(msg); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidUnitException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidUnitException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/InvalidUnitException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,60 @@ +/* InvalidUnitException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals that an unknown unit constant was used. + * + * @author Kurt Vermeulen + */ +public class InvalidUnitException extends JMathTeXException { + + protected InvalidUnitException() { + super("The delimiter type was not valid! " + + "Use one of the unit constants from the class 'TeXConstants'."); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ItAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ItAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ItAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,72 @@ +/* ItAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a italic atom. + */ +public class ItAtom extends Atom { + + private Atom base; + + public ItAtom(Atom base) { + this.base = base; + } + + public Box createBox(TeXEnvironment env) { + Box box; + if (base != null) { + env = env.copy(env.getTeXFont().copy()); + env.getTeXFont().setIt(true); + box = base.createBox(env); + } else { + box = new StrutBox(0, 0, 0, 0); + } + + return box; + } + +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/JMathTeXException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/JMathTeXException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/JMathTeXException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,63 @@ +/* JMathTeXException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Superclass of all the possible (public) exceptions that can be thrown in this package. + * + * @author Kurt Vermeulen + */ +public class JMathTeXException extends RuntimeException { + + protected JMathTeXException(String msg) { + super(msg); + } + + protected JMathTeXException(String msg, Throwable cause) { + super(msg, cause); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/JavaFontRenderingAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/JavaFontRenderingAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/JavaFontRenderingAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,94 @@ +/* ScaleAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Font; + +/** + * The string rendering is made in using Java Graphics2D.drawString. + */ +public class JavaFontRenderingAtom extends Atom { + + private String str; + private int type; + private TeXFormula.FontInfos fontInfos; + + public JavaFontRenderingAtom(String str, int type) { + this.str = str; + this.type = type; + } + + public JavaFontRenderingAtom(String str, TeXFormula.FontInfos fontInfos) { + this(str, 0); + this.fontInfos = fontInfos; + } + + public Box createBox(TeXEnvironment env) { + if (fontInfos == null) { + return new JavaFontRenderingBox(str, type, DefaultTeXFont.getSizeFactor(env.getStyle())); + } else { + DefaultTeXFont dtf = (DefaultTeXFont) env.getTeXFont(); + int type = dtf.isIt ? Font.ITALIC : Font.PLAIN; + type = type | (dtf.isBold ? Font.BOLD : 0); + boolean kerning = dtf.isRoman; + Font font; + if (dtf.isSs) { + if (fontInfos.sansserif == null) { + font = new Font(fontInfos.serif, Font.PLAIN, 10); + } else { + font = new Font(fontInfos.sansserif, Font.PLAIN, 10); + } + } else { + if (fontInfos.serif == null) { + font = new Font(fontInfos.sansserif, Font.PLAIN, 10); + } else { + font = new Font(fontInfos.serif, Font.PLAIN, 10); + } + } + return new JavaFontRenderingBox(str, type, DefaultTeXFont.getSizeFactor(env.getStyle()), font, kerning); + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/JavaFontRenderingBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/JavaFontRenderingBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/JavaFontRenderingBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,122 @@ +/* ScaleBox.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.font.TextAttribute; +import java.awt.font.TextLayout; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.lang.reflect.Field; +import java.util.Hashtable; +import java.util.Map; + +/** + * A box representing a scaled box. + */ +public class JavaFontRenderingBox extends Box { + + private static final Graphics2D TEMPGRAPHIC = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).createGraphics(); + + private static Font font = new Font("Serif", Font.PLAIN, 10); + + private String str; + private TextLayout text; + private float size; + private static TextAttribute KERNING; + private static Integer KERNING_ON; + private static TextAttribute LIGATURES; + private static Integer LIGATURES_ON; + + static { + try { // to avoid problems with Java 1.5 + KERNING = (TextAttribute) (TextAttribute.class.getField("KERNING").get(TextAttribute.class)); + KERNING_ON = (Integer) (TextAttribute.class.getField("KERNING_ON").get(TextAttribute.class)); + LIGATURES = (TextAttribute) (TextAttribute.class.getField("LIGATURES").get(TextAttribute.class)); + LIGATURES_ON = (Integer) (TextAttribute.class.getField("LIGATURES_ON").get(TextAttribute.class)); + } catch (Exception e) { } + } + + public JavaFontRenderingBox(String str, int type, float size, Font f, boolean kerning) { + this.str = str; + this.size = size; + + if (kerning && KERNING != null) { + Map map = new Hashtable(); + map.put(KERNING, KERNING_ON); + map.put(LIGATURES, LIGATURES_ON); + f = f.deriveFont(map); + } + + this.text = new TextLayout(str, f.deriveFont(type), TEMPGRAPHIC.getFontRenderContext()); + Rectangle2D rect = text.getBounds(); + this.height = (float) (-rect.getY() * size / 10); + this.depth = (float) (rect.getHeight() * size / 10) - this.height; + this.width = (float) ((rect.getWidth() + rect.getX() + 0.4f) * size / 10); + } + + public JavaFontRenderingBox(String str, int type, float size) { + this(str, type, size, font, true); + } + + public static void setFont(String name) { + font = new Font(name, Font.PLAIN, 10); + } + + public void draw(Graphics2D g2, float x, float y) { + drawDebug(g2, x, y); + g2.translate(x, y); + g2.scale(0.1 * size, 0.1 * size); + text.draw(g2, 0, 0); + g2.scale(10 / size, 10 / size); + g2.translate(-x, -y); + } + + public int getLastFontId() { + return 0; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/LCaronAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/LCaronAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/LCaronAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,70 @@ +/* LCaronAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom with representing an L with a caron. + */ +public class LCaronAtom extends Atom { + + private boolean upper; + + public LCaronAtom(boolean upper) { + this.upper = upper; + } + + public Box createBox(TeXEnvironment env) { + CharBox A = new CharBox(env.getTeXFont().getChar("textapos", env.getStyle())); + CharBox L = new CharBox(env.getTeXFont().getChar(upper ? 'L' : 'l', "mathnormal", env.getStyle())); + HorizontalBox hb = new HorizontalBox(L); + if (upper) + hb.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.3f, 0, 0).createBox(env)); + else + hb.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.13f, 0, 0).createBox(env)); + hb.add(A); + return hb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/LaTeXAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/LaTeXAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/LaTeXAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,88 @@ +/* LaTeXAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing whitespace. The dimension values can be set using different + * unit types. + */ +public class LaTeXAtom extends Atom { + + public LaTeXAtom() { + } + + public Box createBox(TeXEnvironment env) { + env = env.copy(env.getTeXFont().copy()); + env.getTeXFont().setRoman(true); + float sc = env.getTeXFont().getScaleFactor(); + + TeXFormula.FontInfos fontInfos = TeXFormula.externalFontMap.get(Character.UnicodeBlock.BASIC_LATIN); + if (fontInfos != null) { + TeXFormula.externalFontMap.put(Character.UnicodeBlock.BASIC_LATIN, null); + } + RowAtom rat = (RowAtom)((RomanAtom)new TeXFormula("\\mathrm{XETL}").root).base; + if (fontInfos != null) { + TeXFormula.externalFontMap.put(Character.UnicodeBlock.BASIC_LATIN, fontInfos); + } + + HorizontalBox hb = new HorizontalBox(rat.getLastAtom().createBox(env)); + hb.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.35f * sc, 0, 0).createBox(env)); + float f = new SpaceAtom(TeXConstants.UNIT_EX, 0.45f * sc, 0, 0).createBox(env).getWidth(); + float f1 = new SpaceAtom(TeXConstants.UNIT_EX, 0.5f * sc, 0, 0).createBox(env).getWidth(); + CharBox A = new CharBox(env.getTeXFont().getChar('A', "mathnormal", env.supStyle().getStyle())); + A.setShift(-f); + hb.add(A); + hb.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.15f * sc, 0, 0).createBox(env)); + hb.add(rat.getLastAtom().createBox(env)); + hb.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.15f * sc, 0, 0).createBox(env)); + Box E = rat.getLastAtom().createBox(env); + E.setShift(f1); + hb.add(E); + hb.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.15f * sc, 0, 0).createBox(env)); + hb.add(rat.getLastAtom().createBox(env)); + return hb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/LapedAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/LapedAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/LapedAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,79 @@ +/* LapedAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a laped atom (i.e. with no width). + */ +public class LapedAtom extends Atom { + + private Atom at; + private char type; + + public LapedAtom(Atom at, char type) { + this.at = at; + this.type = type; + } + + public Box createBox(TeXEnvironment env) { + Box b = at.createBox(env); + VerticalBox vb = new VerticalBox(); + vb.add(b); + vb.setWidth(0); + switch (type) { + case 'l' : + b.setShift(- b.getWidth()); + break; + case 'r' : + b.setShift(0); + break; + default : + b.setShift(- b.getWidth() / 2); + } + + return vb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/LongdivAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/LongdivAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/LongdivAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,117 @@ +/* GraphicsAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2017 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.util.ArrayList; + +/** + * An atom representing a long division. + */ +public class LongdivAtom extends VRowAtom { + + public LongdivAtom(long divisor, long dividend) { + setHalign(TeXConstants.ALIGN_RIGHT); + setVtop(true); + String[] res = makeResults(divisor, dividend); + Atom rule = new RuleAtom(TeXConstants.UNIT_EX, 0f, + TeXConstants.UNIT_EX, 2.6f, + TeXConstants.UNIT_EX, 0.5f); + for (int i = 0; i < res.length; ++i) { + Atom num = new TeXFormula(res[i]).root; + if (i % 2 == 0) { + RowAtom ra = new RowAtom(num); + ra.add(rule); + if (i == 0) { + append(ra); + } else { + append(new UnderlinedAtom(ra)); + } + } else if (i == 1) { + String div = Long.toString(divisor); + SymbolAtom rparen = SymbolAtom.get(TeXFormula.symbolMappings[')']); + Atom big = new BigDelimiterAtom(rparen, 1); + Atom ph = new PhantomAtom(big, false, true, true); + RowAtom ra = new RowAtom(ph); + Atom raised = new RaiseAtom(big, + TeXConstants.UNIT_X8, 3.5f, + TeXConstants.UNIT_X8, 0f, + TeXConstants.UNIT_X8, 0f); + ra.add(new SmashedAtom(raised)); + ra.add(num); + Atom a = new OverlinedAtom(ra); + RowAtom ra1 = new RowAtom(new TeXFormula(div).root); + ra1.add(new SpaceAtom(TeXConstants.THINMUSKIP)); + ra1.add(a); + append(ra1); + } else { + RowAtom ra = new RowAtom(num); + ra.add(rule); + append(ra); + } + } + } + + private String[] makeResults(long divisor, long dividend) { + ArrayList vec = new ArrayList<>(); + long q = dividend / divisor; + vec.add(Long.toString(q)); + vec.add(Long.toString(dividend)); + + while (q != 0) { + final double p = (double) Math.floor(Math.log10((double) q)); + final double p10 = Math.pow(10., p); + final long d = (long) (Math.floor(((double) q) / p10) * p10); + final long dd = d * divisor; + vec.add(Long.toString(dd)); + dividend -= dd; + vec.add(Long.toString(dividend)); + q -= d; + } + + String[] res = new String[vec.size()]; + return vec.toArray(res); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MacroInfo.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MacroInfo.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MacroInfo.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,140 @@ +/* MacroInfo.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; + +public class MacroInfo { + + public static HashMap Commands = new HashMap(300); + public static HashMap Packages = new HashMap(); + + public Object pack; + public Method macro; + public int nbArgs; + public boolean hasOptions = false; + public int posOpts; + + public MacroInfo(Object pack, Method macro, int nbArgs) { + this.pack = pack; + this.macro = macro; + this.nbArgs = nbArgs; + } + + public MacroInfo(Object pack, Method macro, int nbArgs, int posOpts) { + this(pack, macro, nbArgs); + this.hasOptions = true; + this.posOpts = posOpts; + } + + public MacroInfo(int nbArgs, int posOpts) { + this(null, (Method) null, nbArgs); + this.hasOptions = true; + this.posOpts = posOpts; + } + + public MacroInfo(int nbArgs) { + this(null, (Method) null, nbArgs); + } + + public MacroInfo(String className, String methodName, float nbArgs) { + int nba = (int) nbArgs; + Class[] args = new Class[]{TeXParser.class, String[].class}; + + try { + Object pack = Packages.get(className); + if (pack == null) { + Class cl = Class.forName(className); + pack = cl.getConstructor(new Class[0]).newInstance(new Object[0]); + Packages.put(className, pack); + } + this.pack = pack; + this.macro = pack.getClass().getDeclaredMethod(methodName, args); + this.nbArgs = nba; + } catch (Exception e) { + System.err.println("Cannot load package " + className + ":"); + System.err.println(e.toString()); + } + } + + public MacroInfo(String className, String methodName, float nbArgs, float posOpts) { + int nba = (int) nbArgs; + Class[] args = new Class[]{TeXParser.class, String[].class}; + + try { + Object pack = Packages.get(className); + if (pack == null) { + Class cl = Class.forName(className); + pack = cl.getConstructor(new Class[0]).newInstance(new Object[0]); + Packages.put(className, pack); + } + this.pack = pack; + this.macro = pack.getClass().getDeclaredMethod(methodName, args); + this.nbArgs = nba; + this.hasOptions = true; + this.posOpts = (int) posOpts; + } catch (Exception e) { + System.err.println("Cannot load package " + className + ":"); + System.err.println(e.toString()); + } + } + + public Object invoke(final TeXParser tp, final String[] args) throws ParseException { + Object[] argsMethod = {(Object) tp, (Object) args}; + try { + return macro.invoke(pack, argsMethod); + } catch (IllegalAccessException e) { + throw new ParseException("Problem with command " + args[0] + " at position " + tp.getLine() + ":" + tp.getCol() + "\n", e); + } catch (IllegalArgumentException e) { + throw new ParseException("Problem with command " + args[0] + " at position " + tp.getLine() + ":" + tp.getCol() + "\n", e); + } catch (InvocationTargetException e) { + Throwable th = e.getCause(); + throw new ParseException("Problem with command " + args[0] + " at position " + tp.getLine() + ":" + tp.getCol() + "\n" + th.getMessage()); + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MathAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MathAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MathAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,70 @@ +/* MathAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2011 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a math atom. + */ +public class MathAtom extends Atom { + + private int style = TeXConstants.STYLE_DISPLAY; + protected Atom base; + + public MathAtom(Atom base, int style) { + this.base = base; + this.style = style; + } + + public Box createBox(TeXEnvironment env) { + env = env.copy(env.getTeXFont().copy()); + env.getTeXFont().setRoman(false); + int sstyle = env.getStyle(); + env.setStyle(style); + Box box = base.createBox(env); + env.setStyle(sstyle); + return box; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MatrixAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MatrixAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MatrixAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,562 @@ +/* MatrixAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.util.BitSet; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; +import java.util.List; + +/** + * A box representing a matrix. + */ +public class MatrixAtom extends Atom { + + public static SpaceAtom hsep = new SpaceAtom(TeXConstants.UNIT_EM, 1f, 0.0f, 0.0f); + public static SpaceAtom semihsep = new SpaceAtom(TeXConstants.UNIT_EM, 0.5f, 0.0f, 0.0f); + public static SpaceAtom vsep_in = new SpaceAtom(TeXConstants.UNIT_EX, 0.0f, 1f, 0.0f); + public static SpaceAtom vsep_ext_top = new SpaceAtom(TeXConstants.UNIT_EX, 0.0f, 0.4f, 0.0f); + public static SpaceAtom vsep_ext_bot = new SpaceAtom(TeXConstants.UNIT_EX, 0.0f, 0.4f, 0.0f); + + public static final int ARRAY = 0; + public static final int MATRIX = 1; + public static final int ALIGN = 2; + public static final int ALIGNAT = 3; + public static final int FLALIGN = 4; + public static final int SMALLMATRIX = 5; + public static final int ALIGNED = 6; + public static final int ALIGNEDAT = 7; + + private static final Box nullBox = new StrutBox(0, 0, 0, 0); + + private ArrayOfAtoms matrix; + private int[] position; + private Map vlines = new HashMap(); + private boolean isAlign; + private boolean isAlignat; + private boolean isFl; + private int type; + private boolean isPartial; + private boolean spaceAround; + + private static SpaceAtom align = new SpaceAtom(TeXConstants.MEDMUSKIP); + + /** + * Creates an empty matrix + * + */ + public MatrixAtom(boolean isPartial, ArrayOfAtoms array, String options, boolean spaceAround) { + this.isPartial = isPartial; + this.matrix = array; + this.type = ARRAY; + this.spaceAround = spaceAround; + parsePositions(new StringBuffer(options)); + } + + /** + * Creates an empty matrix + * + */ + public MatrixAtom(boolean isPartial, ArrayOfAtoms array, String options) { + this(isPartial, array, options, false); + } + + /** + * Creates an empty matrix + * + */ + public MatrixAtom(ArrayOfAtoms array, String options) { + this(false, array, options); + } + + public MatrixAtom(boolean isPartial, ArrayOfAtoms array, int type) { + this(isPartial, array, type, false); + } + + public MatrixAtom(boolean isPartial, ArrayOfAtoms array, int type, boolean spaceAround) { + this.isPartial = isPartial; + this.matrix = array; + this.type = type; + this.spaceAround = spaceAround; + + if (type != MATRIX && type != SMALLMATRIX) { + position = new int[matrix.col]; + for (int i = 0; i < matrix.col; i += 2) { + position[i] = TeXConstants.ALIGN_RIGHT; + if (i + 1 < matrix.col) { + position[i + 1] = TeXConstants.ALIGN_LEFT; + } + } + } else { + position = new int[matrix.col]; + for (int i = 0; i < matrix.col; i++) { + position[i] = TeXConstants.ALIGN_CENTER; + } + } + } + + public MatrixAtom(boolean isPartial, ArrayOfAtoms array, int type, int alignment) { + this(isPartial, array, type, alignment, true); + } + + public MatrixAtom(boolean isPartial, ArrayOfAtoms array, int type, int alignment, boolean spaceAround) { + this.isPartial = isPartial; + this.matrix = array; + this.type = type; + this.spaceAround = spaceAround; + + position = new int[matrix.col]; + for (int i = 0; i < matrix.col; i++) { + position[i] = alignment; + } + } + + public MatrixAtom(ArrayOfAtoms array, int type) { + this(false, array, type); + } + + private void parsePositions(StringBuffer opt) { + int len = opt.length(); + int pos = 0; + char ch; + TeXFormula tf; + TeXParser tp; + List lposition = new ArrayList(); + while (pos < len) { + ch = opt.charAt(pos); + switch (ch) { + case 'l' : + lposition.add(TeXConstants.ALIGN_LEFT); + break; + case 'r' : + lposition.add(TeXConstants.ALIGN_RIGHT); + break; + case 'c' : + lposition.add(TeXConstants.ALIGN_CENTER); + break; + case '|' : + int nb = 1; + while (++pos < len) { + ch = opt.charAt(pos); + if (ch != '|') { + pos--; + break; + } else { + nb++; + } + } + vlines.put(lposition.size(), new VlineAtom(nb)); + break; + case '@' : + pos++; + tf = new TeXFormula(); + tp = new TeXParser(isPartial, opt.substring(pos), tf, false); + Atom at = tp.getArgument(); + matrix.col++; + for (int j = 0; j < matrix.row; j++) { + matrix.array.get(j).add(lposition.size(), at); + } + + lposition.add(TeXConstants.ALIGN_NONE); + pos += tp.getPos(); + pos--; + break; + case '*' : + pos++; + tf = new TeXFormula(); + tp = new TeXParser(isPartial, opt.substring(pos), tf, false); + String[] args = tp.getOptsArgs(2, 0); + pos += tp.getPos(); + int nrep = Integer.parseInt(args[1]); + String str = ""; + for (int j = 0; j < nrep; j++) { + str += args[2]; + } + opt.insert(pos, str); + len = opt.length(); + pos--; + break; + case ' ': + case '\t': + break; + default : + lposition.add(TeXConstants.ALIGN_CENTER); + } + pos++; + } + + for (int j = lposition.size(); j < matrix.col; j++) { + lposition.add(TeXConstants.ALIGN_CENTER); + } + + if (lposition.size() != 0) { + Integer[] tab = lposition.toArray(new Integer[0]); + position = new int[tab.length]; + for (int i = 0; i < tab.length; i++) { + position[i] = tab[i]; + } + } else { + position = new int[]{TeXConstants.ALIGN_CENTER}; + } + } + + public Box[] getColumnSep(TeXEnvironment env, float width) { + int row = matrix.row; + int col = matrix.col; + Box[] arr = new Box[col + 1]; + Box Align, AlignSep, Hsep; + float h, w = env.getTextwidth(); + int i; + + if (type == ALIGNED || type == ALIGNEDAT) { + w = Float.POSITIVE_INFINITY; + } + + switch (type) { + case ARRAY : + //Array : hsep_col/2 elem hsep_col elem hsep_col ... hsep_col elem hsep_col/2 + i = 1; + if (position[0] == TeXConstants.ALIGN_NONE) { + arr[1] = new StrutBox(0.0f, 0.0f, 0.0f, 0.0f); + i = 2; + } + if (spaceAround) { + arr[0] = semihsep.createBox(env); + } else { + arr[0] = new StrutBox(0.0f, 0.0f, 0.0f, 0.0f); + } + arr[col] = arr[0]; + Hsep = hsep.createBox(env); + for (; i < col; i++) { + if (position[i] == TeXConstants.ALIGN_NONE) { + arr[i] = new StrutBox(0.0f, 0.0f, 0.0f, 0.0f); + arr[i + 1] = arr[i]; + i++; + } else { + arr[i] = Hsep; + } + } + + return arr; + case MATRIX : + case SMALLMATRIX : + //Simple matrix : (hsep_col/2 or 0) elem hsep_col elem hsep_col ... hsep_col elem (hsep_col/2 or 0) + arr[0] = nullBox; + arr[col] = arr[0]; + Hsep = hsep.createBox(env); + for (i = 1; i < col; i++) { + arr[i] = Hsep; + } + + return arr; + case ALIGNED : + case ALIGN : + //Align env. : hsep=(textwidth-matWidth)/(2n+1) and hsep eq_lft \medskip el_rgt hsep ... hsep elem hsep + Align = align.createBox(env); + if (w != Float.POSITIVE_INFINITY) { + h = Math.max((w - width - (col / 2) * Align.getWidth()) / (float) Math.floor((col + 3)/ 2), 0); + AlignSep = new StrutBox(h, 0.0f, 0.0f, 0.0f); + } else { + AlignSep = hsep.createBox(env); + } + + arr[col] = AlignSep; + for (i = 0; i < col; i++) { + if (i % 2 == 0) { + arr[i] = AlignSep; + } else { + arr[i] = Align; + } + } + + break; + case ALIGNEDAT : + case ALIGNAT : + //Alignat env. : hsep=(textwidth-matWidth)/2 and hsep elem ... elem hsep + if (w != Float.POSITIVE_INFINITY) { + h = Math.max((w - width) / 2, 0); + } else { + h = 0; + } + + Align = align.createBox(env); + Box empty = nullBox; + arr[0] = new StrutBox(h, 0.0f, 0.0f, 0.0f); + arr[col] = arr[0]; + for (i = 1; i < col; i++) { + if (i % 2 == 0) { + arr[i] = empty; + } else { + arr[i] = Align; + } + } + + break; + case FLALIGN : + //flalign env. : hsep=(textwidth-matWidth)/(2n+1) and hsep eq_lft \medskip el_rgt hsep ... hsep elem hsep + Align = align.createBox(env); + if (w != Float.POSITIVE_INFINITY) { + h = Math.max((w - width - (col / 2) * Align.getWidth()) / (float) Math.floor((col - 1)/ 2), 0); + AlignSep = new StrutBox(h, 0.0f, 0.0f, 0.0f); + } else { + AlignSep = hsep.createBox(env); + } + + arr[0] = nullBox; + arr[col] = arr[0]; + for (i = 1; i < col; i++) { + if (i % 2 == 0) { + arr[i] = AlignSep; + } else { + arr[i] = Align; + } + } + + break; + } + + if (w == Float.POSITIVE_INFINITY) { + arr[0] = nullBox; + arr[col] = arr[0]; + } + + return arr; + + } + + public Box createBox(TeXEnvironment env) { + int row = matrix.row; + int col = matrix.col; + Box[][] boxarr = new Box[row][col]; + float[] lineDepth = new float[row]; + float[] lineHeight = new float[row]; + float[] rowWidth = new float[col]; + float matW = 0; + float drt = env.getTeXFont().getDefaultRuleThickness(env.getStyle()); + + if (type == SMALLMATRIX) { + env = env.copy(); + env.setStyle(TeXConstants.STYLE_SCRIPT); + } + + List listMulti = new ArrayList(); + + for (int i = 0; i < row; i++) { + lineDepth[i] = 0; + lineHeight[i] = 0; + for (int j = 0; j < col; j++) { + Atom at = null; + try { + at = matrix.array.get(i).get(j); + } catch (Exception e) { + //The previous atom was an intertext atom + //position[j - 1] = -1; + boxarr[i][j - 1].type = TeXConstants.TYPE_INTERTEXT; + j = col - 1; + } + + boxarr[i][j] = (at == null) ? nullBox : at.createBox(env); + + lineDepth[i] = Math.max(boxarr[i][j].getDepth(), lineDepth[i]); + lineHeight[i] = Math.max(boxarr[i][j].getHeight(), lineHeight[i]); + + if (boxarr[i][j].type != TeXConstants.TYPE_MULTICOLUMN) { + rowWidth[j] = Math.max(boxarr[i][j].getWidth(), rowWidth[j]); + } else { + ((MulticolumnAtom) at).setRowColumn(i, j); + listMulti.add((MulticolumnAtom) at); + } + } + } + + for (int i = 0; i < listMulti.size(); i++) { + MulticolumnAtom multi = listMulti.get(i); + int c = multi.getCol(); + int r = multi.getRow(); + int n = multi.getSkipped(); + float w = 0; + for (int j = c; j < c + n; j++) { + w += rowWidth[j]; + } + if (boxarr[r][c].getWidth() > w) { + float extraW = (boxarr[r][c].getWidth() - w) / n; + for (int j = c; j < c + n; j++) { + rowWidth[j] += extraW; + } + } + } + + for (int j = 0; j < col; j++) { + matW += rowWidth[j]; + } + Box[] Hsep = getColumnSep(env, matW); + + for (int j = 0; j < col + 1; j++) { + matW += Hsep[j].getWidth(); + if (vlines.get(j) != null) { + matW += vlines.get(j).getWidth(env); + } + } + + VerticalBox vb = new VerticalBox(); + Box Vsep = vsep_in.createBox(env); + vb.add(vsep_ext_top.createBox(env)); + float vsepH = Vsep.getHeight(); + float totalHeight = 0; + + for (int i = 0; i < row; i++) { + HorizontalBox hb = new HorizontalBox(); + for (int j = 0; j < col; j++) { + switch (boxarr[i][j].type) { + case -1 : + case TeXConstants.TYPE_MULTICOLUMN : + if (j == 0) { + if (vlines.get(0) != null) { + VlineAtom vat = vlines.get(0); + vat.setHeight(lineHeight[i] + lineDepth[i] + Vsep.getHeight()); + vat.setShift(lineDepth[i] + Vsep.getHeight() / 2); + Box vatBox = vat.createBox(env); + hb.add(new HorizontalBox(vatBox, Hsep[0].getWidth() + vatBox.getWidth(), TeXConstants.ALIGN_LEFT)); + } else { + hb.add(Hsep[0]); + } + } + + boolean lastVline = true; + + if (boxarr[i][j].type == -1) { + hb.add(new HorizontalBox(boxarr[i][j], rowWidth[j], position[j])); + } else { + Box b = generateMulticolumn(env, Hsep, rowWidth, i, j); + MulticolumnAtom matom = (MulticolumnAtom) matrix.array.get(i).get(j); + j += matom.getSkipped() - 1; + hb.add(b); + lastVline = matom.hasRightVline(); + } + + if (lastVline && vlines.get(j + 1) != null) { + VlineAtom vat = vlines.get(j + 1); + vat.setHeight(lineHeight[i] + lineDepth[i] + Vsep.getHeight()); + vat.setShift(lineDepth[i] + Vsep.getHeight() / 2); + Box vatBox = vat.createBox(env); + if (j < col - 1) { + hb.add(new HorizontalBox(vatBox, Hsep[j + 1].getWidth() + vatBox.getWidth(), TeXConstants.ALIGN_CENTER)); + } else { + hb.add(new HorizontalBox(vatBox, Hsep[j + 1].getWidth() + vatBox.getWidth(), TeXConstants.ALIGN_RIGHT)); + } + } else { + hb.add(Hsep[j + 1]); + } + break; + case TeXConstants.TYPE_INTERTEXT : + float f = env.getTextwidth(); + f = f == Float.POSITIVE_INFINITY ? rowWidth[j] : f; + hb = new HorizontalBox(boxarr[i][j], f, TeXConstants.ALIGN_LEFT); + j = col - 1; + break; + case TeXConstants.TYPE_HLINE : + HlineAtom at = (HlineAtom) matrix.array.get(i).get(j); + at.setWidth(matW); + if (i >= 1 && matrix.array.get(i - 1).get(j) instanceof HlineAtom) { + hb.add(new StrutBox(0, 2 * drt, 0, 0)); + at.setShift(-Vsep.getHeight() / 2 + drt); + } else { + at.setShift(-Vsep.getHeight() / 2); + } + + hb.add(at.createBox(env)); + j = col; + break; + } + } + + if (boxarr[i][0].type != TeXConstants.TYPE_HLINE) { + hb.setHeight(lineHeight[i]); + hb.setDepth(lineDepth[i]); + vb.add(hb); + + if (i < row - 1) + vb.add(Vsep); + } else { + vb.add(hb); + } + } + + vb.add(vsep_ext_bot.createBox(env)); + totalHeight = vb.getHeight() + vb.getDepth(); + + float axis = env.getTeXFont().getAxisHeight(env.getStyle()); + vb.setHeight(totalHeight / 2 + axis); + vb.setDepth(totalHeight / 2 - axis); + + return vb; + } + + private Box generateMulticolumn(TeXEnvironment env, Box[] Hsep, float[] rowWidth, int i, int j) { + float w = 0; + MulticolumnAtom mca = (MulticolumnAtom) matrix.array.get(i).get(j); + int k, n = mca.getSkipped(); + for (k = j; k < j + n - 1; k++) { + w += rowWidth[k] + Hsep[k + 1].getWidth(); + if (vlines.get(k + 1) != null) { + w += vlines.get(k + 1).getWidth(env); + } + } + w += rowWidth[k]; + + Box b = mca.createBox(env); + float bw = b.getWidth(); + if (bw > w) { + // It isn't a good idea but for the moment I have no other solution ! + w = 0; + } + + mca.setWidth(w); + b = mca.createBox(env); + return b; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Metrics.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Metrics.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Metrics.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,87 @@ +/* Metrics.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Contains the metrics for 1 character: width, height, depth and italic correction. + */ +public class Metrics { + + private final float w; + private final float h; + private final float d; + private final float i; + private final float s; + + public Metrics(float w, float h, float d, float i, float factor, float size) { + this.w = w * factor; + this.h = h * factor; + this.d = d * factor; + this.i = i * factor; + this.s = size; + } + + public float getWidth() { + return w; + } + + public float getHeight() { + return h; + } + + public float getDepth() { + return d; + } + + public float getItalic() { + return i; + } + + public float getSize() { + return s; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MiddleAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MiddleAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MiddleAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,63 @@ +/* MiddleAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a middle atom which must be rounded by a left and right delimiter. + */ +public class MiddleAtom extends Atom { + + public Atom base; + public Box box = new StrutBox(0, 0, 0, 0); + + public MiddleAtom(Atom at) { + base = at; + } + + public Box createBox(TeXEnvironment env) { + return box; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MonoScaleAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MonoScaleAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MonoScaleAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,66 @@ +/* MonoScaleAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a mono scale Atom. + */ +public class MonoScaleAtom extends ScaleAtom { + + private float factor; + + public MonoScaleAtom(Atom base, float factor) { + super(base, (double) factor, (double) factor); + this.factor = factor; + } + + public Box createBox(TeXEnvironment env) { + env = env.copy(); + float f = env.getScaleFactor(); + env.setScaleFactor(factor); + return new ScaleBox(base.createBox(env), factor / f); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MulticolumnAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MulticolumnAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MulticolumnAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,148 @@ +/* MulticolumnAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom used in array mode to write on several columns. + */ +public class MulticolumnAtom extends Atom { + + protected int n; + protected int align; + protected float w = 0; + protected Atom cols; + protected int beforeVlines; + protected int afterVlines; + protected int row, col; + + public MulticolumnAtom(int n, String align, Atom cols) { + this.n = n >= 1 ? n : 1; + this.cols = cols; + this.align = parseAlign(align); + } + + public void setWidth(float w) { + this.w = w; + } + + public int getSkipped() { + return n; + } + + public boolean hasRightVline() { + return afterVlines != 0; + } + + public void setRowColumn(int i, int j) { + this.row = i; + this.col = j; + } + + public int getRow() { + return row; + } + + public int getCol() { + return col; + } + + private int parseAlign(String str) { + int pos = 0; + int len = str.length(); + int align = TeXConstants.ALIGN_CENTER; + boolean first = true; + while (pos < len) { + char c = str.charAt(pos); + switch (c) { + case 'l' : + align = TeXConstants.ALIGN_LEFT; + first = false; + break; + case 'r': + align = TeXConstants.ALIGN_RIGHT; + first = false; + break; + case 'c': + align = TeXConstants.ALIGN_CENTER; + first = false; + break; + case '|': + if (first) { + beforeVlines = 1; + } else { + afterVlines = 1; + } + while (++pos < len) { + c = str.charAt(pos); + if (c != '|') { + pos--; + break; + } else { + if (first) { + beforeVlines++; + } else { + afterVlines++; + } + } + } + } + pos++; + } + return align; + } + + public Box createBox(TeXEnvironment env) { + Box b; + if (w == 0) { + b = cols.createBox(env); + } else { + b = new HorizontalBox(cols.createBox(env), w, align); + } + + b.type = TeXConstants.TYPE_MULTICOLUMN; + return b; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MultlineAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MultlineAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/MultlineAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,112 @@ +/* MultlineAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a vertical row of other atoms. + */ +public class MultlineAtom extends Atom { + + public static SpaceAtom vsep_in = new SpaceAtom(TeXConstants.UNIT_EX, 0.0f, 1.0f, 0.0f); + public static final int MULTLINE = 0; + public static final int GATHER = 1; + public static final int GATHERED = 2; + + private ArrayOfAtoms column; + private int type; + private boolean isPartial; + + public MultlineAtom(boolean isPartial, ArrayOfAtoms column, int type) { + this.isPartial = isPartial; + this.column = column; + this.type = type; + } + + public MultlineAtom(ArrayOfAtoms column, int type) { + this(false, column, type); + } + + public Box createBox(TeXEnvironment env) { + float tw = env.getTextwidth(); + if (tw == Float.POSITIVE_INFINITY || type == GATHERED) { + return new MatrixAtom(isPartial, column, "").createBox(env); + } + + VerticalBox vb = new VerticalBox(); + Atom at = column.array.get(0).get(0); + int alignment = type == GATHER ? TeXConstants.ALIGN_CENTER : TeXConstants.ALIGN_LEFT; + if (at.alignment != -1) { + alignment = at.alignment; + } + vb.add(new HorizontalBox(at.createBox(env), tw, alignment)); + Box Vsep = vsep_in.createBox(env); + for (int i = 1; i < column.row - 1; i++) { + at = column.array.get(i).get(0); + alignment = TeXConstants.ALIGN_CENTER; + if (at.alignment != -1) { + alignment = at.alignment; + } + vb.add(Vsep); + vb.add(new HorizontalBox(at.createBox(env), tw, alignment)); + } + + if (column.row > 1) { + at = column.array.get(column.row - 1).get(0); + alignment = type == GATHER ? TeXConstants.ALIGN_CENTER : TeXConstants.ALIGN_RIGHT; + if (at.alignment != -1) { + alignment = at.alignment; + } + vb.add(Vsep); + vb.add(new HorizontalBox(at.createBox(env), tw, alignment)); + } + + float height = vb.getHeight() + vb.getDepth(); + vb.setHeight(height / 2); + vb.setDepth(height / 2); + + return vb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/NewCommandMacro.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/NewCommandMacro.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/NewCommandMacro.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,109 @@ +/* NewCommandMacro.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.util.HashMap; +import java.util.regex.Matcher; + +public class NewCommandMacro { + + protected static HashMap macrocode = new HashMap(); + protected static HashMap macroreplacement = new HashMap(); + + public NewCommandMacro() { + } + + public static void addNewCommand(String name, String code, int nbargs) throws ParseException { + //if (macrocode.get(name) != null) + //throw new ParseException("Command " + name + " already exists ! Use renewcommand instead ..."); + macrocode.put(name, code); + MacroInfo.Commands.put(name, new MacroInfo("org.scilab.forge.jlatexmath.NewCommandMacro", "executeMacro", nbargs)); + } + + public static void addNewCommand(String name, String code, int nbargs, String def) throws ParseException { + if (macrocode.get(name) != null) + throw new ParseException("Command " + name + " already exists ! Use renewcommand instead ..."); + macrocode.put(name, code); + macroreplacement.put(name, def); + MacroInfo.Commands.put(name, new MacroInfo("org.scilab.forge.jlatexmath.NewCommandMacro", "executeMacro", nbargs, 1)); + } + + public static boolean isMacro(String name) { + return macrocode.containsKey(name); + } + + public static void addReNewCommand(String name, String code, int nbargs) { + if (macrocode.get(name) == null) + throw new ParseException("Command " + name + " is not defined ! Use newcommand instead ..."); + macrocode.put(name, code); + MacroInfo.Commands.put(name, new MacroInfo("org.scilab.forge.jlatexmath.NewCommandMacro", "executeMacro", nbargs)); + } + + public String executeMacro(TeXParser tp, String[] args) { + String code = macrocode.get(args[0]); + String rep; + int nbargs = args.length - 11; + int dec = 0; + + + if (args[nbargs + 1] != null) { + dec = 1; + rep = Matcher.quoteReplacement(args[nbargs + 1]); + code = code.replaceAll("#1", rep); + } else if (macroreplacement.get(args[0]) != null) { + dec = 1; + rep = Matcher.quoteReplacement(macroreplacement.get(args[0])); + code = code.replaceAll("#1", rep); + } + + for (int i = 1; i <= nbargs; i++) { + rep = Matcher.quoteReplacement(args[i]); + code = code.replaceAll("#" + (i + dec), rep); + } + + return code; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/NewEnvironmentMacro.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/NewEnvironmentMacro.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/NewEnvironmentMacro.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,67 @@ +/* NewEnvironmentMacro.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.util.HashMap; +import java.util.regex.Matcher; + +public class NewEnvironmentMacro extends NewCommandMacro { + + public NewEnvironmentMacro() { + } + + public static void addNewEnvironment(String name, String begdef, String enddef, int nbArgs) throws ParseException { + //if (macrocode.get(name + "@env") != null) + //throw new ParseException("Environment " + name + " already exists ! Use renewenvironment instead ..."); + addNewCommand(name + "@env", begdef + " #" + (nbArgs + 1) + " " + enddef, nbArgs + 1); + } + + public static void addReNewEnvironment(String name, String begdef, String enddef, int nbArgs) throws ParseException { + if (macrocode.get(name + "@env") == null) + throw new ParseException("Environment " + name + "is not defined ! Use newenvironment instead ..."); + addReNewCommand(name + "@env", begdef + " #" + (nbArgs + 1) + " " + enddef, nbArgs + 1); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/NthRoot.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/NthRoot.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/NthRoot.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,128 @@ +/* NthRoot.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing an nth-root construction. + */ +public class NthRoot extends Atom { + + private static final String sqrtSymbol = "sqrt"; + + private static final float FACTOR = 0.55f; + + // base atom to be put under the root sign + private final Atom base; + + // root atom to be put in the upper left corner above the root sign + private final Atom root; + + public NthRoot(Atom base, Atom root) { + this.base = base == null ? new EmptyAtom() : base; + this.root = root == null ? new EmptyAtom() : root; + } + + public Box createBox(TeXEnvironment env) { + // first create a simple square root construction + + TeXFont tf = env.getTeXFont(); + int style = env.getStyle(); + // calculate minimum clearance clr + float clr, drt = tf.getDefaultRuleThickness(style); + if (style < TeXConstants.STYLE_TEXT) + clr = tf.getXHeight(style, tf.getChar(sqrtSymbol, style).getFontCode()); + else + clr = drt; + clr = drt + Math.abs(clr) / 4 ; + + // cramped style for the formula under the root sign + Box bs = base.createBox(env.crampStyle()); + HorizontalBox b = new HorizontalBox(bs); + b.add(new SpaceAtom(TeXConstants.UNIT_MU, 1, 0, 0).createBox(env.crampStyle())); + // create root sign + float totalH = b.getHeight() + b.getDepth(); + Box rootSign = DelimiterFactory.create(sqrtSymbol, env, totalH + clr + drt); + + // add half the excess to clr + float delta = rootSign.getDepth() - (totalH + clr); + clr += delta / 2; + + // create total box + rootSign.setShift(-(b.getHeight() + clr)); + OverBar ob = new OverBar(b, clr, rootSign.getHeight()); + ob.setShift(-(b.getHeight() + clr + drt)); + HorizontalBox squareRoot = new HorizontalBox(rootSign); + squareRoot.add(ob); + + if (root == null) + // simple square root + return squareRoot; + else { // nthRoot, not a simple square root + + // create box from root + Box r = root.createBox(env.rootStyle()); + + // shift root up + float bottomShift = FACTOR * (squareRoot.getHeight() + squareRoot.getDepth()); + r.setShift(squareRoot.getDepth() - r.getDepth() - bottomShift); + + // negative kern + Box negativeKern = new SpaceAtom(TeXConstants.UNIT_MU, -10f, 0, 0).createBox(env); + + // arrange both boxes together with the negative kern + Box res = new HorizontalBox(); + float pos = r.getWidth() + negativeKern.getWidth(); + if (pos < 0) + res.add(new StrutBox(-pos, 0, 0, 0)); + + res.add(r); + res.add(negativeKern); + res.add(squareRoot); + return res; + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OgonekAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OgonekAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OgonekAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,82 @@ +/* OgonekAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom with an ogonek. + */ +public class OgonekAtom extends Atom { + + private static final SymbolAtom ogonek = SymbolAtom.get("ogonek"); + private Atom base; + + public OgonekAtom(Atom base) { + this.base = base; + } + + public Box createBox(TeXEnvironment env) { + Box b = base.createBox(env); + VerticalBox vb = new VerticalBox(); + vb.add(b); + Char ch = env.getTeXFont().getChar("ogonek", env.getStyle()); + float italic = ch.getItalic(); + Box ogonek = new CharBox(ch); + Box y; + if (Math.abs(italic) > TeXFormula.PREC) { + y = new HorizontalBox(new StrutBox(-italic, 0, 0, 0)); + y.add(ogonek); + } else + y = ogonek; + + Box og = new HorizontalBox(y, b.getWidth(), TeXConstants.ALIGN_RIGHT); + vb.add(new StrutBox(0, -ogonek.getHeight(), 0, 0)); + vb.add(og); + float f = vb.getHeight() + vb.getDepth(); + vb.setHeight(b.getHeight()); + vb.setDepth(f - b.getHeight()); + return vb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OvalAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OvalAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OvalAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,62 @@ +/* ShadowAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Color; + +/** + * An atom representing a boxed base atom. + */ +public class OvalAtom extends FBoxAtom { + + public OvalAtom(Atom base) { + super(base); + } + + public Box createBox(TeXEnvironment env) { + return new OvalBox((FramedBox) super.createBox(env)); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OvalBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OvalBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OvalBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,78 @@ +/* OvalBox.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2011 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Graphics2D; +import java.awt.Stroke; +import java.awt.BasicStroke; +import java.awt.geom.RoundRectangle2D; + +/** + * A box representing a rotated box. + */ +public class OvalBox extends FramedBox { + + private float shadowRule; + + public OvalBox(FramedBox fbox) { + super(fbox.box, fbox.thickness, fbox.space); + } + + public void draw(Graphics2D g2, float x, float y) { + box.draw(g2, x + space + thickness, y); + Stroke st = g2.getStroke(); + g2.setStroke(new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); + float th = thickness / 2; + float r = 0.5f * Math.min(width - thickness, height + depth - thickness); + g2.draw(new RoundRectangle2D.Float(x + th, y - height + th, width - thickness, height + depth - thickness, r, r)); + //drawDebug(g2, x, y); + g2.setStroke(st); + } + + public int getLastFontId() { + return box.getLastFontId(); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OverBar.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OverBar.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OverBar.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,62 @@ +/* OverBar.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * A box representing another box with a horizontal rule above it, with appropriate + * kerning. + */ +public class OverBar extends VerticalBox { + + public OverBar(Box b, float kern, float thickness) { + // construct vertical box + add(new StrutBox(0, thickness, 0, 0)); + add(new HorizontalRule(thickness, b.getWidth(), 0)); + add(new StrutBox(0, kern, 0, 0)); + add(b); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OverUnderBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OverUnderBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OverUnderBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,140 @@ +/* OverUnderBox.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009-2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; + +/** + * A box representing another box with a delimiter box and a script box above or under it, + * with script and delimiter seperated by a kern. + */ +public class OverUnderBox extends Box { + + // base, delimiter and script atom + private final Box base; + private final Box del; + private final Box script; + + // kern amount between the delimiter and the script + private final float kern; + + // whether the delimiter should be drawn over (<-> under) the base atom + private final boolean over; + + /** + * the parameter boxes must have an equal width!! + * + * @param b + * base box to be drawn on the baseline + * @param d + * delimiter box + * @param script + * subscript or superscript box + * @param over + * true : draws delimiter and script box above the base box, false : under the + * base box + */ + public OverUnderBox(Box b, Box d, Box script, float kern, boolean over) { + base = b; + del = d; + this.script = script; + this.kern = kern; + this.over = over; + + // calculate metrics of the box + width = b.getWidth(); + height = b.height + + (over ? d.getWidth() : 0) + + (over && script != null ? script.height + script.depth + kern : 0); + depth = b.depth + + (over ? 0 : d.getWidth()) + + (!over && script != null ? script.height + script.depth + kern : 0); + } + + public void draw(Graphics2D g2, float x, float y) { + drawDebug(g2, x, y); + base.draw(g2, x, y); + + float yVar = y - base.height - del.getWidth(); + del.setDepth(del.getHeight() + del.getDepth()); + del.setHeight(0); + if (over) { // draw delimiter and script above base box + double transX = x + (del.height + del.depth) * 0.75, transY = yVar; + AffineTransform oldAt = g2.getTransform(); + g2.translate(transX, transY); + g2.rotate(Math.PI / 2); + del.draw(g2, 0, 0); + g2.setTransform(oldAt); + + // draw superscript + if (script != null) { + script.draw(g2, x, yVar - kern - script.depth); + } + } + + yVar = y + base.depth; + if (!over) { // draw delimiter and script under base box + double transX = x + (del.getHeight() + del.depth) * 0.75, transY = yVar; + AffineTransform oldAt = g2.getTransform(); + g2.translate(transX, transY); + g2.rotate(Math.PI / 2); + del.draw(g2, 0, 0); + g2.setTransform(oldAt); + yVar += del.getWidth(); + + // draw subscript + if (script != null) { + script.draw(g2, x, yVar + kern + script.height); + } + } + } + + public int getLastFontId() { + return base.getLastFontId(); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OverUnderDelimiter.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OverUnderDelimiter.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OverUnderDelimiter.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,117 @@ +/* OverUnderDelimiter.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009-2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * A box representing another atom with a delimiter and a script above or under it, + * with script and delimiter seperated by a kern. + */ +public class OverUnderDelimiter extends Atom { + + // base and script atom + private final Atom base; + private Atom script; + + // delimiter symbol + private final SymbolAtom symbol; + + // kern between delimiter and script + private final SpaceAtom kern; + + // whether the delimiter should be positioned above or under the base + private final boolean over; + + public OverUnderDelimiter(Atom base, Atom script, SymbolAtom s, int kernUnit, + float kern, boolean over) throws InvalidUnitException { + type = TeXConstants.TYPE_INNER; + this.base = base; + this.script = script; + symbol = s; + this.kern = new SpaceAtom(kernUnit, 0, kern, 0); + this.over = over; + } + + public void addScript(Atom script) { + this.script = script; + } + + public boolean isOver() { + return over; + } + + public Box createBox(TeXEnvironment env) { + Box b = (base == null ? new StrutBox(0, 0, 0, 0) : base.createBox(env)); + Box del = DelimiterFactory.create(symbol.getName(), env, b.getWidth()); + + Box scriptBox = null; + if (script != null) { + scriptBox = script.createBox((over ? env.supStyle() : env.subStyle())); + } + + // create centered horizontal box if smaller than maximum width + float max = getMaxWidth(b, del, scriptBox); + if (max - b.getWidth() > TeXFormula.PREC) { + b = new HorizontalBox(b, max, TeXConstants.ALIGN_CENTER); + } + + del = new VerticalBox(del, max, TeXConstants.ALIGN_CENTER); + if (scriptBox != null && max - scriptBox.getWidth() > TeXFormula.PREC) { + scriptBox = new HorizontalBox(scriptBox, max, TeXConstants.ALIGN_CENTER); + } + + return new OverUnderBox(b, del, scriptBox, kern.createBox(env).getHeight(), over); + } + + private static float getMaxWidth(Box b, Box del, Box script) { + float max = Math.max(b.getWidth(), del.getHeight() + del.getDepth()); + if (script != null) { + max = Math.max(max, script.getWidth()); + } + + return max; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OverlinedAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OverlinedAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/OverlinedAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,76 @@ +/* OverlinedAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing another atom with a horizontal line above it + */ +public class OverlinedAtom extends Atom { + + // base atom to be overlined + private final Atom base; + + public OverlinedAtom(Atom f) { + base = f; + type = TeXConstants.TYPE_ORDINARY; + } + + public Box createBox(TeXEnvironment env) { + float drt = env.getTeXFont().getDefaultRuleThickness(env.getStyle()); + + // cramp the style of the formula to be overlined and create vertical box + Box b = (base == null ? new StrutBox(0, 0, 0, 0) : base.createBox(env + .crampStyle())); + OverBar ob = new OverBar(b, 3 * drt, drt); + + // baseline vertical box = baseline box b + ob.setDepth(b.getDepth()); + ob.setHeight(b.getHeight() + 5 * drt); + + return ob; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ParseException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ParseException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ParseException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,61 @@ +/* ParseException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals that an error occured while parsing a string to a formula. + */ +public class ParseException extends JMathTeXException { + + public ParseException(String str, Throwable cause) { + super(str, cause); + } + + public ParseException(String str) { + super(str); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ParseOption.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ParseOption.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ParseOption.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,78 @@ +/* ParseOption.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2011 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +/** + * Parse command options, e.g. \includegraphics[width=1cm,height=2in,keepaspectratio]{...} + */ +public final class ParseOption { + + public final static Map parseMap(String options) { + Map map = new HashMap(); + if (options == null || options.length() == 0) { + return map; + } + StringTokenizer tokens = new StringTokenizer(options, ","); + while (tokens.hasMoreTokens()) { + String tok = tokens.nextToken().trim(); + String[] optarg = tok.split("="); + if (optarg != null){ + if (optarg.length == 2) { + map.put(optarg[0].trim(), optarg[1].trim()); + } else if (optarg.length == 1) { + map.put(optarg[0].trim(), null); + } + } + } + + return map; + } + +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PhantomAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PhantomAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PhantomAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,91 @@ +/* PhantomAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing another atom that should be drawn invisibly. + */ +public class PhantomAtom extends Atom implements Row { + + // RowAtom to be drawn invisibly + private RowAtom elements; + + // dimensions to be taken into account + private boolean w = true, h = true, d = true; + + public PhantomAtom(Atom el) { + if (el == null) + elements = new RowAtom(); + else + elements = new RowAtom(el); + } + + public PhantomAtom(Atom el, boolean width, boolean height, boolean depth) { + this(el); + w = width; + h = height; + d = depth; + } + + public Box createBox(TeXEnvironment env) { + Box res = elements.createBox(env); + return new StrutBox((w ? res.getWidth() : 0), (h ? res.getHeight() : 0), + (d ? res.getDepth() : 0), res.getShift()); + } + + public int getLeftType() { + return elements.getLeftType(); + } + + public int getRightType() { + return elements.getRightType(); + } + + public void setPreviousAtom(Dummy prev) { + elements.setPreviousAtom(prev); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefMacroInfo.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefMacroInfo.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefMacroInfo.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,596 @@ +/* PredefMacroInfo.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2011 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; + +/** + * Class to load the predefined commands. Mainly wrote to avoid the use of the Java reflection. + */ +class PredefMacroInfo extends MacroInfo { + + private int id; + + public PredefMacroInfo(int id, int nbArgs, int posOpts) { + super(nbArgs, posOpts); + this.id = id; + } + + public PredefMacroInfo(int id, int nbArgs) { + super(nbArgs); + this.id = id; + } + + public Object invoke(final TeXParser tp, final String[] args) throws ParseException { + return invokeID(id, tp, args); + } + + private static final Object invokeID(final int id, final TeXParser tp, final String[] args) throws ParseException { + try { + switch (id) { + case 0: + return PredefMacros.newcommand_macro(tp, args); + case 1: + return PredefMacros.renewcommand_macro(tp, args); + case 2: + return PredefMacros.rule_macro(tp, args); + case 3: + case 4: + return PredefMacros.hvspace_macro(tp, args); + case 5: + case 6: + case 7: + return PredefMacros.clrlap_macro(tp, args); + case 8: + case 9: + case 10: + return PredefMacros.mathclrlap_macro(tp, args); + case 11: + return PredefMacros.includegraphics_macro(tp, args); + case 12: + return PredefMacros.cfrac_macro(tp, args); + case 13: + return PredefMacros.frac_macro(tp, args); + case 14: + return PredefMacros.sfrac_macro(tp, args); + case 15: + return PredefMacros.genfrac_macro(tp, args); + case 16: + return PredefMacros.over_macro(tp, args); + case 17: + return PredefMacros.overwithdelims_macro(tp, args); + case 18: + return PredefMacros.atop_macro(tp, args); + case 19: + return PredefMacros.atopwithdelims_macro(tp, args); + case 20: + return PredefMacros.choose_macro(tp, args); + case 21: + return PredefMacros.underscore_macro(tp, args); + case 22: + return PredefMacros.mbox_macro(tp, args); + case 23: + return PredefMacros.text_macro(tp, args); + case 24: + return PredefMacros.intertext_macro(tp, args); + case 25: + return PredefMacros.binom_macro(tp, args); + case 26: + return PredefMacros.mathbf_macro(tp, args); + case 27: + return PredefMacros.bf_macro(tp, args); + case 28: + return PredefMacros.textstyle_macros(tp, args); + case 29: + return PredefMacros.textstyle_macros(tp, args); + case 30: + return PredefMacros.textstyle_macros(tp, args); + case 31: + return PredefMacros.mathit_macro(tp, args); + case 32: + return PredefMacros.it_macro(tp, args); + case 33: + return PredefMacros.mathrm_macro(tp, args); + case 34: + return PredefMacros.rm_macro(tp, args); + case 35: + return PredefMacros.textstyle_macros(tp, args); + case 36: + return PredefMacros.mathsf_macro(tp, args); + case 37: + return PredefMacros.sf_macro(tp, args); + case 38: + return PredefMacros.mathtt_macro(tp, args); + case 39: + return PredefMacros.tt_macro(tp, args); + case 40: + case 41: + case 42: + case 43: + case 44: + case 45: + return PredefMacros.textstyle_macros(tp, args); + case 46: + case 47: + case 48: + case 49: + case 50: + case 51: + case 52: + case 53: + case 54: + case 55: + case 56: + case 57: + return PredefMacros.accentbis_macros(tp, args); + case 58: + return PredefMacros.T_macro(tp, args); + case 59: + return PredefMacros.accentbis_macros(tp, args); + case 60: + return PredefMacros.accent_macro(tp, args); + case 61: + return PredefMacros.grkaccent_macro(tp, args); + case 62: + case 63: + case 64: + case 65: + case 66: + case 67: + case 68: + case 69: + case 70: + case 71: + case 72: + case 73: + case 74: + case 75: + return PredefMacros.accent_macros(tp, args); + case 76: + return PredefMacros.nbsp_macro(tp, args); + case 77: + return PredefMacros.smallmatrixATATenv_macro(tp, args); + case 78: + return PredefMacros.matrixATATenv_macro(tp, args); + case 79: + return PredefMacros.overrightarrow_macro(tp, args); + case 80: + return PredefMacros.overleftarrow_macro(tp, args); + case 81: + return PredefMacros.overleftrightarrow_macro(tp, args); + case 82: + return PredefMacros.underrightarrow_macro(tp, args); + case 83: + return PredefMacros.underleftarrow_macro(tp, args); + case 84: + return PredefMacros.underleftrightarrow_macro(tp, args); + case 85: + return PredefMacros.xleftarrow_macro(tp, args); + case 86: + return PredefMacros.xrightarrow_macro(tp, args); + case 87: + return PredefMacros.underbrace_macro(tp, args); + case 88: + return PredefMacros.overbrace_macro(tp, args); + case 89: + return PredefMacros.underbrack_macro(tp, args); + case 90: + return PredefMacros.overbrack_macro(tp, args); + case 91: + return PredefMacros.underparen_macro(tp, args); + case 92: + return PredefMacros.overparen_macro(tp, args); + case 93: + case 94: + return PredefMacros.sqrt_macro(tp, args); + case 95: + return PredefMacros.overline_macro(tp, args); + case 96: + return PredefMacros.underline_macro(tp, args); + case 97: + return PredefMacros.mathop_macro(tp, args); + case 98: + return PredefMacros.mathpunct_macro(tp, args); + case 99: + return PredefMacros.mathord_macro(tp, args); + case 100: + return PredefMacros.mathrel_macro(tp, args); + case 101: + return PredefMacros.mathinner_macro(tp, args); + case 102: + return PredefMacros.mathbin_macro(tp, args); + case 103: + return PredefMacros.mathopen_macro(tp, args); + case 104: + return PredefMacros.mathclose_macro(tp, args); + case 105: + return PredefMacros.joinrel_macro(tp, args); + case 106: + return PredefMacros.smash_macro(tp, args); + case 107: + return PredefMacros.vdots_macro(tp, args); + case 108: + return PredefMacros.ddots_macro(tp, args); + case 109: + return PredefMacros.iddots_macro(tp, args); + case 110: + return PredefMacros.nolimits_macro(tp, args); + case 111: + return PredefMacros.limits_macro(tp, args); + case 112: + return PredefMacros.normal_macro(tp, args); + case 113: + return PredefMacros.leftparenthesis_macro(tp, args); + case 114: + return PredefMacros.leftbracket_macro(tp, args); + case 115: + return PredefMacros.left_macro(tp, args); + case 116: + return PredefMacros.middle_macro(tp, args); + case 117: + return PredefMacros.cr_macro(tp, args); + case 118: + return PredefMacros.multicolumn_macro(tp, args); + case 119: + return PredefMacros.hdotsfor_macro(tp, args); + case 120: + return PredefMacros.arrayATATenv_macro(tp, args); + case 121: + return PredefMacros.alignATATenv_macro(tp, args); + case 122: + return PredefMacros.alignedATATenv_macro(tp, args); + case 123: + return PredefMacros.flalignATATenv_macro(tp, args); + case 124: + return PredefMacros.alignatATATenv_macro(tp, args); + case 125: + return PredefMacros.alignedatATATenv_macro(tp, args); + case 126: + return PredefMacros.multlineATATenv_macro(tp, args); + case 127: + return PredefMacros.gatherATATenv_macro(tp, args); + case 128: + return PredefMacros.gatheredATATenv_macro(tp, args); + case 129: + return PredefMacros.shoveright_macro(tp, args); + case 130: + return PredefMacros.shoveleft_macro(tp, args); + case 131: + return PredefMacros.backslashcr_macro(tp, args); + case 132: + return PredefMacros.newenvironment_macro(tp, args); + case 133: + return PredefMacros.renewenvironment_macro(tp, args); + case 134: + return PredefMacros.makeatletter_macro(tp, args); + case 135: + return PredefMacros.makeatother_macro(tp, args); + case 136: + case 137: + return PredefMacros.fbox_macro(tp, args); + case 138: + return PredefMacros.stackrel_macro(tp, args); + case 139: + return PredefMacros.stackbin_macro(tp, args); + case 140: + return PredefMacros.accentset_macro(tp, args); + case 141: + return PredefMacros.underaccent_macro(tp, args); + case 142: + return PredefMacros.undertilde_macro(tp, args); + case 143: + return PredefMacros.overset_macro(tp, args); + case 144: + return PredefMacros.Braket_macro(tp, args); + case 145: + return PredefMacros.Set_macro(tp, args); + case 146: + return PredefMacros.underset_macro(tp, args); + case 147: + return PredefMacros.boldsymbol_macro(tp, args); + case 148: + return PredefMacros.LaTeX_macro(tp, args); + case 149: + return PredefMacros.GeoGebra_macro(tp, args); + case 150: + return PredefMacros.big_macro(tp, args); + case 151: + return PredefMacros.Big_macro(tp, args); + case 152: + return PredefMacros.bigg_macro(tp, args); + case 153: + return PredefMacros.Bigg_macro(tp, args); + case 154: + return PredefMacros.bigl_macro(tp, args); + case 155: + return PredefMacros.Bigl_macro(tp, args); + case 156: + return PredefMacros.biggl_macro(tp, args); + case 157: + return PredefMacros.Biggl_macro(tp, args); + case 158: + return PredefMacros.bigr_macro(tp, args); + case 159: + return PredefMacros.Bigr_macro(tp, args); + case 160: + return PredefMacros.biggr_macro(tp, args); + case 161: + return PredefMacros.Biggr_macro(tp, args); + case 162: + return PredefMacros.displaystyle_macro(tp, args); + case 163: + return PredefMacros.textstyle_macro(tp, args); + case 164: + return PredefMacros.scriptstyle_macro(tp, args); + case 165: + return PredefMacros.scriptscriptstyle_macro(tp, args); + case 166: + return PredefMacros.sideset_macro(tp, args); + case 167: + return PredefMacros.prescript_macro(tp, args); + case 168: + return PredefMacros.rotatebox_macro(tp, args); + case 169: + return PredefMacros.reflectbox_macro(tp, args); + case 170: + return PredefMacros.scalebox_macro(tp, args); + case 171: + return PredefMacros.resizebox_macro(tp, args); + case 172: + return PredefMacros.raisebox_macro(tp, args); + case 173: + return PredefMacros.shadowbox_macro(tp, args); + case 174: + return PredefMacros.ovalbox_macro(tp, args); + case 175: + return PredefMacros.doublebox_macro(tp, args); + case 176: + return PredefMacros.phantom_macro(tp, args); + case 177: + return PredefMacros.hphantom_macro(tp, args); + case 178: + return PredefMacros.vphantom_macro(tp, args); + case 179: + return PredefMacros.spATbreve_macro(tp, args); + case 180: + return PredefMacros.spAThat_macro(tp, args); + case 181: + return PredefMacros.definecolor_macro(tp, args); + case 182: + return PredefMacros.textcolor_macro(tp, args); + case 183: + return PredefMacros.fgcolor_macro(tp, args); + case 184: + return PredefMacros.bgcolor_macro(tp, args); + case 185: + return PredefMacros.colorbox_macro(tp, args); + case 186: + return PredefMacros.fcolorbox_macro(tp, args); + case 187: + return PredefMacros.cedilla_macro(tp, args); + case 188: + return PredefMacros.IJ_macro(tp, args); + case 189: + return PredefMacros.IJ_macro(tp, args); + case 190: + return PredefMacros.TStroke_macro(tp, args); + case 191: + return PredefMacros.TStroke_macro(tp, args); + case 192: + return PredefMacros.LCaron_macro(tp, args); + case 193: + return PredefMacros.tcaron_macro(tp, args); + case 194: + return PredefMacros.LCaron_macro(tp, args); + case 195: + return PredefMacros.ogonek_macro(tp, args); + case 196: + return PredefMacros.cong_macro(tp, args); + case 197: + return PredefMacros.doteq_macro(tp, args); + case 198: + return PredefMacros.jlmDynamic_macro(tp, args); + case 199: + return PredefMacros.jlmExternalFont_macro(tp, args); + case 200: + return PredefMacros.jlmText_macro(tp, args); + case 201: + return PredefMacros.jlmTextit_macro(tp, args); + case 202: + return PredefMacros.jlmTextbf_macro(tp, args); + case 203: + return PredefMacros.jlmTextitbf_macro(tp, args); + case 204: + return PredefMacros.DeclareMathSizes_macro(tp, args); + case 205: + return PredefMacros.magnification_macro(tp, args); + case 206: + return PredefMacros.hline_macro(tp, args); + case 207: + case 208: + case 209: + case 210: + case 211: + case 212: + case 213: + case 214: + case 215: + case 216: + return PredefMacros.size_macros(tp, args); + case 217: + return PredefMacros.jlatexmathcumsup_macro(tp, args); + case 218: + return PredefMacros.jlatexmathcumsub_macro(tp, args); + case 219: + return PredefMacros.hstrok_macro(tp, args); + case 220: + return PredefMacros.Hstrok_macro(tp, args); + case 221: + return PredefMacros.dstrok_macro(tp, args); + case 222: + return PredefMacros.Dstrok_macro(tp, args); + case 223: + return PredefMacros.dotminus_macro(tp, args); + case 224: + return PredefMacros.ratio_macro(tp, args); + case 225: + return PredefMacros.smallfrowneq_macro(tp, args); + case 226: + return PredefMacros.geoprop_macro(tp, args); + case 227: + return PredefMacros.minuscolon_macro(tp, args); + case 228: + return PredefMacros.minuscoloncolon_macro(tp, args); + case 229: + return PredefMacros.simcolon_macro(tp, args); + case 230: + return PredefMacros.simcoloncolon_macro(tp, args); + case 231: + return PredefMacros.approxcolon_macro(tp, args); + case 232: + return PredefMacros.approxcoloncolon_macro(tp, args); + case 233: + return PredefMacros.coloncolon_macro(tp, args); + case 234: + return PredefMacros.equalscolon_macro(tp, args); + case 235: + return PredefMacros.equalscoloncolon_macro(tp, args); + case 236: + return PredefMacros.colonminus_macro(tp, args); + case 237: + return PredefMacros.coloncolonminus_macro(tp, args); + case 238: + return PredefMacros.colonequals_macro(tp, args); + case 239: + return PredefMacros.coloncolonequals_macro(tp, args); + case 240: + return PredefMacros.colonsim_macro(tp, args); + case 241: + return PredefMacros.coloncolonsim_macro(tp, args); + case 242: + return PredefMacros.colonapprox_macro(tp, args); + case 243: + return PredefMacros.coloncolonapprox_macro(tp, args); + case 244: + return PredefMacros.kern_macro(tp, args); + case 245: + return PredefMacros.char_macro(tp, args); + case 246: + case 247: + return PredefMacros.romannumeral_macro(tp, args); + case 248: + return PredefMacros.textcircled_macro(tp, args); + case 249: + return PredefMacros.textsc_macro(tp, args); + case 250: + return PredefMacros.sc_macro(tp, args); + case 251: + case 252: + case 253: + case 254: + case 255: + case 256: + case 257: + case 258: + case 259: + case 260: + return PredefMacros.muskip_macros(tp, args); + case 261: + return PredefMacros.quad_macro(tp, args); + case 262: + return PredefMacros.surd_macro(tp, args); + case 263: + return PredefMacros.iint_macro(tp, args); + case 264: + return PredefMacros.iiint_macro(tp, args); + case 265: + return PredefMacros.iiiint_macro(tp, args); + case 266: + return PredefMacros.idotsint_macro(tp, args); + case 267: + return PredefMacros.int_macro(tp, args); + case 268: + return PredefMacros.oint_macro(tp, args); + case 269: + return PredefMacros.lmoustache_macro(tp, args); + case 270: + return PredefMacros.rmoustache_macro(tp, args); + case 271: + return PredefMacros.insertBreakMark_macro(tp, args); + case 272: + return PredefMacros.jlmXML_macro(tp, args); + case 273: + return PredefMacros.above_macro(tp, args); + case 274: + return PredefMacros.abovewithdelims_macro(tp, args); + case 275: + return PredefMacros.st_macro(tp, args); + case 276: + return PredefMacros.fcscore_macro(tp, args); + case 277: + return PredefMacros.textstyle_macros(tp, args); + case 278: + return PredefMacros.qquad_macro(tp, args); + case 279: + return PredefMacros.longdiv_macro(tp, args); + case 280: + return PredefMacros.questeq_macro(tp, args); + case 281: + return PredefMacros.bangle_macro(tp, args); + case 282: + return PredefMacros.brace_macro(tp, args); + case 283: + return PredefMacros.brack_macro(tp, args); + default: + return null; + } + } catch (Exception e) { + throw new ParseException("Problem with command " + args[0] + " at position " + tp.getLine() + ":" + tp.getCol() + "\n" + e.getMessage()); + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefMacros.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefMacros.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefMacros.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,1877 @@ +/* predefMacros.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Color; +import java.awt.Font; +import java.util.Map; +import java.util.StringTokenizer; + +import org.scilab.forge.jlatexmath.dynamic.DynamicAtom; + +/** + * This class contains the most of basic commands of LaTeX, they're activated in + * byt the class PredefinedCommands.java. + **/ +public class PredefMacros { + + static { + NewEnvironmentMacro.addNewEnvironment("array", "\\array@@env{#1}{", "}", 1); + NewEnvironmentMacro.addNewEnvironment("tabular", "\\array@@env{#1}{", "}", 1); + NewEnvironmentMacro.addNewEnvironment("matrix", "\\matrix@@env{", "}", 0); + NewEnvironmentMacro.addNewEnvironment("smallmatrix", "\\smallmatrix@@env{", "}", 0); + NewEnvironmentMacro.addNewEnvironment("pmatrix", "\\left(\\begin{matrix}", "\\end{matrix}\\right)", 0); + NewEnvironmentMacro.addNewEnvironment("bmatrix", "\\left[\\begin{matrix}", "\\end{matrix}\\right]", 0); + NewEnvironmentMacro.addNewEnvironment("Bmatrix", "\\left\\{\\begin{matrix}", "\\end{matrix}\\right\\}", 0); + NewEnvironmentMacro.addNewEnvironment("vmatrix", "\\left|\\begin{matrix}", "\\end{matrix}\\right|", 0); + NewEnvironmentMacro.addNewEnvironment("Vmatrix", "\\left\\|\\begin{matrix}", "\\end{matrix}\\right\\|", 0); + NewEnvironmentMacro.addNewEnvironment("eqnarray", "\\begin{array}{rcl}", "\\end{array}", 0); + NewEnvironmentMacro.addNewEnvironment("align", "\\align@@env{", "}", 0); + NewEnvironmentMacro.addNewEnvironment("flalign", "\\flalign@@env{", "}", 0); + NewEnvironmentMacro.addNewEnvironment("alignat", "\\alignat@@env{#1}{", "}", 1); + NewEnvironmentMacro.addNewEnvironment("aligned", "\\aligned@@env{", "}", 0); + NewEnvironmentMacro.addNewEnvironment("alignedat", "\\alignedat@@env{#1}{", "}", 1); + NewEnvironmentMacro.addNewEnvironment("multline", "\\multline@@env{", "}", 0); + NewEnvironmentMacro.addNewEnvironment("cases", "\\left\\{\\begin{array}{l@{\\!}l}", "\\end{array}\\right.", 0); + NewEnvironmentMacro.addNewEnvironment("split", "\\begin{array}{rl}", "\\end{array}", 0); + NewEnvironmentMacro.addNewEnvironment("gather", "\\gather@@env{", "}", 0); + NewEnvironmentMacro.addNewEnvironment("gathered", "\\gathered@@env{", "}", 0); + NewEnvironmentMacro.addNewEnvironment("math", "\\(", "\\)", 0); + NewEnvironmentMacro.addNewEnvironment("displaymath", "\\[", "\\]", 0); + NewCommandMacro.addNewCommand("operatorname", "\\mathop{\\mathrm{#1}}\\nolimits ", 1); + NewCommandMacro.addNewCommand("DeclareMathOperator", "\\newcommand{#1}{\\mathop{\\mathrm{#2}}\\nolimits}", 2); + NewCommandMacro.addNewCommand("substack", "{\\scriptstyle\\begin{array}{c}#1\\end{array}}", 1); + NewCommandMacro.addNewCommand("dfrac", "\\genfrac{}{}{}{}{#1}{#2}", 2); + NewCommandMacro.addNewCommand("tfrac", "\\genfrac{}{}{}{1}{#1}{#2}", 2); + NewCommandMacro.addNewCommand("dbinom", "\\genfrac{(}{)}{0pt}{}{#1}{#2}", 2); + NewCommandMacro.addNewCommand("tbinom", "\\genfrac{(}{)}{0pt}{1}{#1}{#2}", 2); + NewCommandMacro.addNewCommand("pmod", "\\qquad\\mathbin{(\\mathrm{mod}\\ #1)}", 1); + NewCommandMacro.addNewCommand("mod", "\\qquad\\mathbin{\\mathrm{mod}\\ #1}", 1); + NewCommandMacro.addNewCommand("pod", "\\qquad\\mathbin{(#1)}", 1); + NewCommandMacro.addNewCommand("dddot", "\\mathop{#1}\\limits^{...}", 1); + NewCommandMacro.addNewCommand("ddddot", "\\mathop{#1}\\limits^{....}", 1); + NewCommandMacro.addNewCommand("spdddot", "^{\\mathrm{...}}", 0); + NewCommandMacro.addNewCommand("spbreve", "^{\\makeatletter\\sp@breve\\makeatother}", 0); + NewCommandMacro.addNewCommand("sphat", "^{\\makeatletter\\sp@hat\\makeatother}", 0); + NewCommandMacro.addNewCommand("spddot", "^{\\displaystyle..}", 0); + NewCommandMacro.addNewCommand("spcheck", "^{\\vee}", 0); + NewCommandMacro.addNewCommand("sptilde", "^{\\sim}", 0); + NewCommandMacro.addNewCommand("spdot", "^{\\displaystyle.}", 0); + NewCommandMacro.addNewCommand("d", "\\underaccent{\\dot}{#1}", 1); + NewCommandMacro.addNewCommand("b", "\\underaccent{\\bar}{#1}", 1); + NewCommandMacro.addNewCommand("Bra", "\\left\\langle{#1}\\right\\vert", 1); + NewCommandMacro.addNewCommand("Ket", "\\left\\vert{#1}\\right\\rangle", 1); + NewCommandMacro.addNewCommand("textsuperscript", "{}^{\\text{#1}}", 1); + NewCommandMacro.addNewCommand("textsubscript", "{}_{\\text{#1}}", 1); + NewCommandMacro.addNewCommand("textit", "\\mathit{\\text{#1}}", 1); + NewCommandMacro.addNewCommand("textbf", "\\mathbf{\\text{#1}}", 1); + NewCommandMacro.addNewCommand("textsf", "\\mathsf{\\text{#1}}", 1); + NewCommandMacro.addNewCommand("texttt", "\\mathtt{\\text{#1}}", 1); + NewCommandMacro.addNewCommand("textrm", "\\text{#1}", 1); + NewCommandMacro.addNewCommand("degree", "^\\circ", 0); + NewCommandMacro.addNewCommand("with", "\\mathbin{\\&}", 0); + NewCommandMacro.addNewCommand("parr", "\\mathbin{\\rotatebox[origin=c]{180}{\\&}}", 0); + NewCommandMacro.addNewCommand("copyright", "\\textcircled{\\raisebox{0.2ex}{c}}", 0); + NewCommandMacro.addNewCommand("L", "\\mathrm{\\polishlcross L}", 0); + NewCommandMacro.addNewCommand("l", "\\mathrm{\\polishlcross l}", 0); + NewCommandMacro.addNewCommand("Join", "\\mathop{\\rlap{\\ltimes}\\rtimes}", 0); + } + + public static final Atom fcscore_macro(final TeXParser tp, final String[] args) throws ParseException { + int n = Integer.parseInt(args[1]); + if (n > 5) { + final int q = n / 5; + final int r = n % 5; + RowAtom rat = new RowAtom(); + for (int i = 0; i < q; i++) { + rat.add(new FcscoreAtom(5)); + } + rat.add(new FcscoreAtom(r)); + + return rat; + } else { + return new FcscoreAtom(n); + } + } + + public static final Atom longdiv_macro(final TeXParser tp, final String[] args) throws ParseException { + try { + long dividend = Long.valueOf(args[1]); + long divisor = Long.valueOf(args[2]); + return new LongdivAtom(divisor, dividend); + } catch (NumberFormatException e) { + throw new ParseException("Divisor and dividend must be integer numbers"); + } + } + + public static final Atom st_macro(final TeXParser tp, final String[] args) throws ParseException { + return new StrikeThroughAtom(new TeXFormula(tp, args[1], false).root); + } + + public static final Atom Braket_macro(final TeXParser tp, final String[] args) throws ParseException { + String str = args[1].replaceAll("\\|", "\\\\middle\\\\vert "); + return new TeXFormula(tp, "\\left\\langle " + str + "\\right\\rangle").root; + } + + public static final Atom Set_macro(final TeXParser tp, final String[] args) throws ParseException { + String str = args[1].replaceFirst("\\|", "\\\\middle\\\\vert "); + return new TeXFormula(tp, "\\left\\{" + str + "\\right\\}").root; + } + + public static final Atom spATbreve_macro(final TeXParser tp, final String[] args) throws ParseException { + VRowAtom vra = new VRowAtom(new TeXFormula("\\displaystyle\\!\\breve{}").root); + vra.setRaise(TeXConstants.UNIT_EX, 0.6f); + + return new SmashedAtom(vra, null); + } + + public static final Atom spAThat_macro(final TeXParser tp, final String[] args) throws ParseException { + VRowAtom vra = new VRowAtom(new TeXFormula("\\displaystyle\\widehat{}").root); + vra.setRaise(TeXConstants.UNIT_EX, 0.6f); + + return new SmashedAtom(vra, null); + } + + public static final Atom hvspace_macro(final TeXParser tp, final String[] args) throws ParseException { + int i; + for (i = 0; i < args[1].length() && !Character.isLetter(args[1].charAt(i)); i++); + float f = 0; + try { + f = Float.parseFloat(args[1].substring(0, i)); + } catch (NumberFormatException e) { + throw new ParseException(e.toString()); + } + + int unit; + if (i != args[1].length()) { + unit = SpaceAtom.getUnit(args[1].substring(i).toLowerCase()); + } else { + unit = TeXConstants.UNIT_POINT; + } + + if (unit == -1) { + throw new ParseException("Unknown unit \"" + args[1].substring(i) + "\" !"); + } + + return args[0].charAt(0) == 'h' ? new SpaceAtom(unit, f, 0, 0) : new SpaceAtom(unit, 0, f, 0); + } + + public static final Atom clrlap_macro(final TeXParser tp, final String[] args) throws ParseException { + return new LapedAtom(new TeXFormula(tp, args[1]).root, args[0].charAt(0)); + } + + public static final Atom mathclrlap_macro(final TeXParser tp, final String[] args) throws ParseException { + return new LapedAtom(new TeXFormula(tp, args[1]).root, args[0].charAt(4)); + } + + public static final Atom includegraphics_macro(final TeXParser tp, final String[] args) throws ParseException { + return new GraphicsAtom(args[1], args[2]); + } + + public static final Atom rule_macro(final TeXParser tp, final String[] args) throws ParseException { + float[] winfo = SpaceAtom.getLength(args[1]); + if (winfo.length == 1) { + throw new ParseException("Error in getting width in \\rule command !"); + } + float[] hinfo = SpaceAtom.getLength(args[2]); + if (hinfo.length == 1) { + throw new ParseException("Error in getting height in \\rule command !"); + } + + float[] rinfo = SpaceAtom.getLength(args[3]); + if (rinfo.length == 1) { + throw new ParseException("Error in getting raise in \\rule command !"); + } + + return new RuleAtom((int) winfo[0], winfo[1], (int) hinfo[0], hinfo[1], (int) rinfo[0], -rinfo[1]); + } + + /* Thanks to Juan Enrique Escobar Robles for this macro */ + public static final Atom cfrac_macro(final TeXParser tp, final String[] args) throws ParseException { + int alig = TeXConstants.ALIGN_CENTER; + if ("r".equals(args[3])) { + alig = TeXConstants.ALIGN_RIGHT; + } else if ("l".equals(args[3])) { + alig = TeXConstants.ALIGN_LEFT; + } + TeXFormula num = new TeXFormula(tp, args[1], false); + TeXFormula denom = new TeXFormula(tp, args[2], false); + if (num.root == null || denom.root == null) { + throw new ParseException("Both numerator and denominator of a fraction can't be empty!"); + } + Atom f = new FractionAtom(num.root, denom.root, true, alig, TeXConstants.ALIGN_CENTER); + RowAtom rat = new RowAtom(); + rat.add(new StyleAtom(TeXConstants.STYLE_DISPLAY, f)); + return rat; + } + + public static final Atom frac_macro(final TeXParser tp, final String[] args) throws ParseException { + TeXFormula num = new TeXFormula(tp, args[1], false); + TeXFormula denom = new TeXFormula(tp, args[2], false); + if (num.root == null || denom.root == null) + throw new ParseException("Both numerator and denominator of a fraction can't be empty!"); + return new FractionAtom(num.root, denom.root, true); + } + + public static final Atom sfrac_macro(final TeXParser tp, final String[] args) throws ParseException { + TeXFormula num = new TeXFormula(tp, args[1], false); + TeXFormula denom = new TeXFormula(tp, args[2], false); + if (num.root == null || denom.root == null) + throw new ParseException("Both numerator and denominator of a fraction can't be empty!"); + + double scaleX = 0.75; + double scaleY = 0.75; + float raise1 = 0.45f; + float shiftL = -0.13f; + float shiftR = -0.065f; + Atom slash = SymbolAtom.get("slash"); + + if (!tp.isMathMode()) { + scaleX = 0.6; + scaleY = 0.5; + raise1 = 0.75f; + shiftL = -0.24f; + shiftR = -0.24f; + slash = new VRowAtom(new ScaleAtom(SymbolAtom.get("textfractionsolidus"), 1.25, 0.65)); + ((VRowAtom) slash).setRaise(TeXConstants.UNIT_EX, 0.4f); + } + + VRowAtom snum = new VRowAtom(new ScaleAtom(num.root, scaleX, scaleY)); + snum.setRaise(TeXConstants.UNIT_EX, raise1); + RowAtom at = new RowAtom(snum); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, shiftL, 0f, 0f)); + at.add(slash); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, shiftR, 0f, 0f)); + at.add(new ScaleAtom(denom.root, scaleX, scaleY)); + + return at; + } + + public static final Atom genfrac_macro(final TeXParser tp, final String[] args) throws ParseException { + TeXFormula left = new TeXFormula(tp, args[1], false); + SymbolAtom L = null, R = null; + if (left != null && left.root instanceof SymbolAtom) { + L = (SymbolAtom) left.root; + } + + TeXFormula right = new TeXFormula(tp, args[2], false); + if (right != null && right.root instanceof SymbolAtom) { + R = (SymbolAtom) right.root; + } + + boolean rule = true; + float[] ths = SpaceAtom.getLength(args[3]); + if (args[3] == null || args[3].length() == 0 || ths.length == 1) { + ths = new float[]{0.0f, 0.0f}; + rule = false; + } + + int style = 0; + if (args[4].length() != 0) { + style = Integer.parseInt(args[4]); + } + TeXFormula num = new TeXFormula(tp, args[5], false); + TeXFormula denom = new TeXFormula(tp, args[6], false); + if (num.root == null || denom.root == null) + throw new ParseException("Both numerator and denominator of a fraction can't be empty!"); + Atom at = new FractionAtom(num.root, denom.root, rule, (int) ths[0], ths[1]); + RowAtom rat = new RowAtom(); + rat.add(new StyleAtom(style * 2, new FencedAtom(at, L, R))); + + return rat; + } + + public static final Atom over_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom num = tp.getFormulaAtom(); + Atom denom = new TeXFormula(tp, tp.getOverArgument(), false).root; + if (num == null || denom == null) + throw new ParseException("Both numerator and denominator of a fraction can't be empty!"); + return new FractionAtom(num, denom, true); + } + + public static final Atom overwithdelims_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom num = tp.getFormulaAtom(); + Atom denom = new TeXFormula(tp, tp.getOverArgument(), false).root; + + if (num == null || denom == null) + throw new ParseException("Both numerator and denominator of a fraction can't be empty!"); + + Atom left = new TeXFormula(tp, args[1], false).root; + if (left instanceof BigDelimiterAtom) + left = ((BigDelimiterAtom)left).delim; + Atom right = new TeXFormula(tp, args[2], false).root; + if (right instanceof BigDelimiterAtom) + right = ((BigDelimiterAtom)right).delim; + if (left instanceof SymbolAtom && right instanceof SymbolAtom) { + return new FencedAtom(new FractionAtom(num, denom, true), (SymbolAtom) left, (SymbolAtom) right); + } + + RowAtom ra = new RowAtom(); + ra.add(left); + ra.add(new FractionAtom(num, denom, true)); + ra.add(right); + return ra; + } + + public static final Atom atop_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom num = tp.getFormulaAtom(); + Atom denom = new TeXFormula(tp, tp.getOverArgument(), false).root; + if (num == null || denom == null) + throw new ParseException("Both numerator and denominator of a fraction can't be empty!"); + return new FractionAtom(num, denom, false); + } + + public static final Atom atopwithdelims_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom num = tp.getFormulaAtom(); + Atom denom = new TeXFormula(tp, tp.getOverArgument(), false).root; + + if (num == null || denom == null) + throw new ParseException("Both numerator and denominator of a fraction can't be empty!"); + + Atom left = new TeXFormula(tp, args[1], false).root; + if (left instanceof BigDelimiterAtom) + left = ((BigDelimiterAtom)left).delim; + Atom right = new TeXFormula(tp, args[2], false).root; + if (right instanceof BigDelimiterAtom) + right = ((BigDelimiterAtom)right).delim; + if (left instanceof SymbolAtom && right instanceof SymbolAtom) { + return new FencedAtom(new FractionAtom(num, denom, false), (SymbolAtom) left, (SymbolAtom) right); + } + + RowAtom ra = new RowAtom(); + ra.add(left); + ra.add(new FractionAtom(num, denom, false)); + ra.add(right); + return ra; + } + + public static final Atom choose_macro(final TeXParser tp, final String[] args) throws ParseException { + return choose_brackets("lbrack", "rbrack", tp, args); + } + + public static final Atom brack_macro(final TeXParser tp, final String[] args) throws ParseException { + return choose_brackets("lsqbrack", "rsqbrack", tp, args); + } + + public static final Atom bangle_macro(final TeXParser tp, final String[] args) throws ParseException { + return choose_brackets("langle", "rangle", tp, args); + } + + public static final Atom brace_macro(final TeXParser tp, final String[] args) throws ParseException { + return choose_brackets("lbrace", "rbrace", tp, args); + } + + public static final Atom choose_brackets(final String left, final String right, final TeXParser tp, final String[] args) throws ParseException { + Atom num = tp.getFormulaAtom(); + Atom denom = new TeXFormula(tp, tp.getOverArgument(), false).root; + if (num == null || denom == null) + throw new ParseException("Both numerator and denominator of choose can't be empty!"); + return new FencedAtom(new FractionAtom(num, denom, false), new SymbolAtom(left, TeXConstants.TYPE_OPENING, true), new SymbolAtom(right, TeXConstants.TYPE_CLOSING, true)); + } + + public static final Atom binom_macro(final TeXParser tp, final String[] args) throws ParseException { + TeXFormula num = new TeXFormula(tp, args[1], false); + TeXFormula denom = new TeXFormula(tp, args[2], false); + if (num.root == null || denom.root == null) + throw new ParseException("Both binomial coefficients must be not empty !!"); + return new FencedAtom(new FractionAtom(num.root, denom.root, false), new SymbolAtom("lbrack", TeXConstants.TYPE_OPENING, true), new SymbolAtom("rbrack", TeXConstants.TYPE_CLOSING, true)); + } + + public static final Atom above_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom num = tp.getFormulaAtom(); + float[] dim = tp.getLength(); + Atom denom = new TeXFormula(tp, tp.getOverArgument(), false).root; + if (dim == null || dim.length != 2) { + throw new ParseException("Invalid length in above macro"); + } + if (num == null || denom == null) + throw new ParseException("Both numerator and denominator of a fraction can't be empty!"); + + return new FractionAtom(num, denom, (int) dim[0], dim[1]); + } + + public static final Atom abovewithdelims_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom num = tp.getFormulaAtom(); + float[] dim = tp.getLength(); + Atom denom = new TeXFormula(tp, tp.getOverArgument(), false).root; + if (dim == null || dim.length != 2) { + throw new ParseException("Invalid length in above macro"); + } + if (num == null || denom == null) + throw new ParseException("Both numerator and denominator of a fraction can't be empty!"); + + Atom left = new TeXFormula(tp, args[1], false).root; + if (left instanceof BigDelimiterAtom) + left = ((BigDelimiterAtom)left).delim; + Atom right = new TeXFormula(tp, args[2], false).root; + if (right instanceof BigDelimiterAtom) + right = ((BigDelimiterAtom)right).delim; + if (left instanceof SymbolAtom && right instanceof SymbolAtom) { + return new FencedAtom(new FractionAtom(num, denom, (int) dim[0], dim[1]), (SymbolAtom) left, (SymbolAtom) right); + } + + RowAtom ra = new RowAtom(); + ra.add(left); + ra.add(new FractionAtom(num, denom, true)); + ra.add(right); + return ra; + } + + public static final Atom textstyle_macros(final TeXParser tp, final String[] args) throws ParseException { + String style = args[0]; + if ("frak".equals(args[0])) + style = "mathfrak"; + else if ("Bbb".equals(args[0])) + style = "mathbb"; + else if ("bold".equals(args[0])) + return new BoldAtom(new TeXFormula(tp, args[1], false).root); + else if ("cal".equals(args[0])) + style = "mathcal"; + + TeXFormula.FontInfos fontInfos = TeXFormula.externalFontMap.get(Character.UnicodeBlock.BASIC_LATIN); + if (fontInfos != null) { + TeXFormula.externalFontMap.put(Character.UnicodeBlock.BASIC_LATIN, null); + } + Atom at = new TeXFormula(tp, args[1], false).root; + if (fontInfos != null) { + TeXFormula.externalFontMap.put(Character.UnicodeBlock.BASIC_LATIN, fontInfos); + } + + return new TextStyleAtom(at, style); + } + + public static final Atom mbox_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom group = new RomanAtom(new TeXFormula(tp, args[1], "mathnormal", false, false).root); + return new StyleAtom(TeXConstants.STYLE_TEXT, group); + } + + public static final Atom text_macro(final TeXParser tp, final String[] args) throws ParseException { + return new RomanAtom(new TeXFormula(tp, args[1], "mathnormal", false, false).root); + } + + public static final Atom underscore_macro(final TeXParser tp, final String[] args) throws ParseException { + return new UnderscoreAtom(); + } + + public static final Atom accent_macros(final TeXParser tp, final String[] args) throws ParseException { + return new AccentedAtom(new TeXFormula(tp, args[1], false).root, args[0]); + } + + public static final Atom grkaccent_macro(final TeXParser tp, final String[] args) throws ParseException { + return new AccentedAtom(new TeXFormula(tp, args[2], false).root, new TeXFormula(tp, args[1], false).root, false); + } + + public static final Atom accent_macro(final TeXParser tp, final String[] args) throws ParseException { + return new AccentedAtom(new TeXFormula(tp, args[2], false).root, new TeXFormula(tp, args[1], false).root); + } + + public static final Atom accentbis_macros(final TeXParser tp, final String[] args) throws ParseException { + String acc = ""; + switch (args[0].charAt(0)) { + case '~' : + acc = "tilde"; + break; + case '\'' : + acc = "acute"; + break; + case '^' : + acc = "hat"; + break; + case '\"' : + acc = "ddot"; + break; + case '`' : + acc = "grave"; + break; + case '=' : + acc = "bar"; + break; + case '.' : + acc = "dot"; + break; + case 'u' : + acc = "breve"; + break; + case 'v' : + acc = "check"; + break; + case 'H' : + acc = "doubleacute"; + break; + case 't' : + acc = "tie"; + break; + case 'r' : + acc = "mathring"; + break; + case 'U' : + acc = "cyrbreve"; + } + + return new AccentedAtom(new TeXFormula(tp, args[1], false).root, acc); + } + + public static final Atom cedilla_macro(final TeXParser tp, final String[] args) throws ParseException { + return new CedillaAtom(new TeXFormula(tp, args[1]).root); + } + + public static final Atom IJ_macro(final TeXParser tp, final String[] args) throws ParseException { + return new IJAtom(args[0].charAt(0) == 'I'); + } + + public static final Atom TStroke_macro(final TeXParser tp, final String[] args) throws ParseException { + return new TStrokeAtom(args[0].charAt(0) == 'T'); + } + + public static final Atom LCaron_macro(final TeXParser tp, final String[] args) throws ParseException { + return new LCaronAtom(args[0].charAt(0) == 'L'); + } + + public static final Atom tcaron_macro(final TeXParser tp, final String[] args) throws ParseException { + return new tcaronAtom(); + } + + public static final Atom ogonek_macro(final TeXParser tp, final String[] args) throws ParseException { + return new OgonekAtom(new TeXFormula(tp, args[1]).root); + } + + public static final Atom nbsp_macro(final TeXParser tp, final String[] args) throws ParseException { + return new SpaceAtom(); + } + + public static final Atom sqrt_macro(final TeXParser tp, final String[] args) throws ParseException { + if (args[2] == null) + return new NthRoot(new TeXFormula(tp, args[1], false).root, null); + return new NthRoot(new TeXFormula(tp, args[1], false).root, new TeXFormula(tp, args[2], false).root); + } + + public static final Atom overrightarrow_macro(final TeXParser tp, final String[] args) throws ParseException { + return new UnderOverArrowAtom(new TeXFormula(tp, args[1], false).root, false, true); + } + + public static final Atom overleftarrow_macro(final TeXParser tp, final String[] args) throws ParseException { + return new UnderOverArrowAtom(new TeXFormula(tp, args[1], false).root, true, true); + } + + public static final Atom overleftrightarrow_macro(final TeXParser tp, final String[] args) throws ParseException { + return new UnderOverArrowAtom(new TeXFormula(tp, args[1], false).root, true); + } + + public static final Atom underrightarrow_macro(final TeXParser tp, final String[] args) throws ParseException { + return new UnderOverArrowAtom(new TeXFormula(tp, args[1], false).root, false, false); + } + + public static final Atom underleftarrow_macro(final TeXParser tp, final String[] args) throws ParseException { + return new UnderOverArrowAtom(new TeXFormula(tp, args[1], false).root, true, false); + } + + public static final Atom underleftrightarrow_macro(final TeXParser tp, final String[] args) throws ParseException { + return new UnderOverArrowAtom(new TeXFormula(tp, args[1], false).root, false); + } + + public static final Atom xleftarrow_macro(final TeXParser tp, final String[] args) throws ParseException { + return new XArrowAtom(new TeXFormula(tp, args[1], false).root, new TeXFormula(tp, args[2]).root, true); + } + + public static final Atom xrightarrow_macro(final TeXParser tp, final String[] args) throws ParseException { + return new XArrowAtom(new TeXFormula(tp, args[1], false).root, new TeXFormula(tp, args[2]).root, false); + } + + public static final Atom sideset_macro(final TeXParser tp, final String[] args) throws ParseException { + TeXFormula tf = new TeXFormula(); + tf.add(new PhantomAtom(new TeXFormula(tp, args[3]).root, false, true, true)); + tf.append(tp.getIsPartial(), args[1]); + tf.add(new SpaceAtom(TeXConstants.UNIT_MU, -0.3f, 0f, 0f)); + tf.append(tp.getIsPartial(), args[3] + "\\nolimits" + args[2]); + return new TypedAtom(TeXConstants.TYPE_ORDINARY, TeXConstants.TYPE_ORDINARY, tf.root); + } + + public static final Atom prescript_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom base = new TeXFormula(tp, args[3]).root; + tp.addAtom(new ScriptsAtom(new PhantomAtom(base, false, true, true), new TeXFormula(tp, args[2]).root, new TeXFormula(tp, args[1]).root, false)); + tp.addAtom(new SpaceAtom(TeXConstants.UNIT_MU, -0.3f, 0f, 0f)); + return new TypedAtom(TeXConstants.TYPE_ORDINARY, TeXConstants.TYPE_ORDINARY, base); + } + + public static final Atom underbrace_macro(final TeXParser tp, final String[] args) throws ParseException { + return new OverUnderDelimiter(new TeXFormula(tp, args[1], false).root, null, SymbolAtom.get("rbrace"), TeXConstants.UNIT_EX, 0, false); + } + + public static final Atom overbrace_macro(final TeXParser tp, final String[] args) throws ParseException { + return new OverUnderDelimiter(new TeXFormula(tp, args[1], false).root, null, SymbolAtom.get("lbrace"), TeXConstants.UNIT_EX, 0, true); + } + + public static final Atom underbrack_macro(final TeXParser tp, final String[] args) throws ParseException { + return new OverUnderDelimiter(new TeXFormula(tp, args[1], false).root, null, SymbolAtom.get("rsqbrack"), TeXConstants.UNIT_EX, 0, false); + } + + public static final Atom overbrack_macro(final TeXParser tp, final String[] args) throws ParseException { + return new OverUnderDelimiter(new TeXFormula(tp, args[1], false).root, null, SymbolAtom.get("lsqbrack"), TeXConstants.UNIT_EX, 0, true); + } + + public static final Atom underparen_macro(final TeXParser tp, final String[] args) throws ParseException { + return new OverUnderDelimiter(new TeXFormula(tp, args[1], false).root, null, SymbolAtom.get("rbrack"), TeXConstants.UNIT_EX, 0, false); + } + + public static final Atom overparen_macro(final TeXParser tp, final String[] args) throws ParseException { + return new OverUnderDelimiter(new TeXFormula(tp, args[1], false).root, null, SymbolAtom.get("lbrack"), TeXConstants.UNIT_EX, 0, true); + } + + public static final Atom overline_macro(final TeXParser tp, final String[] args) throws ParseException { + return new OverlinedAtom(new TeXFormula(tp, args[1], false).root); + } + + public static final Atom underline_macro(final TeXParser tp, final String[] args) throws ParseException { + return new UnderlinedAtom(new TeXFormula(tp, args[1], false).root); + } + + public static final Atom mathop_macro(final TeXParser tp, final String[] args) throws ParseException { + TypedAtom at = new TypedAtom(TeXConstants.TYPE_BIG_OPERATOR, TeXConstants.TYPE_BIG_OPERATOR, new TeXFormula(tp, args[1], false).root); + at.type_limits = TeXConstants.SCRIPT_NORMAL; + return at; + } + + public static final Atom mathpunct_macro(final TeXParser tp, final String[] args) throws ParseException { + return new TypedAtom(TeXConstants.TYPE_PUNCTUATION, TeXConstants.TYPE_PUNCTUATION, new TeXFormula(tp, args[1], false).root); + } + + public static final Atom mathord_macro(final TeXParser tp, final String[] args) throws ParseException { + return new TypedAtom(TeXConstants.TYPE_ORDINARY, TeXConstants.TYPE_ORDINARY, new TeXFormula(tp, args[1], false).root); + } + + public static final Atom mathrel_macro(final TeXParser tp, final String[] args) throws ParseException { + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, new TeXFormula(tp, args[1], false).root); + } + + public static final Atom mathinner_macro(final TeXParser tp, final String[] args) throws ParseException { + return new TypedAtom(TeXConstants.TYPE_INNER, TeXConstants.TYPE_INNER, new TeXFormula(tp, args[1], false).root); + } + + public static final Atom mathbin_macro(final TeXParser tp, final String[] args) throws ParseException { + return new TypedAtom(TeXConstants.TYPE_BINARY_OPERATOR, TeXConstants.TYPE_BINARY_OPERATOR, new TeXFormula(tp, args[1], false).root); + } + + public static final Atom mathopen_macro(final TeXParser tp, final String[] args) throws ParseException { + return new TypedAtom(TeXConstants.TYPE_OPENING, TeXConstants.TYPE_OPENING, new TeXFormula(tp, args[1], false).root); + } + + public static final Atom mathclose_macro(final TeXParser tp, final String[] args) throws ParseException { + return new TypedAtom(TeXConstants.TYPE_CLOSING, TeXConstants.TYPE_CLOSING, new TeXFormula(tp, args[1], false).root); + } + + public static final Atom joinrel_macro(final TeXParser tp, final String[] args) throws ParseException { + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, new SpaceAtom(TeXConstants.UNIT_MU, -2.6f, 0, 0)); + } + + public static final Atom smash_macro(final TeXParser tp, final String[] args) throws ParseException { + return new SmashedAtom(new TeXFormula(tp, args[1], false).root, args[2]); + } + + public static final Atom vdots_macro(final TeXParser tp, final String[] args) throws ParseException { + return new VdotsAtom(); + } + + public static final Atom ddots_macro(final TeXParser tp, final String[] args) throws ParseException { + return new TypedAtom(TeXConstants.TYPE_INNER, TeXConstants.TYPE_INNER, new DdotsAtom()); + } + + public static final Atom iddots_macro(final TeXParser tp, final String[] args) throws ParseException { + return new TypedAtom(TeXConstants.TYPE_INNER, TeXConstants.TYPE_INNER, new IddotsAtom()); + } + + public static final Atom nolimits_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = tp.getLastAtom(); + at.type_limits = TeXConstants.SCRIPT_NOLIMITS; + return at.clone(); + } + + public static final Atom limits_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = tp.getLastAtom(); + at.type_limits = TeXConstants.SCRIPT_LIMITS; + return at.clone(); + } + + public static final Atom normal_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = tp.getLastAtom(); + at.type_limits = TeXConstants.SCRIPT_NORMAL; + return at.clone(); + } + + public static final Atom left_macro(final TeXParser tp, final String[] args) throws ParseException { + String grp = tp.getGroup("\\left", "\\right"); + Atom left = new TeXFormula(tp, args[1], false).root; + if (left instanceof BigDelimiterAtom) + left = ((BigDelimiterAtom)left).delim; + Atom right = tp.getArgument(); + if (right instanceof BigDelimiterAtom) + right = ((BigDelimiterAtom)right).delim; + if (left instanceof SymbolAtom && right instanceof SymbolAtom) { + TeXFormula tf = new TeXFormula(tp, grp, false); + return new FencedAtom(tf.root, (SymbolAtom)left, tf.middle, (SymbolAtom)right); + } + + RowAtom ra = new RowAtom(); + ra.add(left); + ra.add(new TeXFormula(tp, grp, false).root); + ra.add(right); + return ra; + } + + public static final Atom leftparenthesis_macro(final TeXParser tp, final String[] args) throws ParseException { + String grp = tp.getGroup("\\(", "\\)"); + return new MathAtom(new TeXFormula(tp, grp, false).root, TeXConstants.STYLE_TEXT); + } + + public static final Atom leftbracket_macro(final TeXParser tp, final String[] args) throws ParseException { + String grp = tp.getGroup("\\[", "\\]"); + return new MathAtom(new TeXFormula(tp, grp, false).root, TeXConstants.STYLE_DISPLAY); + } + + public static final Atom middle_macro(final TeXParser tp, final String[] args) throws ParseException { + return new MiddleAtom(new TeXFormula(tp, args[1]).root); + } + + public static final Atom cr_macro(final TeXParser tp, final String[] args) throws ParseException { + if (tp.isArrayMode()) { + tp.addRow(); + } else { + ArrayOfAtoms array = new ArrayOfAtoms(); + array.add(tp.formula.root); + array.addRow(); + TeXParser parser = new TeXParser(tp.getIsPartial(), tp.getStringFromCurrentPos(), array, false, tp.isIgnoreWhiteSpace()); + parser.parse(); + array.checkDimensions(); + tp.finish(); + tp.formula.root = array.getAsVRow();//new MatrixAtom(tp.getIsPartial(), array, MatrixAtom.ARRAY, TeXConstants.ALIGN_LEFT, false); + } + + return null; + } + + public static final Atom backslashcr_macro(final TeXParser tp, final String[] args) throws ParseException { + return cr_macro(tp, args); + } + + public static final Atom intertext_macro(final TeXParser tp, final String[] args) throws ParseException { + if (!tp.isArrayMode()) { + throw new ParseException("Bad environment for \\intertext command !"); + } + + String str = args[1].replaceAll("\\^\\{\\\\prime\\}", "\'"); + str = str.replaceAll("\\^\\{\\\\prime\\\\prime\\}", "\'\'"); + Atom at = new RomanAtom(new TeXFormula(tp, str, "mathnormal", false, false).root); + at.type = TeXConstants.TYPE_INTERTEXT; + tp.addAtom(at); + tp.addRow(); + return null; + } + + public static final Atom smallmatrixATATenv_macro(final TeXParser tp, final String[] args) throws ParseException { + ArrayOfAtoms array = new ArrayOfAtoms(); + TeXParser parser = new TeXParser(tp.getIsPartial(), args[1], array, false); + parser.parse(); + array.checkDimensions(); + return new MatrixAtom(tp.getIsPartial(), array, MatrixAtom.SMALLMATRIX); + } + + public static final Atom matrixATATenv_macro(final TeXParser tp, final String[] args) throws ParseException { + ArrayOfAtoms array = new ArrayOfAtoms(); + TeXParser parser = new TeXParser(tp.getIsPartial(), args[1], array, false); + parser.parse(); + array.checkDimensions(); + return new MatrixAtom(tp.getIsPartial(), array, MatrixAtom.MATRIX); + } + + public static final Atom multicolumn_macro(final TeXParser tp, final String[] args) throws ParseException { + int n = Integer.parseInt(args[1]); + tp.addAtom(new MulticolumnAtom(n, args[2], new TeXFormula(tp, args[3]).root)); + ((ArrayOfAtoms)tp.formula).addCol(n); + return null; + } + + public static final Atom hdotsfor_macro(final TeXParser tp, final String[] args) throws ParseException { + int n = Integer.parseInt(args[1]); + float f = 1; + if (args[2] != null) { + f = Float.parseFloat(args[2]); + } + tp.addAtom(new HdotsforAtom(n, f)); + ((ArrayOfAtoms)tp.formula).addCol(n); + return null; + } + + public static final Atom arrayATATenv_macro(final TeXParser tp, final String[] args) throws ParseException { + ArrayOfAtoms array = new ArrayOfAtoms(); + TeXParser parser = new TeXParser(tp.getIsPartial(), args[2], array, false); + parser.parse(); + array.checkDimensions(); + return new MatrixAtom(tp.getIsPartial(), array, args[1], true); + } + + public static final Atom alignATATenv_macro(final TeXParser tp, final String[] args) throws ParseException { + ArrayOfAtoms array = new ArrayOfAtoms(); + TeXParser parser = new TeXParser(tp.getIsPartial(), args[1], array, false); + parser.parse(); + array.checkDimensions(); + return new MatrixAtom(tp.getIsPartial(), array, MatrixAtom.ALIGN); + } + + public static final Atom flalignATATenv_macro(final TeXParser tp, final String[] args) throws ParseException { + ArrayOfAtoms array = new ArrayOfAtoms(); + TeXParser parser = new TeXParser(tp.getIsPartial(), args[1], array, false); + parser.parse(); + array.checkDimensions(); + return new MatrixAtom(tp.getIsPartial(), array, MatrixAtom.FLALIGN); + } + + public static final Atom alignatATATenv_macro(final TeXParser tp, final String[] args) throws ParseException { + ArrayOfAtoms array = new ArrayOfAtoms(); + TeXParser parser = new TeXParser(tp.getIsPartial(), args[2], array, false); + parser.parse(); + array.checkDimensions(); + int n = Integer.parseInt(args[1]); + if (array.col != 2 * n) { + throw new ParseException("Bad number of equations in alignat environment !"); + } + + return new MatrixAtom(tp.getIsPartial(), array, MatrixAtom.ALIGNAT); + } + + public static final Atom alignedATATenv_macro(final TeXParser tp, final String[] args) throws ParseException { + ArrayOfAtoms array = new ArrayOfAtoms(); + TeXParser parser = new TeXParser(tp.getIsPartial(), args[1], array, false); + parser.parse(); + array.checkDimensions(); + return new MatrixAtom(tp.getIsPartial(), array, MatrixAtom.ALIGNED); + } + + public static final Atom alignedatATATenv_macro(final TeXParser tp, final String[] args) throws ParseException { + ArrayOfAtoms array = new ArrayOfAtoms(); + TeXParser parser = new TeXParser(tp.getIsPartial(), args[2], array, false); + parser.parse(); + array.checkDimensions(); + int n = Integer.parseInt(args[1]); + if (array.col != 2 * n) { + throw new ParseException("Bad number of equations in alignedat environment !"); + } + + return new MatrixAtom(tp.getIsPartial(), array, MatrixAtom.ALIGNEDAT); + } + + public static final Atom multlineATATenv_macro(final TeXParser tp, final String[] args) throws ParseException { + ArrayOfAtoms array = new ArrayOfAtoms(); + TeXParser parser = new TeXParser(tp.getIsPartial(), args[1], array, false); + parser.parse(); + array.checkDimensions(); + if (array.col > 1) { + throw new ParseException("Character '&' is only available in array mode !"); + } + if (array.col == 0) { + return null; + } + + return new MultlineAtom(tp.getIsPartial(), array, MultlineAtom.MULTLINE); + } + + public static final Atom gatherATATenv_macro(final TeXParser tp, final String[] args) throws ParseException { + ArrayOfAtoms array = new ArrayOfAtoms(); + TeXParser parser = new TeXParser(tp.getIsPartial(), args[1], array, false); + parser.parse(); + array.checkDimensions(); + if (array.col > 1) { + throw new ParseException("Character '&' is only available in array mode !"); + } + if (array.col == 0) { + return null; + } + + return new MultlineAtom(tp.getIsPartial(), array, MultlineAtom.GATHER); + } + + public static final Atom gatheredATATenv_macro(final TeXParser tp, final String[] args) throws ParseException { + ArrayOfAtoms array = new ArrayOfAtoms(); + TeXParser parser = new TeXParser(tp.getIsPartial(), args[1], array, false); + parser.parse(); + array.checkDimensions(); + if (array.col > 1) { + throw new ParseException("Character '&' is only available in array mode !"); + } + if (array.col == 0) { + return null; + } + + return new MultlineAtom(tp.getIsPartial(), array, MultlineAtom.GATHERED); + } + + public static final Atom shoveright_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1]).root; + at.alignment = TeXConstants.ALIGN_RIGHT; + return at; + } + + public static final Atom shoveleft_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1]).root; + at.alignment = TeXConstants.ALIGN_LEFT; + return at; + } + + public static final Atom newcommand_macro(final TeXParser tp, final String[] args) throws ParseException { + String newcom = args[1]; + Integer nbArgs; + if (!tp.isValidName(newcom)) { + throw new ParseException("Invalid name for the command :" + newcom); + } + + if (args[3] == null) + nbArgs = new Integer(0); + else + nbArgs = Integer.parseInt(args[3]); + + if (nbArgs == null) { + throw new ParseException("The optional argument should be an integer !"); + } + + if (args[4] == null) + NewCommandMacro.addNewCommand(newcom.substring(1), args[2], nbArgs.intValue()); + else + NewCommandMacro.addNewCommand(newcom.substring(1), args[2], nbArgs.intValue(), args[4]); + + return null; + } + + public static final Atom renewcommand_macro(final TeXParser tp, final String[] args) throws ParseException { + String newcom = args[1]; + Integer nbArgs; + if (!tp.isValidName(newcom)) { + throw new ParseException("Invalid name for the command :" + newcom); + } + + if (args[3] == null) + nbArgs = new Integer(0); + else + nbArgs = Integer.parseInt(args[3]); + + if (nbArgs == null) + throw new ParseException("The optional argument should be an integer !"); + + NewCommandMacro.addReNewCommand(newcom.substring(1), args[2], nbArgs.intValue()); + + return null; + } + + public static final Atom makeatletter_macro(final TeXParser tp, final String[] args) throws ParseException { + tp.makeAtLetter(); + return null; + } + + public static final Atom makeatother_macro(final TeXParser tp, final String[] args) throws ParseException { + tp.makeAtOther(); + return null; + } + + public static final Atom newenvironment_macro(final TeXParser tp, final String[] args) throws ParseException { + Integer opt = args[4] == null ? 0 : Integer.parseInt(args[4]); + if (opt == null) + throw new ParseException("The optional argument should be an integer !"); + + NewEnvironmentMacro.addNewEnvironment(args[1], args[2], args[3], opt.intValue()); + return null; + } + + public static final Atom renewenvironment_macro(final TeXParser tp, final String[] args) throws ParseException { + Integer opt = args[4] == null ? 0 : Integer.parseInt(args[4]); + if (opt == null) + throw new ParseException("The optional argument should be an integer !"); + + NewEnvironmentMacro.addReNewEnvironment(args[1], args[2], args[3], opt.intValue()); + return null; + } + + public static final Atom fbox_macro(final TeXParser tp, final String[] args) throws ParseException { + return new FBoxAtom(new TeXFormula(tp, args[1], false).root); + } + + public static final Atom questeq_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new UnderOverAtom(SymbolAtom.get(TeXFormula.symbolMappings['=']), new ScaleAtom(SymbolAtom.get(TeXFormula.symbolMappings['?']), 0.75f), TeXConstants.UNIT_MU, 2.5f, true, true); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom stackrel_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new UnderOverAtom(new TeXFormula(tp, args[2], false).root, new TeXFormula(tp, args[3], false).root, TeXConstants.UNIT_MU, 0.5f, true, new TeXFormula(tp, args[1], false).root, TeXConstants.UNIT_MU, 2.5f, true); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom stackbin_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new UnderOverAtom(new TeXFormula(tp, args[2], false).root, new TeXFormula(tp, args[3], false).root, TeXConstants.UNIT_MU, 0.5f, true, new TeXFormula(tp, args[1], false).root, TeXConstants.UNIT_MU, 2.5f, true); + return new TypedAtom(TeXConstants.TYPE_BINARY_OPERATOR, TeXConstants.TYPE_BINARY_OPERATOR, at); + } + + public static final Atom overset_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new UnderOverAtom(new TeXFormula(tp, args[2], false).root, new TeXFormula(tp, args[1], false).root, TeXConstants.UNIT_MU, 2.5f, true, true); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom underset_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new UnderOverAtom(new TeXFormula(tp, args[2], false).root, new TeXFormula(tp, args[1], false).root, TeXConstants.UNIT_MU, 0.5f, true, false); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom accentset_macro(final TeXParser tp, final String[] args) throws ParseException { + return new AccentedAtom(new TeXFormula(tp, args[2], false).root, new TeXFormula(tp, args[1], false).root); + } + + public static final Atom underaccent_macro(final TeXParser tp, final String[] args) throws ParseException { + return new UnderOverAtom(new TeXFormula(tp, args[2], false).root, new TeXFormula(tp, args[1], false).root, TeXConstants.UNIT_MU, 0.3f, true, false); + } + + public static final Atom undertilde_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1], false).root; + return new UnderOverAtom(at, new AccentedAtom(new PhantomAtom(at, true, false, false), "widetilde"), TeXConstants.UNIT_MU, 0.3f, true, false); + } + + public static final Atom boldsymbol_macro(final TeXParser tp, final String[] args) throws ParseException { + return new BoldAtom(new TeXFormula(tp, args[1], false).root); + } + + public static final Atom mathrm_macro(final TeXParser tp, final String[] args) throws ParseException { + return new RomanAtom(new TeXFormula(tp, args[1], false).root); + } + + public static final Atom rm_macro(final TeXParser tp, final String[] args) throws ParseException { + return new RomanAtom(new TeXFormula(tp, tp.getOverArgument(), null, false, tp.isIgnoreWhiteSpace()).root); + } + + public static final Atom mathbf_macro(final TeXParser tp, final String[] args) throws ParseException { + return new BoldAtom(new RomanAtom(new TeXFormula(tp, args[1], false).root)); + } + + public static final Atom bf_macro(final TeXParser tp, final String[] args) throws ParseException { + return new BoldAtom(new RomanAtom(new TeXFormula(tp, tp.getOverArgument(), null, false, tp.isIgnoreWhiteSpace()).root)); + } + + public static final Atom mathtt_macro(final TeXParser tp, final String[] args) throws ParseException { + return new TtAtom(new TeXFormula(tp, args[1], false).root); + } + + public static final Atom tt_macro(final TeXParser tp, final String[] args) throws ParseException { + return new TtAtom(new TeXFormula(tp, tp.getOverArgument(), null, false, tp.isIgnoreWhiteSpace()).root); + } + + public static final Atom mathit_macro(final TeXParser tp, final String[] args) throws ParseException { + return new ItAtom(new TeXFormula(tp, args[1], false).root); + } + + public static final Atom it_macro(final TeXParser tp, final String[] args) throws ParseException { + return new ItAtom(new TeXFormula(tp, tp.getOverArgument(), null, false, tp.isIgnoreWhiteSpace()).root); + } + + public static final Atom mathsf_macro(final TeXParser tp, final String[] args) throws ParseException { + return new SsAtom(new TeXFormula(tp, args[1], false).root); + } + + public static final Atom sf_macro(final TeXParser tp, final String[] args) throws ParseException { + return new SsAtom(new TeXFormula(tp, tp.getOverArgument(), null, false, tp.isIgnoreWhiteSpace()).root); + } + + public static final Atom LaTeX_macro(final TeXParser tp, final String[] args) throws ParseException { + return new LaTeXAtom(); + } + + public static final Atom GeoGebra_macro(final TeXParser tp, final String[] args) throws ParseException { + TeXFormula tf = new TeXFormula("\\mathbb{G}\\mathsf{e}"); + tf.add(new GeoGebraLogoAtom()); + tf.add("\\mathsf{Gebra}"); + return new ColorAtom(tf.root, null, new Color(102, 102, 102)); + } + + public static final Atom hphantom_macro(final TeXParser tp, final String[] args) throws ParseException { + return new PhantomAtom(new TeXFormula(tp, args[1], false).root, true, false, false); + } + + public static final Atom vphantom_macro(final TeXParser tp, final String[] args) throws ParseException { + return new PhantomAtom(new TeXFormula(tp, args[1], false).root, false, true, true); + } + + public static final Atom phantom_macro(final TeXParser tp, final String[] args) throws ParseException { + return new PhantomAtom(new TeXFormula(tp, args[1], false).root, true, true, true); + } + + public static final Atom big_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1], false).root; + if (!(at instanceof SymbolAtom)) { + return at; + } + return new BigDelimiterAtom((SymbolAtom) at, 1); + } + + public static final Atom Big_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1], false).root; + if (!(at instanceof SymbolAtom)) { + return at; + } + return new BigDelimiterAtom((SymbolAtom) at, 2); + } + + public static final Atom bigg_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1], false).root; + if (!(at instanceof SymbolAtom)) { + return at; + } + return new BigDelimiterAtom((SymbolAtom) at, 3); + } + + public static final Atom Bigg_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1], false).root; + if (!(at instanceof SymbolAtom)) { + return at; + } + return new BigDelimiterAtom((SymbolAtom) at, 4); + } + + public static final Atom bigl_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1], false).root; + if (!(at instanceof SymbolAtom)) { + return at; + } + Atom att = new BigDelimiterAtom((SymbolAtom) at, 1); + att.type = TeXConstants.TYPE_OPENING; + return att; + } + + public static final Atom Bigl_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1], false).root; + if (!(at instanceof SymbolAtom)) { + return at; + } + Atom att = new BigDelimiterAtom((SymbolAtom) at, 2); + att.type = TeXConstants.TYPE_OPENING; + return att; + } + + public static final Atom biggl_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1], false).root; + if (!(at instanceof SymbolAtom)) { + return at; + } + Atom att = new BigDelimiterAtom((SymbolAtom) at, 3); + att.type = TeXConstants.TYPE_OPENING; + return att; + } + + public static final Atom Biggl_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1], false).root; + if (!(at instanceof SymbolAtom)) { + return at; + } + Atom att = new BigDelimiterAtom((SymbolAtom) at, 4); + att.type = TeXConstants.TYPE_OPENING; + return att; + } + + public static final Atom bigr_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1], false).root; + if (!(at instanceof SymbolAtom)) { + return at; + } + Atom att = new BigDelimiterAtom((SymbolAtom) at, 1); + att.type = TeXConstants.TYPE_CLOSING; + return att; + } + + public static final Atom Bigr_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1], false).root; + if (!(at instanceof SymbolAtom)) { + return at; + } + Atom att = new BigDelimiterAtom((SymbolAtom) at, 2); + att.type = TeXConstants.TYPE_CLOSING; + return att; + } + + public static final Atom biggr_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1], false).root; + if (!(at instanceof SymbolAtom)) { + return at; + } + Atom att = new BigDelimiterAtom((SymbolAtom) at, 3); + att.type = TeXConstants.TYPE_CLOSING; + return att; + } + + public static final Atom Biggr_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new TeXFormula(tp, args[1], false).root; + if (!(at instanceof SymbolAtom)) { + return at; + } + Atom att = new BigDelimiterAtom((SymbolAtom) at, 4); + att.type = TeXConstants.TYPE_CLOSING; + return att; + } + + public static final Atom displaystyle_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom group = new TeXFormula(tp, tp.getOverArgument(), false).root; + return new StyleAtom(TeXConstants.STYLE_DISPLAY, group); + } + + public static final Atom scriptstyle_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom group = new TeXFormula(tp, tp.getOverArgument(), false).root; + return new StyleAtom(TeXConstants.STYLE_SCRIPT, group); + } + + public static final Atom textstyle_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom group = new TeXFormula(tp, tp.getOverArgument(), false).root; + return new StyleAtom(TeXConstants.STYLE_TEXT, group); + } + + public static final Atom scriptscriptstyle_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom group = new TeXFormula(tp, tp.getOverArgument(), false).root; + return new StyleAtom(TeXConstants.STYLE_SCRIPT_SCRIPT, group); + } + + public static final Atom rotatebox_macro(final TeXParser tp, final String[] args) throws ParseException { + return new RotateAtom(new TeXFormula(tp, args[2]).root, args[1] == null ? 0 : Double.parseDouble(args[1]), args[3]); + } + + public static final Atom reflectbox_macro(final TeXParser tp, final String[] args) throws ParseException { + return new ReflectAtom(new TeXFormula(tp, args[1]).root); + } + + public static final Atom scalebox_macro(final TeXParser tp, final String[] args) throws ParseException { + return new ScaleAtom(new TeXFormula(tp, args[2]).root, Double.parseDouble(args[1]), args[3] == null ? Double.parseDouble(args[1]) : Double.parseDouble(args[3])); + } + + public static final Atom resizebox_macro(final TeXParser tp, final String[] args) throws ParseException { + return new ResizeAtom(new TeXFormula(tp, args[3]).root, args[1], args[2], args[1].equals("!") || args[2].equals("!")); + } + + public static final Atom raisebox_macro(final TeXParser tp, final String[] args) throws ParseException { + float[] raise = SpaceAtom.getLength(args[1]); + if (raise.length == 1) { + throw new ParseException("Error in getting raise in \\raisebox command !"); + } + float[] height = SpaceAtom.getLength(args[3]); + float[] depth = SpaceAtom.getLength(args[4]); + if (height.length == 1 || height[1] == 0) { + height = new float[]{-1, 0}; + } + if (depth.length == 1 || depth[1] == 0) { + depth = new float[]{-1, 0}; + } + + return new RaiseAtom(new TeXFormula(tp, args[2]).root, (int) raise[0], raise[1], (int) height[0], height[1], (int) depth[0], depth[1]); + } + + public static final Atom shadowbox_macro(final TeXParser tp, final String[] args) throws ParseException { + return new ShadowAtom(new TeXFormula(tp, args[1]).root); + } + + public static final Atom ovalbox_macro(final TeXParser tp, final String[] args) throws ParseException { + return new OvalAtom(new TeXFormula(tp, args[1]).root); + } + + public static final Atom doublebox_macro(final TeXParser tp, final String[] args) throws ParseException { + return new DoubleFramedAtom(new TeXFormula(tp, args[1]).root); + } + + public static final Atom definecolor_macro(final TeXParser tp, final String[] args) throws ParseException { + Color color = null; + if ("gray".equals(args[2])) { + float f = Float.parseFloat(args[3]); + color = new Color(f, f, f); + } else if ("rgb".equals(args[2])) { + StringTokenizer stok = new StringTokenizer(args[3], ";,"); + if (stok.countTokens() != 3) + throw new ParseException("The color definition must have three components !"); + float r = Float.parseFloat(stok.nextToken().trim()); + float g = Float.parseFloat(stok.nextToken().trim()); + float b = Float.parseFloat(stok.nextToken().trim()); + color = new Color(r, g, b); + } else if ("cmyk".equals(args[2])) { + StringTokenizer stok = new StringTokenizer(args[3], ",;"); + if (stok.countTokens() != 4) + throw new ParseException("The color definition must have four components !"); + float[] cmyk = new float[4]; + for (int i = 0; i < 4; i++) + cmyk[i] = Float.parseFloat(stok.nextToken().trim()); + float k = 1 - cmyk[3]; + color = new Color(k * (1 - cmyk[0]), k * (1 - cmyk[1]), k * (1 - cmyk[2])); + } else + throw new ParseException("The color model is incorrect !"); + + ColorAtom.Colors.put(args[1], color); + return null; + } + + public static final Atom fgcolor_macro(final TeXParser tp, final String[] args) throws ParseException { + try { + return new ColorAtom(new TeXFormula(tp, args[2]).root, null, ColorAtom.getColor(args[1])); + } catch (NumberFormatException e) { + throw new ParseException(e.toString()); + } + } + + public static final Atom bgcolor_macro(final TeXParser tp, final String[] args) throws ParseException { + try { + return new ColorAtom(new TeXFormula(tp, args[2]).root, ColorAtom.getColor(args[1]), null); + } catch (NumberFormatException e) { + throw new ParseException(e.toString()); + } + } + + public static final Atom textcolor_macro(final TeXParser tp, final String[] args) throws ParseException { + return new ColorAtom(new TeXFormula(tp, args[2]).root, null, ColorAtom.getColor(args[1])); + } + + public static final Atom colorbox_macro(final TeXParser tp, final String[] args) throws ParseException { + Color c = ColorAtom.getColor(args[1]); + return new FBoxAtom(new TeXFormula(tp, args[2]).root, c, c); + } + + public static final Atom fcolorbox_macro(final TeXParser tp, final String[] args) throws ParseException { + return new FBoxAtom(new TeXFormula(tp, args[3]).root, ColorAtom.getColor(args[2]), ColorAtom.getColor(args[1])); + } + + public static final Atom cong_macro(final TeXParser tp, final String[] args) throws ParseException { + VRowAtom vra = new VRowAtom(SymbolAtom.get("equals")); + vra.add(new SpaceAtom(TeXConstants.UNIT_MU, 0f, 1.5f, 0f)); + vra.add(SymbolAtom.get("sim")); + vra.setRaise(TeXConstants.UNIT_MU, -1f); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, vra); + } + + public static final Atom doteq_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new UnderOverAtom(SymbolAtom.get("equals"), SymbolAtom.get("ldotp"), TeXConstants.UNIT_MU, 3.7f, false, true); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom jlmDynamic_macro(final TeXParser tp, final String[] args) throws ParseException { + if (DynamicAtom.hasAnExternalConverterFactory()) { + return new DynamicAtom(args[1], args[2]); + } else { + throw new ParseException("No ExternalConverterFactory set !"); + } + } + + public static final Atom jlmExternalFont_macro(final TeXParser tp, final String[] args) throws ParseException { + JavaFontRenderingBox.setFont(args[1]); + return null; + } + + public static final Atom jlmText_macro(final TeXParser tp, final String[] args) throws ParseException { + return new JavaFontRenderingAtom(args[1], Font.PLAIN); + } + + public static final Atom jlmTextit_macro(final TeXParser tp, final String[] args) throws ParseException { + return new JavaFontRenderingAtom(args[1], Font.ITALIC); + } + + public static final Atom jlmTextbf_macro(final TeXParser tp, final String[] args) throws ParseException { + return new JavaFontRenderingAtom(args[1], Font.BOLD); + } + + public static final Atom jlmTextitbf_macro(final TeXParser tp, final String[] args) throws ParseException { + return new JavaFontRenderingAtom(args[1], Font.BOLD | Font.ITALIC); + } + + public static final Atom DeclareMathSizes_macro(final TeXParser tp, final String[] args) throws ParseException { + DefaultTeXFont.setMathSizes(Float.parseFloat(args[1]), Float.parseFloat(args[2]), Float.parseFloat(args[3]), Float.parseFloat(args[4])); + return null; + } + + public static final Atom magnification_macro(final TeXParser tp, final String[] args) throws ParseException { + DefaultTeXFont.setMagnification(Float.parseFloat(args[1])); + return null; + } + + public static final Atom hline_macro(final TeXParser tp, final String[] args) throws ParseException { + if (!tp.isArrayMode()) + throw new ParseException("The macro \\hline is only available in array mode !"); + return new HlineAtom(); + } + + public static final Atom size_macros(final TeXParser tp, final String[] args) throws ParseException { + float f = 1f; + if ("tiny".equals(args[0])) { + f = 0.5f; + } else if ("scriptsize".equals(args[0])) { + f = 0.7f; + } else if ("footnotesize".equals(args[0])) { + f = 0.8f; + } else if ("small".equals(args[0])) { + f = 0.9f; + } else if ("normalsize".equals(args[0])) { + f = 1f; + } else if ("large".equals(args[0])) { + f = 1.2f; + } else if ("Large".equals(args[0])) { + f = 1.4f; + } else if ("LARGE".equals(args[0])) { + f = 1.8f; + } else if ("huge".equals(args[0])) { + f = 2f; + } else if ("Huge".equals(args[0])) { + f = 2.5f; + } + + return new MonoScaleAtom(new TeXFormula(tp, tp.getOverArgument(), null, false, tp.isIgnoreWhiteSpace()).root, f); + } + + public static final Atom jlatexmathcumsup_macro(final TeXParser tp, final String[] args) throws ParseException { + return new CumulativeScriptsAtom(tp.getLastAtom(), null, new TeXFormula(tp, args[1]).root); + } + + public static final Atom jlatexmathcumsub_macro(final TeXParser tp, final String[] args) throws ParseException { + return new CumulativeScriptsAtom(tp.getLastAtom(), new TeXFormula(tp, args[1]).root, null); + } + + public static final Atom dotminus_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new UnderOverAtom(SymbolAtom.get("minus"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, -3.3f, false, true); + return new TypedAtom(TeXConstants.TYPE_BINARY_OPERATOR, TeXConstants.TYPE_BINARY_OPERATOR, at); + } + + public static final Atom ratio_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom geoprop_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom ddot = new RowAtom(SymbolAtom.get("normaldot")); + ddot.add(new SpaceAtom(TeXConstants.UNIT_MU, 4f, 0f, 0f)); + ddot.add(SymbolAtom.get("normaldot")); + Atom at = new UnderOverAtom(SymbolAtom.get("minus"), ddot, TeXConstants.UNIT_MU, -3.4f, false, ddot, TeXConstants.UNIT_MU, -3.4f, false); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom minuscolon_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom at = new RowAtom(SymbolAtom.get("minus")); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.095f, 0f, 0f)); + at.add(new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true)); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom minuscoloncolon_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom at = new RowAtom(SymbolAtom.get("minus")); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.095f, 0f, 0f)); + Atom colon = new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true); + at.add(colon); + at.add(colon); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom simcolon_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom at = new RowAtom(SymbolAtom.get("sim")); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.095f, 0f, 0f)); + at.add(new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true)); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom simcoloncolon_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom at = new RowAtom(SymbolAtom.get("sim")); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.095f, 0f, 0f)); + Atom colon = new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true); + at.add(colon); + at.add(colon); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom approxcolon_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom at = new RowAtom(SymbolAtom.get("approx")); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.095f, 0f, 0f)); + at.add(new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true)); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom approxcoloncolon_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom at = new RowAtom(SymbolAtom.get("approx")); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.095f, 0f, 0f)); + Atom colon = new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true); + at.add(colon); + at.add(colon); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom equalscolon_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom at = new RowAtom(SymbolAtom.get("equals")); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.095f, 0f, 0f)); + at.add(new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true)); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom equalscoloncolon_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom at = new RowAtom(SymbolAtom.get("equals")); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.095f, 0f, 0f)); + Atom colon = new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true); + at.add(colon); + at.add(colon); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom colonminus_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom at = new RowAtom(new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true)); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.32f, 0f, 0f)); + at.add(SymbolAtom.get("minus")); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom coloncolonminus_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom colon = new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true); + RowAtom at = new RowAtom(colon); + at.add(colon); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.32f, 0f, 0f)); + at.add(SymbolAtom.get("minus")); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom colonequals_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom at = new RowAtom(new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true)); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.32f, 0f, 0f)); + at.add(SymbolAtom.get("equals")); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom coloncolonequals_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom colon = new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true); + RowAtom at = new RowAtom(colon); + at.add(colon); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.32f, 0f, 0f)); + at.add(SymbolAtom.get("equals")); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom coloncolon_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom colon = new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true); + RowAtom at = new RowAtom(colon); + at.add(colon); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom colonsim_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom at = new RowAtom(new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true)); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.32f, 0f, 0f)); + at.add(SymbolAtom.get("sim")); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom coloncolonsim_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom colon = new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true); + RowAtom at = new RowAtom(colon); + at.add(colon); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.32f, 0f, 0f)); + at.add(SymbolAtom.get("sim")); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom colonapprox_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom at = new RowAtom(new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true)); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.32f, 0f, 0f)); + at.add(SymbolAtom.get("approx")); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom coloncolonapprox_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom colon = new UnderOverAtom(SymbolAtom.get("normaldot"), SymbolAtom.get("normaldot"), TeXConstants.UNIT_MU, 5.2f, false, true); + RowAtom at = new RowAtom(colon); + at.add(colon); + at.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.32f, 0f, 0f)); + at.add(SymbolAtom.get("approx")); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom smallfrowneq_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new UnderOverAtom(SymbolAtom.get("equals"), SymbolAtom.get("smallfrown"), TeXConstants.UNIT_MU, -2f, true, true); + return new TypedAtom(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_RELATION, at); + } + + public static final Atom hstrok_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom ra = new RowAtom(new SpaceAtom(TeXConstants.UNIT_EX, -0.1f, 0f, 0f)); + ra.add(SymbolAtom.get("bar")); + VRowAtom vra = new VRowAtom(new LapedAtom(ra, 'r')); + vra.setRaise(TeXConstants.UNIT_EX, -0.1f); + RowAtom at = new RowAtom(vra); + at.add(new RomanAtom(new CharAtom('h', tp.formula.textStyle))); + return at; + } + + public static final Atom Hstrok_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom ra = new RowAtom(new SpaceAtom(TeXConstants.UNIT_EX, 0.28f, 0f, 0f)); + ra.add(SymbolAtom.get("textendash")); + VRowAtom vra = new VRowAtom(new LapedAtom(ra, 'r')); + vra.setRaise(TeXConstants.UNIT_EX, 0.55f); + RowAtom at = new RowAtom(vra); + at.add(new RomanAtom(new CharAtom('H', tp.formula.textStyle))); + return at; + } + + public static final Atom dstrok_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom ra = new RowAtom(new SpaceAtom(TeXConstants.UNIT_EX, 0.25f, 0f, 0f)); + ra.add(SymbolAtom.get("bar")); + VRowAtom vra = new VRowAtom(new LapedAtom(ra, 'r')); + vra.setRaise(TeXConstants.UNIT_EX, -0.1f); + RowAtom at = new RowAtom(vra); + at.add(new RomanAtom(new CharAtom('d', tp.formula.textStyle))); + return at; + } + + public static final Atom Dstrok_macro(final TeXParser tp, final String[] args) throws ParseException { + RowAtom ra = new RowAtom(new SpaceAtom(TeXConstants.UNIT_EX, -0.1f, 0f, 0f)); + ra.add(SymbolAtom.get("bar")); + VRowAtom vra = new VRowAtom(new LapedAtom(ra, 'r')); + vra.setRaise(TeXConstants.UNIT_EX, -0.55f); + RowAtom at = new RowAtom(vra); + at.add(new RomanAtom(new CharAtom('D', tp.formula.textStyle))); + return at; + } + + public static final Atom kern_macro(final TeXParser tp, final String[] args) throws ParseException { + float[] info = SpaceAtom.getLength(args[1]); + if (info.length == 1) { + throw new ParseException("Error in getting kern in \\kern command !"); + } + + return new SpaceAtom((int) info[0], info[1], 0f, 0f); + } + + public static final Atom char_macro(final TeXParser tp, final String[] args) throws ParseException { + String number = args[1]; + int radix = 10; + if (number.startsWith("0x") || number.startsWith("0X")) { + number = number.substring(2); + radix = 16; + } else if (number.startsWith("x") || number.startsWith("X")) { + number = number.substring(1); + radix = 16; + } else if (number.startsWith("0")) { + number = number.substring(1); + radix = 8; + } + int n = Integer.parseInt(number, radix); + return tp.convertCharacter((char) n, true); + } + + public static final Atom T_macro(final TeXParser tp, final String[] args) throws ParseException { + return new RotateAtom(new TeXFormula(tp, args[1]).root, 180, "origin=cc"); + } + + public static final Atom romannumeral_macro(final TeXParser tp, final String[] args) throws ParseException { + int[] numbers = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; + String[] letters = { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; + String roman = ""; + int num = Integer.parseInt(args[1].trim()); + for (int i = 0; i < numbers.length; i++) { + while (num >= numbers[i]) { + roman += letters[i]; + num -= numbers[i]; + } + } + + if (args[0].charAt(0) == 'r') { + roman = roman.toLowerCase(); + } + + return new TeXFormula(roman, false).root; + } + + public static final Atom textcircled_macro(final TeXParser tp, final String[] args) throws ParseException { + return new TextCircledAtom(new RomanAtom(new TeXFormula(tp, args[1]).root)); + } + + public static final Atom textsc_macro(final TeXParser tp, final String[] args) throws ParseException { + return new SmallCapAtom(new TeXFormula(tp, args[1], false).root); + } + + public static final Atom sc_macro(final TeXParser tp, final String[] args) throws ParseException { + return new SmallCapAtom(new TeXFormula(tp, tp.getOverArgument(), null, false, tp.isIgnoreWhiteSpace()).root); + } + + public static final Atom quad_macro(final TeXParser tp, final String[] args) throws ParseException { + return new SpaceAtom(TeXConstants.UNIT_EM, 1f, 0f, 0f); + } + + public static final Atom qquad_macro(final TeXParser tp, final String[] args) throws ParseException { + return new SpaceAtom(TeXConstants.UNIT_EM, 2f, 0f, 0f); + } + + public static final Atom muskip_macros(final TeXParser tp, final String[] args) throws ParseException { + int type = 0; + if (args[0].equals(",")) { + type = TeXConstants.THINMUSKIP; + } else if (args[0].equals(":")) { + type = TeXConstants.MEDMUSKIP; + } else if (args[0].equals(";")) { + type = TeXConstants.THICKMUSKIP; + } else if (args[0].equals("thinspace")) { + type = TeXConstants.THINMUSKIP; + } else if (args[0].equals("medspace")) { + type = TeXConstants.MEDMUSKIP; + } else if (args[0].equals("thickspace")) { + type = TeXConstants.THICKMUSKIP; + } else if (args[0].equals("!")) { + type = TeXConstants.NEGTHINMUSKIP; + } else if (args[0].equals("negthinspace")) { + type = TeXConstants.NEGTHINMUSKIP; + } else if (args[0].equals("negmedspace")) { + type = TeXConstants.NEGMEDMUSKIP; + } else if (args[0].equals("negthickspace")) { + type = TeXConstants.NEGTHICKMUSKIP; + } + + return new SpaceAtom(type); + } + + public static final Atom surd_macro(final TeXParser tp, final String[] args) throws ParseException { + return new VCenteredAtom(SymbolAtom.get("surdsign")); + } + + public static final Atom int_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom integral = SymbolAtom.get("int").clone(); + integral.type_limits = TeXConstants.SCRIPT_NOLIMITS; + return integral; + } + + public static final Atom oint_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom integral = SymbolAtom.get("oint").clone(); + integral.type_limits = TeXConstants.SCRIPT_NOLIMITS; + return integral; + } + + public static final Atom iint_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom integral = SymbolAtom.get("int").clone(); + integral.type_limits = TeXConstants.SCRIPT_NOLIMITS; + RowAtom ra = new RowAtom(integral); + ra.add(new SpaceAtom(TeXConstants.UNIT_MU, -6f, 0f, 0f)); + ra.add(integral); + ra.lookAtLastAtom = true; + return new TypedAtom(TeXConstants.TYPE_BIG_OPERATOR, TeXConstants.TYPE_BIG_OPERATOR, ra); + } + + public static final Atom iiint_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom integral = SymbolAtom.get("int").clone(); + integral.type_limits = TeXConstants.SCRIPT_NOLIMITS; + RowAtom ra = new RowAtom(integral); + ra.add(new SpaceAtom(TeXConstants.UNIT_MU, -6f, 0f, 0f)); + ra.add(integral); + ra.add(new SpaceAtom(TeXConstants.UNIT_MU, -6f, 0f, 0f)); + ra.add(integral); + ra.lookAtLastAtom = true; + return new TypedAtom(TeXConstants.TYPE_BIG_OPERATOR, TeXConstants.TYPE_BIG_OPERATOR, ra); + } + + public static final Atom iiiint_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom integral = SymbolAtom.get("int").clone(); + integral.type_limits = TeXConstants.SCRIPT_NOLIMITS; + RowAtom ra = new RowAtom(integral); + ra.add(new SpaceAtom(TeXConstants.UNIT_MU, -6f, 0f, 0f)); + ra.add(integral); + ra.add(new SpaceAtom(TeXConstants.UNIT_MU, -6f, 0f, 0f)); + ra.add(integral); + ra.add(new SpaceAtom(TeXConstants.UNIT_MU, -6f, 0f, 0f)); + ra.add(integral); + ra.lookAtLastAtom = true; + return new TypedAtom(TeXConstants.TYPE_BIG_OPERATOR, TeXConstants.TYPE_BIG_OPERATOR, ra); + } + + public static final Atom idotsint_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom integral = SymbolAtom.get("int").clone(); + integral.type_limits = TeXConstants.SCRIPT_NOLIMITS; + RowAtom ra = new RowAtom(integral); + ra.add(new SpaceAtom(TeXConstants.UNIT_MU, -1f, 0f, 0f)); + Atom cdotp = SymbolAtom.get("cdotp"); + RowAtom cdots = new RowAtom(cdotp); + cdots.add(cdotp); + cdots.add(cdotp); + ra.add(new TypedAtom(TeXConstants.TYPE_INNER, TeXConstants.TYPE_INNER, cdots)); + ra.add(new SpaceAtom(TeXConstants.UNIT_MU, -1f, 0f, 0f)); + ra.add(integral); + ra.lookAtLastAtom = true; + return new TypedAtom(TeXConstants.TYPE_BIG_OPERATOR, TeXConstants.TYPE_BIG_OPERATOR, ra); + } + + public static final Atom lmoustache_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new BigDelimiterAtom((SymbolAtom) SymbolAtom.get("lmoustache").clone(), 1); + at.type = TeXConstants.TYPE_OPENING; + return at; + } + + public static final Atom rmoustache_macro(final TeXParser tp, final String[] args) throws ParseException { + Atom at = new BigDelimiterAtom((SymbolAtom) SymbolAtom.get("rmoustache").clone(), 1); + at.type = TeXConstants.TYPE_CLOSING; + return at; + } + + public static final Atom insertBreakMark_macro(final TeXParser tp, final String[] args) throws ParseException { + return new BreakMarkAtom(); + } + + public static final Atom jlmXML_macro(final TeXParser tp, final String[] args) throws ParseException { + Map map = tp.formula.jlmXMLMap; + String str = args[1]; + StringBuffer buffer = new StringBuffer(); + int start = 0; + int pos; + while ((pos = str.indexOf("$")) != -1) { + if (pos < str.length() - 1) { + start = pos; + while (++start < str.length() && Character.isLetter(str.charAt(start))); + String key = str.substring(pos + 1, start); + String value = map.get(key); + if (value != null) { + buffer.append(str.substring(0, pos)); + buffer.append(value); + } else { + buffer.append(str.substring(0, start)); + } + str = str.substring(start); + } else { + buffer.append(str); + str = ""; + } + } + buffer.append(str); + str = buffer.toString(); + + return new TeXFormula(tp, str).root; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefinedCommands.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefinedCommands.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefinedCommands.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,338 @@ +/* PredefinedCommands.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2011 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +final class PredefinedCommands { + + PredefinedCommands() { } + + static { + MacroInfo.Commands.put("newcommand", new PredefMacroInfo(0, 2, 2)); + MacroInfo.Commands.put("renewcommand", new PredefMacroInfo(1, 2, 2)); + MacroInfo.Commands.put("rule", new PredefMacroInfo(2, 2, 1)); + MacroInfo.Commands.put("hspace", new PredefMacroInfo(3, 1)); + MacroInfo.Commands.put("vspace", new PredefMacroInfo(4, 1)); + MacroInfo.Commands.put("llap", new PredefMacroInfo(5, 1)); + MacroInfo.Commands.put("rlap", new PredefMacroInfo(6, 1)); + MacroInfo.Commands.put("clap", new PredefMacroInfo(7, 1)); + MacroInfo.Commands.put("mathllap", new PredefMacroInfo(8, 1)); + MacroInfo.Commands.put("mathrlap", new PredefMacroInfo(9, 1)); + MacroInfo.Commands.put("mathclap", new PredefMacroInfo(10, 1)); + MacroInfo.Commands.put("includegraphics", new PredefMacroInfo(11, 1, 1)); + MacroInfo.Commands.put("cfrac", new PredefMacroInfo(12, 2, 1)); + MacroInfo.Commands.put("frac", new PredefMacroInfo(13, 2)); + MacroInfo.Commands.put("sfrac", new PredefMacroInfo(14, 2)); + MacroInfo.Commands.put("genfrac", new PredefMacroInfo(15, 6)); + MacroInfo.Commands.put("over", new PredefMacroInfo(16, 0)); + MacroInfo.Commands.put("overwithdelims", new PredefMacroInfo(17, 2)); + MacroInfo.Commands.put("atop", new PredefMacroInfo(18, 0)); + MacroInfo.Commands.put("atopwithdelims", new PredefMacroInfo(19, 2)); + MacroInfo.Commands.put("choose", new PredefMacroInfo(20, 0)); + MacroInfo.Commands.put("underscore", new PredefMacroInfo(21, 0)); + MacroInfo.Commands.put("mbox", new PredefMacroInfo(22, 1)); + MacroInfo.Commands.put("text", new PredefMacroInfo(23, 1)); + MacroInfo.Commands.put("intertext", new PredefMacroInfo(24, 1)); + MacroInfo.Commands.put("binom", new PredefMacroInfo(25, 2)); + MacroInfo.Commands.put("mathbf", new PredefMacroInfo(26, 1)); + MacroInfo.Commands.put("bf", new PredefMacroInfo(27, 0)); + MacroInfo.Commands.put("mathbb", new PredefMacroInfo(28, 1)); + MacroInfo.Commands.put("mathcal", new PredefMacroInfo(29, 1)); + MacroInfo.Commands.put("cal", new PredefMacroInfo(30, 1)); + MacroInfo.Commands.put("mathit", new PredefMacroInfo(31, 1)); + MacroInfo.Commands.put("it", new PredefMacroInfo(32, 0)); + MacroInfo.Commands.put("mathrm", new PredefMacroInfo(33, 1)); + MacroInfo.Commands.put("rm", new PredefMacroInfo(34, 0)); + MacroInfo.Commands.put("mathscr", new PredefMacroInfo(35, 1)); + MacroInfo.Commands.put("mathsf", new PredefMacroInfo(36, 1)); + MacroInfo.Commands.put("sf", new PredefMacroInfo(37, 0)); + MacroInfo.Commands.put("mathtt", new PredefMacroInfo(38, 1)); + MacroInfo.Commands.put("tt", new PredefMacroInfo(39, 0)); + MacroInfo.Commands.put("mathfrak", new PredefMacroInfo(40, 1)); + MacroInfo.Commands.put("mathds", new PredefMacroInfo(41, 1)); + MacroInfo.Commands.put("frak", new PredefMacroInfo(42, 1)); + MacroInfo.Commands.put("Bbb", new PredefMacroInfo(43, 1)); + MacroInfo.Commands.put("oldstylenums", new PredefMacroInfo(44, 1)); + MacroInfo.Commands.put("bold", new PredefMacroInfo(45, 1)); + MacroInfo.Commands.put("^", new PredefMacroInfo(46, 1)); + MacroInfo.Commands.put("\'", new PredefMacroInfo(47, 1)); + MacroInfo.Commands.put("\"", new PredefMacroInfo(48, 1)); + MacroInfo.Commands.put("`", new PredefMacroInfo(49, 1)); + MacroInfo.Commands.put("=", new PredefMacroInfo(50, 1)); + MacroInfo.Commands.put(".", new PredefMacroInfo(51, 1)); + MacroInfo.Commands.put("~", new PredefMacroInfo(52, 1)); + MacroInfo.Commands.put("u", new PredefMacroInfo(53, 1)); + MacroInfo.Commands.put("v", new PredefMacroInfo(54, 1)); + MacroInfo.Commands.put("H", new PredefMacroInfo(55, 1)); + MacroInfo.Commands.put("r", new PredefMacroInfo(56, 1)); + MacroInfo.Commands.put("U", new PredefMacroInfo(57, 1)); + MacroInfo.Commands.put("T", new PredefMacroInfo(58, 1)); + MacroInfo.Commands.put("t", new PredefMacroInfo(59, 1)); + MacroInfo.Commands.put("accent", new PredefMacroInfo(60, 2)); + MacroInfo.Commands.put("grkaccent", new PredefMacroInfo(61, 2)); + MacroInfo.Commands.put("hat", new PredefMacroInfo(62, 1)); + MacroInfo.Commands.put("widehat", new PredefMacroInfo(63, 1)); + MacroInfo.Commands.put("tilde", new PredefMacroInfo(64, 1)); + MacroInfo.Commands.put("acute", new PredefMacroInfo(65, 1)); + MacroInfo.Commands.put("grave", new PredefMacroInfo(66, 1)); + MacroInfo.Commands.put("ddot", new PredefMacroInfo(67, 1)); + MacroInfo.Commands.put("cyrddot", new PredefMacroInfo(68, 1)); + MacroInfo.Commands.put("mathring", new PredefMacroInfo(69, 1)); + MacroInfo.Commands.put("bar", new PredefMacroInfo(70, 1)); + MacroInfo.Commands.put("breve", new PredefMacroInfo(71, 1)); + MacroInfo.Commands.put("check", new PredefMacroInfo(72, 1)); + MacroInfo.Commands.put("vec", new PredefMacroInfo(73, 1)); + MacroInfo.Commands.put("dot", new PredefMacroInfo(74, 1)); + MacroInfo.Commands.put("widetilde", new PredefMacroInfo(75, 1)); + MacroInfo.Commands.put("nbsp", new PredefMacroInfo(76, 0)); + MacroInfo.Commands.put("smallmatrix@@env", new PredefMacroInfo(77, 1)); + MacroInfo.Commands.put("matrix@@env", new PredefMacroInfo(78, 1)); + MacroInfo.Commands.put("overrightarrow", new PredefMacroInfo(79, 1)); + MacroInfo.Commands.put("overleftarrow", new PredefMacroInfo(80, 1)); + MacroInfo.Commands.put("overleftrightarrow", new PredefMacroInfo(81, 1)); + MacroInfo.Commands.put("underrightarrow", new PredefMacroInfo(82, 1)); + MacroInfo.Commands.put("underleftarrow", new PredefMacroInfo(83, 1)); + MacroInfo.Commands.put("underleftrightarrow", new PredefMacroInfo(84, 1)); + MacroInfo.Commands.put("xleftarrow", new PredefMacroInfo(85, 1, 1)); + MacroInfo.Commands.put("xrightarrow", new PredefMacroInfo(86, 1, 1)); + MacroInfo.Commands.put("underbrace", new PredefMacroInfo(87, 1)); + MacroInfo.Commands.put("overbrace", new PredefMacroInfo(88, 1)); + MacroInfo.Commands.put("underbrack", new PredefMacroInfo(89, 1)); + MacroInfo.Commands.put("overbrack", new PredefMacroInfo(90, 1)); + MacroInfo.Commands.put("underparen", new PredefMacroInfo(91, 1)); + MacroInfo.Commands.put("overparen", new PredefMacroInfo(92, 1)); + MacroInfo.Commands.put("sqrt", new PredefMacroInfo(93, 1, 1)); + MacroInfo.Commands.put("sqrtsign", new PredefMacroInfo(94, 1)); + MacroInfo.Commands.put("overline", new PredefMacroInfo(95, 1)); + MacroInfo.Commands.put("underline", new PredefMacroInfo(96, 1)); + MacroInfo.Commands.put("mathop", new PredefMacroInfo(97, 1)); + MacroInfo.Commands.put("mathpunct", new PredefMacroInfo(98, 1)); + MacroInfo.Commands.put("mathord", new PredefMacroInfo(99, 1)); + MacroInfo.Commands.put("mathrel", new PredefMacroInfo(100, 1)); + MacroInfo.Commands.put("mathinner", new PredefMacroInfo(101, 1)); + MacroInfo.Commands.put("mathbin", new PredefMacroInfo(102, 1)); + MacroInfo.Commands.put("mathopen", new PredefMacroInfo(103, 1)); + MacroInfo.Commands.put("mathclose", new PredefMacroInfo(104, 1)); + MacroInfo.Commands.put("joinrel", new PredefMacroInfo(105, 0)); + MacroInfo.Commands.put("smash", new PredefMacroInfo(106, 1, 1)); + MacroInfo.Commands.put("vdots", new PredefMacroInfo(107, 0)); + MacroInfo.Commands.put("ddots", new PredefMacroInfo(108, 0)); + MacroInfo.Commands.put("iddots", new PredefMacroInfo(109, 0)); + MacroInfo.Commands.put("nolimits", new PredefMacroInfo(110, 0)); + MacroInfo.Commands.put("limits", new PredefMacroInfo(111, 0)); + MacroInfo.Commands.put("normal", new PredefMacroInfo(112, 0)); + MacroInfo.Commands.put("(", new PredefMacroInfo(113, 0)); + MacroInfo.Commands.put("[", new PredefMacroInfo(114, 0)); + MacroInfo.Commands.put("left", new PredefMacroInfo(115, 1)); + MacroInfo.Commands.put("middle", new PredefMacroInfo(116, 1)); + MacroInfo.Commands.put("cr", new PredefMacroInfo(117, 0)); + MacroInfo.Commands.put("multicolumn", new PredefMacroInfo(118, 3)); + MacroInfo.Commands.put("hdotsfor", new PredefMacroInfo(119, 1, 1)); + MacroInfo.Commands.put("array@@env", new PredefMacroInfo(120, 2)); + MacroInfo.Commands.put("align@@env", new PredefMacroInfo(121, 2)); + MacroInfo.Commands.put("aligned@@env", new PredefMacroInfo(122, 2)); + MacroInfo.Commands.put("flalign@@env", new PredefMacroInfo(123, 2)); + MacroInfo.Commands.put("alignat@@env", new PredefMacroInfo(124, 2)); + MacroInfo.Commands.put("alignedat@@env", new PredefMacroInfo(125, 2)); + MacroInfo.Commands.put("multline@@env", new PredefMacroInfo(126, 2)); + MacroInfo.Commands.put("gather@@env", new PredefMacroInfo(127, 2)); + MacroInfo.Commands.put("gathered@@env", new PredefMacroInfo(128, 2)); + MacroInfo.Commands.put("shoveright", new PredefMacroInfo(129, 1)); + MacroInfo.Commands.put("shoveleft", new PredefMacroInfo(130, 1)); + MacroInfo.Commands.put("\\", new PredefMacroInfo(131, 0)); + MacroInfo.Commands.put("newenvironment", new PredefMacroInfo(132, 3)); + MacroInfo.Commands.put("renewenvironment", new PredefMacroInfo(133, 3)); + MacroInfo.Commands.put("makeatletter", new PredefMacroInfo(134, 0)); + MacroInfo.Commands.put("makeatother", new PredefMacroInfo(135, 0)); + MacroInfo.Commands.put("fbox", new PredefMacroInfo(136, 1)); + MacroInfo.Commands.put("boxed", new PredefMacroInfo(137, 1)); + MacroInfo.Commands.put("stackrel", new PredefMacroInfo(138, 2, 1)); + MacroInfo.Commands.put("stackbin", new PredefMacroInfo(139, 2, 1)); + MacroInfo.Commands.put("accentset", new PredefMacroInfo(140, 2)); + MacroInfo.Commands.put("underaccent", new PredefMacroInfo(141, 2)); + MacroInfo.Commands.put("undertilde", new PredefMacroInfo(142, 1)); + MacroInfo.Commands.put("overset", new PredefMacroInfo(143, 2)); + MacroInfo.Commands.put("Braket", new PredefMacroInfo(144, 1)); + MacroInfo.Commands.put("Set", new PredefMacroInfo(145, 1)); + MacroInfo.Commands.put("underset", new PredefMacroInfo(146, 2)); + MacroInfo.Commands.put("boldsymbol", new PredefMacroInfo(147, 1)); + MacroInfo.Commands.put("LaTeX", new PredefMacroInfo(148, 0)); + MacroInfo.Commands.put("GeoGebra", new PredefMacroInfo(149, 0)); + MacroInfo.Commands.put("big", new PredefMacroInfo(150, 1)); + MacroInfo.Commands.put("Big", new PredefMacroInfo(151, 1)); + MacroInfo.Commands.put("bigg", new PredefMacroInfo(152, 1)); + MacroInfo.Commands.put("Bigg", new PredefMacroInfo(153, 1)); + MacroInfo.Commands.put("bigl", new PredefMacroInfo(154, 1)); + MacroInfo.Commands.put("Bigl", new PredefMacroInfo(155, 1)); + MacroInfo.Commands.put("biggl", new PredefMacroInfo(156, 1)); + MacroInfo.Commands.put("Biggl", new PredefMacroInfo(157, 1)); + MacroInfo.Commands.put("bigr", new PredefMacroInfo(158, 1)); + MacroInfo.Commands.put("Bigr", new PredefMacroInfo(159, 1)); + MacroInfo.Commands.put("biggr", new PredefMacroInfo(160, 1)); + MacroInfo.Commands.put("Biggr", new PredefMacroInfo(161, 1)); + MacroInfo.Commands.put("displaystyle", new PredefMacroInfo(162, 0)); + MacroInfo.Commands.put("textstyle", new PredefMacroInfo(163, 0)); + MacroInfo.Commands.put("scriptstyle", new PredefMacroInfo(164, 0)); + MacroInfo.Commands.put("scriptscriptstyle", new PredefMacroInfo(165, 0)); + MacroInfo.Commands.put("sideset", new PredefMacroInfo(166, 3)); + MacroInfo.Commands.put("prescript", new PredefMacroInfo(167, 3)); + MacroInfo.Commands.put("rotatebox", new PredefMacroInfo(168, 2, 1)); + MacroInfo.Commands.put("reflectbox", new PredefMacroInfo(169, 1)); + MacroInfo.Commands.put("scalebox", new PredefMacroInfo(170, 2, 2)); + MacroInfo.Commands.put("resizebox", new PredefMacroInfo(171, 3)); + MacroInfo.Commands.put("raisebox", new PredefMacroInfo(172, 2, 2)); + MacroInfo.Commands.put("shadowbox", new PredefMacroInfo(173, 1)); + MacroInfo.Commands.put("ovalbox", new PredefMacroInfo(174, 1)); + MacroInfo.Commands.put("doublebox", new PredefMacroInfo(175, 1)); + MacroInfo.Commands.put("phantom", new PredefMacroInfo(176, 1)); + MacroInfo.Commands.put("hphantom", new PredefMacroInfo(177, 1)); + MacroInfo.Commands.put("vphantom", new PredefMacroInfo(178, 1)); + MacroInfo.Commands.put("sp@breve", new PredefMacroInfo(179, 0)); + MacroInfo.Commands.put("sp@hat", new PredefMacroInfo(180, 0)); + MacroInfo.Commands.put("definecolor", new PredefMacroInfo(181, 3)); + MacroInfo.Commands.put("textcolor", new PredefMacroInfo(182, 2)); + MacroInfo.Commands.put("fgcolor", new PredefMacroInfo(183, 2)); + MacroInfo.Commands.put("bgcolor", new PredefMacroInfo(184, 2)); + MacroInfo.Commands.put("colorbox", new PredefMacroInfo(185, 2)); + MacroInfo.Commands.put("fcolorbox", new PredefMacroInfo(186, 3)); + MacroInfo.Commands.put("c", new PredefMacroInfo(187, 1)); + MacroInfo.Commands.put("IJ", new PredefMacroInfo(188, 0)); + MacroInfo.Commands.put("ij", new PredefMacroInfo(189, 0)); + MacroInfo.Commands.put("TStroke", new PredefMacroInfo(190, 0)); + MacroInfo.Commands.put("tStroke", new PredefMacroInfo(191, 0)); + MacroInfo.Commands.put("Lcaron", new PredefMacroInfo(192, 0)); + MacroInfo.Commands.put("tcaron", new PredefMacroInfo(193, 0)); + MacroInfo.Commands.put("lcaron", new PredefMacroInfo(194, 0)); + MacroInfo.Commands.put("k", new PredefMacroInfo(195, 1)); + MacroInfo.Commands.put("cong", new PredefMacroInfo(196, 0)); + MacroInfo.Commands.put("doteq", new PredefMacroInfo(197, 0)); + MacroInfo.Commands.put("jlmDynamic", new PredefMacroInfo(198, 1, 1)); + MacroInfo.Commands.put("jlmExternalFont", new PredefMacroInfo(199, 1)); + MacroInfo.Commands.put("jlmText", new PredefMacroInfo(200, 1)); + MacroInfo.Commands.put("jlmTextit", new PredefMacroInfo(201, 1)); + MacroInfo.Commands.put("jlmTextbf", new PredefMacroInfo(202, 1)); + MacroInfo.Commands.put("jlmTextitbf", new PredefMacroInfo(203, 1)); + MacroInfo.Commands.put("DeclareMathSizes", new PredefMacroInfo(204, 4)); + MacroInfo.Commands.put("magnification", new PredefMacroInfo(205, 1)); + MacroInfo.Commands.put("hline", new PredefMacroInfo(206, 0)); + MacroInfo.Commands.put("tiny", new PredefMacroInfo(207, 0)); + MacroInfo.Commands.put("scriptsize", new PredefMacroInfo(208, 0)); + MacroInfo.Commands.put("footnotesize", new PredefMacroInfo(209, 0)); + MacroInfo.Commands.put("small", new PredefMacroInfo(210, 0)); + MacroInfo.Commands.put("normalsize", new PredefMacroInfo(211, 0)); + MacroInfo.Commands.put("large", new PredefMacroInfo(212, 0)); + MacroInfo.Commands.put("Large", new PredefMacroInfo(213, 0)); + MacroInfo.Commands.put("LARGE", new PredefMacroInfo(214, 0)); + MacroInfo.Commands.put("huge", new PredefMacroInfo(215, 0)); + MacroInfo.Commands.put("Huge", new PredefMacroInfo(216, 0)); + MacroInfo.Commands.put("jlatexmathcumsup", new PredefMacroInfo(217, 1)); + MacroInfo.Commands.put("jlatexmathcumsub", new PredefMacroInfo(218, 1)); + MacroInfo.Commands.put("hstrok", new PredefMacroInfo(219, 0)); + MacroInfo.Commands.put("Hstrok", new PredefMacroInfo(220, 0)); + MacroInfo.Commands.put("dstrok", new PredefMacroInfo(221, 0)); + MacroInfo.Commands.put("Dstrok", new PredefMacroInfo(222, 0)); + MacroInfo.Commands.put("dotminus", new PredefMacroInfo(223, 0)); + MacroInfo.Commands.put("ratio", new PredefMacroInfo(224, 0)); + MacroInfo.Commands.put("smallfrowneq", new PredefMacroInfo(225, 0)); + MacroInfo.Commands.put("geoprop", new PredefMacroInfo(226, 0)); + MacroInfo.Commands.put("minuscolon", new PredefMacroInfo(227, 0)); + MacroInfo.Commands.put("minuscoloncolon", new PredefMacroInfo(228, 0)); + MacroInfo.Commands.put("simcolon", new PredefMacroInfo(229, 0)); + MacroInfo.Commands.put("simcoloncolon", new PredefMacroInfo(230, 0)); + MacroInfo.Commands.put("approxcolon", new PredefMacroInfo(231, 0)); + MacroInfo.Commands.put("approxcoloncolon", new PredefMacroInfo(232, 0)); + MacroInfo.Commands.put("coloncolon", new PredefMacroInfo(233, 0)); + MacroInfo.Commands.put("equalscolon", new PredefMacroInfo(234, 0)); + MacroInfo.Commands.put("equalscoloncolon", new PredefMacroInfo(235, 0)); + MacroInfo.Commands.put("colonminus", new PredefMacroInfo(236, 0)); + MacroInfo.Commands.put("coloncolonminus", new PredefMacroInfo(237, 0)); + MacroInfo.Commands.put("colonequals", new PredefMacroInfo(238, 0)); + MacroInfo.Commands.put("coloncolonequals", new PredefMacroInfo(239, 0)); + MacroInfo.Commands.put("colonsim", new PredefMacroInfo(240, 0)); + MacroInfo.Commands.put("coloncolonsim", new PredefMacroInfo(241, 0)); + MacroInfo.Commands.put("colonapprox", new PredefMacroInfo(242, 0)); + MacroInfo.Commands.put("coloncolonapprox", new PredefMacroInfo(243, 0)); + MacroInfo.Commands.put("kern", new PredefMacroInfo(244, 1)); + MacroInfo.Commands.put("char", new PredefMacroInfo(245, 1)); + MacroInfo.Commands.put("roman", new PredefMacroInfo(246, 1)); + MacroInfo.Commands.put("Roman", new PredefMacroInfo(247, 1)); + MacroInfo.Commands.put("textcircled", new PredefMacroInfo(248, 1)); + MacroInfo.Commands.put("textsc", new PredefMacroInfo(249, 1)); + MacroInfo.Commands.put("sc", new PredefMacroInfo(250, 0)); + MacroInfo.Commands.put(",", new PredefMacroInfo(251, 0)); + MacroInfo.Commands.put(":", new PredefMacroInfo(252, 0)); + MacroInfo.Commands.put(";", new PredefMacroInfo(253, 0)); + MacroInfo.Commands.put("thinspace", new PredefMacroInfo(254, 0)); + MacroInfo.Commands.put("medspace", new PredefMacroInfo(255, 0)); + MacroInfo.Commands.put("thickspace", new PredefMacroInfo(256, 0)); + MacroInfo.Commands.put("!", new PredefMacroInfo(257, 0)); + MacroInfo.Commands.put("negthinspace", new PredefMacroInfo(258, 0)); + MacroInfo.Commands.put("negmedspace", new PredefMacroInfo(259, 0)); + MacroInfo.Commands.put("negthickspace", new PredefMacroInfo(260, 0)); + MacroInfo.Commands.put("quad", new PredefMacroInfo(261, 0)); + MacroInfo.Commands.put("surd", new PredefMacroInfo(262, 0)); + MacroInfo.Commands.put("iint", new PredefMacroInfo(263, 0)); + MacroInfo.Commands.put("iiint", new PredefMacroInfo(264, 0)); + MacroInfo.Commands.put("iiiint", new PredefMacroInfo(265, 0)); + MacroInfo.Commands.put("idotsint", new PredefMacroInfo(266, 0)); + MacroInfo.Commands.put("int", new PredefMacroInfo(267, 0)); + MacroInfo.Commands.put("oint", new PredefMacroInfo(268, 0)); + MacroInfo.Commands.put("lmoustache", new PredefMacroInfo(269, 0)); + MacroInfo.Commands.put("rmoustache", new PredefMacroInfo(270, 0)); + MacroInfo.Commands.put("-", new PredefMacroInfo(271, 0)); + MacroInfo.Commands.put("jlmXML", new PredefMacroInfo(272, 1)); + MacroInfo.Commands.put("above", new PredefMacroInfo(273, 0)); + MacroInfo.Commands.put("abovewithdelims", new PredefMacroInfo(274, 2)); + MacroInfo.Commands.put("st", new PredefMacroInfo(275, 1)); + MacroInfo.Commands.put("fcscore", new PredefMacroInfo(276, 1)); + MacroInfo.Commands.put("mathnormal", new PredefMacroInfo(277, 1)); + MacroInfo.Commands.put("qquad", new PredefMacroInfo(278, 0)); + MacroInfo.Commands.put("longdiv", new PredefMacroInfo(279, 2)); + MacroInfo.Commands.put("questeq", new PredefMacroInfo(280, 0)); + MacroInfo.Commands.put("bangle", new PredefMacroInfo(281, 0)); + MacroInfo.Commands.put("brace", new PredefMacroInfo(282, 0)); + MacroInfo.Commands.put("brack", new PredefMacroInfo(283, 0)); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefinedTeXFormulaParser.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefinedTeXFormulaParser.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefinedTeXFormulaParser.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,116 @@ +/* PredefinedTeXFormulaParser.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.util.Map; +import java.io.InputStream; + +import javax.xml.parsers.DocumentBuilderFactory; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * Parses and creates predefined TeXFormula objects form an XML-file. + */ +public class PredefinedTeXFormulaParser { + + private static final String RESOURCE_DIR = ""; + + public static final String RESOURCE_NAME = "PredefinedTeXFormulas.xml"; + + private Element root; + private String type; + + public PredefinedTeXFormulaParser(InputStream file, String type) throws ResourceParseException { + try { + this.type = type; + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setIgnoringElementContentWhitespace(true); + factory.setIgnoringComments(true); + root = factory.newDocumentBuilder().parse(file).getDocumentElement(); + } catch (Exception e) { // JDOMException or IOException + throw new XMLResourceParseException("", e); + } + } + + public PredefinedTeXFormulaParser(String PredefFile, String type) throws ResourceParseException { + this(PredefinedTeXFormulaParser.class.getResourceAsStream(PredefFile), type); + } + + public void parse(Map predefinedTeXFormulas) { + // get required string attribute + String enabledAll = getAttrValueAndCheckIfNotNull("enabled", root); + if ("true".equals(enabledAll)) { // parse formula's + // iterate all "Font"-elements + NodeList list = root.getElementsByTagName(this.type); + for (int i = 0; i < list.getLength(); i++) { + Element formula = (Element)list.item(i); + // get required string attribute + String enabled = getAttrValueAndCheckIfNotNull("enabled", formula); + if ("true".equals (enabled)) { // parse this formula + // get required string attribute + String name = getAttrValueAndCheckIfNotNull("name", formula); + + // parse and build the formula and add it to the table + if ("TeXFormula".equals(this.type)) + predefinedTeXFormulas.put(name, (TeXFormula) new TeXFormulaParser(name, formula, this.type).parse()); + else + predefinedTeXFormulas.put(name, (MacroInfo) new TeXFormulaParser(name, formula, this.type).parse()); + } + } + } + } + + private static String getAttrValueAndCheckIfNotNull(String attrName, + Element element) throws ResourceParseException { + String attrValue = element.getAttribute(attrName); + if (attrValue.equals("")) + throw new XMLResourceParseException(RESOURCE_NAME, element.getTagName(), + attrName, null); + return attrValue; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefinedTeXFormulas.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefinedTeXFormulas.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/PredefinedTeXFormulas.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,179 @@ +/* PredefinedTeXFormulas.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2011 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +final class PredefinedTeXFormulas { + + PredefinedTeXFormulas() { } + + static { + TeXFormula.predefinedTeXFormulasAsString.put("qquad", "\\quad\\quad"); + TeXFormula.predefinedTeXFormulasAsString.put(" ", "\\nbsp"); + TeXFormula.predefinedTeXFormulasAsString.put("ne", "\\not\\equals"); + TeXFormula.predefinedTeXFormulasAsString.put("neq", "\\not\\equals"); + TeXFormula.predefinedTeXFormulasAsString.put("ldots", "\\mathinner{\\ldotp\\ldotp\\ldotp}"); + TeXFormula.predefinedTeXFormulasAsString.put("dotsc", "\\ldots"); + TeXFormula.predefinedTeXFormulasAsString.put("dots", "\\ldots"); + TeXFormula.predefinedTeXFormulasAsString.put("cdots", "\\mathinner{\\cdotp\\cdotp\\cdotp}"); + TeXFormula.predefinedTeXFormulasAsString.put("dotsb", "\\cdots"); + TeXFormula.predefinedTeXFormulasAsString.put("dotso", "\\ldots"); + TeXFormula.predefinedTeXFormulasAsString.put("dotsi", "\\!\\cdots"); + TeXFormula.predefinedTeXFormulasAsString.put("bowtie", "\\mathrel\\triangleright\\joinrel\\mathrel\\triangleleft"); + TeXFormula.predefinedTeXFormulasAsString.put("models", "\\mathrel|\\joinrel\\equals"); + TeXFormula.predefinedTeXFormulasAsString.put("Doteq", "\\doteqdot"); + TeXFormula.predefinedTeXFormulasAsString.put("{", "\\lbrace"); + TeXFormula.predefinedTeXFormulasAsString.put("}", "\\rbrace"); + TeXFormula.predefinedTeXFormulasAsString.put("|", "\\Vert"); + TeXFormula.predefinedTeXFormulasAsString.put("&", "\\textampersand"); + TeXFormula.predefinedTeXFormulasAsString.put("%", "\\textpercent"); + TeXFormula.predefinedTeXFormulasAsString.put("_", "\\underscore"); + TeXFormula.predefinedTeXFormulasAsString.put("$", "\\textdollar"); + TeXFormula.predefinedTeXFormulasAsString.put("@", "\\jlatexmatharobase"); + TeXFormula.predefinedTeXFormulasAsString.put("#", "\\jlatexmathsharp"); + TeXFormula.predefinedTeXFormulasAsString.put("relbar", "\\mathrel{\\smash-}"); + TeXFormula.predefinedTeXFormulasAsString.put("hookrightarrow", "\\lhook\\joinrel\\joinrel\\joinrel\\rightarrow"); + TeXFormula.predefinedTeXFormulasAsString.put("hookleftarrow", "\\leftarrow\\joinrel\\joinrel\\joinrel\\rhook"); + TeXFormula.predefinedTeXFormulasAsString.put("Longrightarrow", "\\Relbar\\joinrel\\Rightarrow"); + TeXFormula.predefinedTeXFormulasAsString.put("longrightarrow", "\\relbar\\joinrel\\rightarrow"); + TeXFormula.predefinedTeXFormulasAsString.put("Longleftarrow", "\\Leftarrow\\joinrel\\Relbar"); + TeXFormula.predefinedTeXFormulasAsString.put("longleftarrow", "\\leftarrow\\joinrel\\relbar"); + TeXFormula.predefinedTeXFormulasAsString.put("Longleftrightarrow", "\\Leftarrow\\joinrel\\Rightarrow"); + TeXFormula.predefinedTeXFormulasAsString.put("longleftrightarrow", "\\leftarrow\\joinrel\\rightarrow"); + TeXFormula.predefinedTeXFormulasAsString.put("iff", "\\;\\Longleftrightarrow\\;"); + TeXFormula.predefinedTeXFormulasAsString.put("implies", "\\;\\Longrightarrow\\;"); + TeXFormula.predefinedTeXFormulasAsString.put("impliedby", "\\;\\Longleftarrow\\;"); + TeXFormula.predefinedTeXFormulasAsString.put("mapsto", "\\mapstochar\\rightarrow"); + TeXFormula.predefinedTeXFormulasAsString.put("longmapsto", "\\mapstochar\\longrightarrow"); + TeXFormula.predefinedTeXFormulasAsString.put("log", "\\mathop{\\mathrm{log}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("lg", "\\mathop{\\mathrm{lg}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("ln", "\\mathop{\\mathrm{ln}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("ln", "\\mathop{\\mathrm{ln}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("lim", "\\mathop{\\mathrm{lim}}"); + TeXFormula.predefinedTeXFormulasAsString.put("limsup", "\\mathop{\\mathrm{lim\\,sup}}"); + TeXFormula.predefinedTeXFormulasAsString.put("liminf", "\\mathop{\\mathrm{lim\\,inf}}"); + TeXFormula.predefinedTeXFormulasAsString.put("injlim", "\\mathop{\\mathrm{inj\\,lim}}"); + TeXFormula.predefinedTeXFormulasAsString.put("projlim", "\\mathop{\\mathrm{proj\\,lim}}"); + TeXFormula.predefinedTeXFormulasAsString.put("varinjlim", "\\mathop{\\underrightarrow{\\mathrm{lim}}}"); + TeXFormula.predefinedTeXFormulasAsString.put("varprojlim", "\\mathop{\\underleftarrow{\\mathrm{lim}}}"); + TeXFormula.predefinedTeXFormulasAsString.put("varliminf", "\\mathop{\\underline{\\mathrm{lim}}}"); + TeXFormula.predefinedTeXFormulasAsString.put("varlimsup", "\\mathop{\\overline{\\mathrm{lim}}}"); + TeXFormula.predefinedTeXFormulasAsString.put("sin", "\\mathop{\\mathrm{sin}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("arcsin", "\\mathop{\\mathrm{arcsin}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("sinh", "\\mathop{\\mathrm{sinh}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("cos", "\\mathop{\\mathrm{cos}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("arccos", "\\mathop{\\mathrm{arccos}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("cot", "\\mathop{\\mathrm{cot}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("arccot", "\\mathop{\\mathrm{arccot}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("cosh", "\\mathop{\\mathrm{cosh}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("tan", "\\mathop{\\mathrm{tan}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("arctan", "\\mathop{\\mathrm{arctan}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("tanh", "\\mathop{\\mathrm{tanh}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("coth", "\\mathop{\\mathrm{coth}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("sec", "\\mathop{\\mathrm{sec}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("arcsec", "\\mathop{\\mathrm{arcsec}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("arccsc", "\\mathop{\\mathrm{arccsc}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("sech", "\\mathop{\\mathrm{sech}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("csc", "\\mathop{\\mathrm{csc}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("csch", "\\mathop{\\mathrm{csch}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("max", "\\mathop{\\mathrm{max}}"); + TeXFormula.predefinedTeXFormulasAsString.put("min", "\\mathop{\\mathrm{min}}"); + TeXFormula.predefinedTeXFormulasAsString.put("sup", "\\mathop{\\mathrm{sup}}"); + TeXFormula.predefinedTeXFormulasAsString.put("inf", "\\mathop{\\mathrm{inf}}"); + TeXFormula.predefinedTeXFormulasAsString.put("arg", "\\mathop{\\mathrm{arg}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("ker", "\\mathop{\\mathrm{ker}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("dim", "\\mathop{\\mathrm{dim}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("hom", "\\mathop{\\mathrm{hom}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("det", "\\mathop{\\mathrm{det}}"); + TeXFormula.predefinedTeXFormulasAsString.put("exp", "\\mathop{\\mathrm{exp}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("Pr", "\\mathop{\\mathrm{Pr}}"); + TeXFormula.predefinedTeXFormulasAsString.put("gcd", "\\mathop{\\mathrm{gcd}}"); + TeXFormula.predefinedTeXFormulasAsString.put("deg", "\\mathop{\\mathrm{deg}}\\nolimits"); + TeXFormula.predefinedTeXFormulasAsString.put("bmod", "\\:\\mathbin{\\mathrm{mod}}\\:"); + TeXFormula.predefinedTeXFormulasAsString.put("JLaTeXMath", "\\mathbb{J}\\LaTeX Math"); + TeXFormula.predefinedTeXFormulasAsString.put("Mapsto", "\\Mapstochar\\Rightarrow"); + TeXFormula.predefinedTeXFormulasAsString.put("mapsfrom", "\\leftarrow\\mapsfromchar"); + TeXFormula.predefinedTeXFormulasAsString.put("Mapsfrom", "\\Leftarrow\\Mapsfromchar"); + TeXFormula.predefinedTeXFormulasAsString.put("Longmapsto", "\\Mapstochar\\Longrightarrow"); + TeXFormula.predefinedTeXFormulasAsString.put("longmapsfrom", "\\longleftarrow\\mapsfromchar"); + TeXFormula.predefinedTeXFormulasAsString.put("Longmapsfrom", "\\Longleftarrow\\Mapsfromchar"); + TeXFormula.predefinedTeXFormulasAsString.put("arrowvert", "\\vert"); + TeXFormula.predefinedTeXFormulasAsString.put("Arrowvert", "\\Vert"); + TeXFormula.predefinedTeXFormulasAsString.put("aa", "\\mathring{a}"); + TeXFormula.predefinedTeXFormulasAsString.put("AA", "\\mathring{A}"); + TeXFormula.predefinedTeXFormulasAsString.put("ddag", "\\ddagger"); + TeXFormula.predefinedTeXFormulasAsString.put("dag", "\\dagger"); + TeXFormula.predefinedTeXFormulasAsString.put("Doteq", "\\doteqdot"); + TeXFormula.predefinedTeXFormulasAsString.put("doublecup", "\\Cup"); + TeXFormula.predefinedTeXFormulasAsString.put("doublecap", "\\Cap"); + TeXFormula.predefinedTeXFormulasAsString.put("llless", "\\lll"); + TeXFormula.predefinedTeXFormulasAsString.put("gggtr", "\\ggg"); + TeXFormula.predefinedTeXFormulasAsString.put("Alpha", "\\mathord{\\mathrm{A}}"); + TeXFormula.predefinedTeXFormulasAsString.put("Beta", "\\mathord{\\mathrm{B}}"); + TeXFormula.predefinedTeXFormulasAsString.put("Epsilon", "\\mathord{\\mathrm{E}}"); + TeXFormula.predefinedTeXFormulasAsString.put("Zeta", "\\mathord{\\mathrm{Z}}"); + TeXFormula.predefinedTeXFormulasAsString.put("Eta", "\\mathord{\\mathrm{H}}"); + TeXFormula.predefinedTeXFormulasAsString.put("Iota", "\\mathord{\\mathrm{I}}"); + TeXFormula.predefinedTeXFormulasAsString.put("Kappa", "\\mathord{\\mathrm{K}}"); + TeXFormula.predefinedTeXFormulasAsString.put("Mu", "\\mathord{\\mathrm{M}}"); + TeXFormula.predefinedTeXFormulasAsString.put("Nu", "\\mathord{\\mathrm{N}}"); + TeXFormula.predefinedTeXFormulasAsString.put("Omicron", "\\mathord{\\mathrm{O}}"); + TeXFormula.predefinedTeXFormulasAsString.put("Rho", "\\mathord{\\mathrm{P}}"); + TeXFormula.predefinedTeXFormulasAsString.put("Tau", "\\mathord{\\mathrm{T}}"); + TeXFormula.predefinedTeXFormulasAsString.put("Chi", "\\mathord{\\mathrm{X}}"); + TeXFormula.predefinedTeXFormulasAsString.put("hdots", "\\ldots"); + TeXFormula.predefinedTeXFormulasAsString.put("restriction", "\\upharpoonright"); + TeXFormula.predefinedTeXFormulasAsString.put("celsius", "\\mathord{{}^\\circ\\mathrm{C}}"); + TeXFormula.predefinedTeXFormulasAsString.put("micro", "\\textmu"); + TeXFormula.predefinedTeXFormulasAsString.put("marker", "\\kern{0.25ex}\\rule{0.5ex}{1.2ex}\\kern{0.25ex}"); + TeXFormula.predefinedTeXFormulasAsString.put("hybull", "\\rule[0.6ex]{1ex}{0.2ex}"); + TeXFormula.predefinedTeXFormulasAsString.put("block", "\\rule{1ex}{1.2ex}"); + TeXFormula.predefinedTeXFormulasAsString.put("uhblk", "\\rule[0.6ex]{1ex}{0.6ex}"); + TeXFormula.predefinedTeXFormulasAsString.put("lhblk", "\\rule{1ex}{0.6ex}"); + TeXFormula.predefinedTeXFormulasAsString.put("notin", "\\not\\in"); + TeXFormula.predefinedTeXFormulasAsString.put("rVert", "\\Vert"); + TeXFormula.predefinedTeXFormulasAsString.put("lVert", "\\Vert"); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RaiseAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RaiseAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RaiseAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,97 @@ +/* RaiseAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2011 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a scaled Atom. + */ +public class RaiseAtom extends Atom { + + private Atom base; + private int runit, hunit, dunit; + private float r, h, d; + + public RaiseAtom(Atom base, int runit, float r, int hunit, float h, int dunit, float d) { + this.base = base; + this.runit = runit; + this.r = r; + this.hunit = hunit; + this.h = h; + this.dunit = dunit; + this.d = d; + } + + public int getLeftType() { + return base.getLeftType(); + } + + public int getRightType() { + return base.getRightType(); + } + + public Box createBox(TeXEnvironment env) { + Box bbox = base.createBox(env); + if (runit == -1) { + bbox.setShift(0); + } else { + bbox.setShift(-r * SpaceAtom.getFactor(runit, env)); + } + + if (hunit == -1) { + return bbox; + } + + HorizontalBox hbox = new HorizontalBox(bbox); + hbox.setHeight(h * SpaceAtom.getFactor(hunit, env)); + if (dunit == -1) { + hbox.setDepth(0); + } else { + hbox.setDepth(d * SpaceAtom.getFactor(dunit, env)); + } + + return hbox; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ReflectAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ReflectAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ReflectAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,63 @@ +/* ReflectAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a reflected Atom. + */ +public class ReflectAtom extends Atom { + + private Atom base; + + public ReflectAtom(Atom base) { + this.type = base.type; + this.base = base; + } + + public Box createBox(TeXEnvironment env) { + return new ReflectBox(base.createBox(env)); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ReflectBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ReflectBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ReflectBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,77 @@ +/* ReflectBox.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Graphics2D; + +/** + * A box representing a rotated box. + */ +public class ReflectBox extends Box { + + private Box box; + + public ReflectBox(Box b) { + this.box = b; + width = b.width; + height = b.height; + depth = b.depth; + shift = b.shift; + } + + public void draw(Graphics2D g2, float x, float y) { + drawDebug(g2, x, y); + g2.translate(x, y); + g2.scale(-1, 1); + box.draw(g2, -width, 0); + g2.scale(-1, 1); + g2.translate(-x, -y); + } + + public int getLastFontId() { + return box.getLastFontId(); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ResizeAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ResizeAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ResizeAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,111 @@ +/* ResizeAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2011 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a scaled Atom. + */ +public class ResizeAtom extends Atom { + + private Atom base; + private int wunit, hunit; + private float w, h; + private boolean keepaspectratio; + + public ResizeAtom(Atom base, String ws, String hs, boolean keepaspectratio) { + this.type = base.type; + this.base = base; + this.keepaspectratio = keepaspectratio; + float[] w = SpaceAtom.getLength(ws == null ? "" : ws); + float[] h = SpaceAtom.getLength(hs == null ? "" : hs); + if (w.length != 2) { + this.wunit = -1; + } else { + this.wunit = (int) w[0]; + this.w = w[1]; + } + if (h.length != 2) { + this.hunit = -1; + } else { + this.hunit = (int) h[0]; + this.h = h[1]; + } + } + + public int getLeftType() { + return base.getLeftType(); + } + + public int getRightType() { + return base.getRightType(); + } + + public Box createBox(TeXEnvironment env) { + Box bbox = base.createBox(env); + if (wunit == -1 && hunit == -1) { + return bbox; + } else { + double xscl = 1; + double yscl = 1; + if (wunit != -1 && hunit != -1) { + xscl = w * SpaceAtom.getFactor(wunit, env) / bbox.width; + yscl = h * SpaceAtom.getFactor(hunit, env) / bbox.height; + if (keepaspectratio) { + xscl = Math.min(xscl, yscl); + yscl = xscl; + } + } else if (wunit != -1 && hunit == -1) { + xscl = w * SpaceAtom.getFactor(wunit, env) / bbox.width; + yscl = xscl; + } else { + yscl = h * SpaceAtom.getFactor(hunit, env) / bbox.height; + xscl = yscl; + } + + return new ScaleBox(bbox, xscl, yscl); + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ResourceParseException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ResourceParseException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ResourceParseException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,61 @@ +/* ResourceParseException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals that an error occurred while loading the necessary resources into memory. + */ +public class ResourceParseException extends JMathTeXException { + + protected ResourceParseException(String msg) { + super(msg); + } + + protected ResourceParseException(String msg, Throwable cause) { + super(msg, cause); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RomanAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RomanAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RomanAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,71 @@ +/* RomanAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a roman atom. + */ +public class RomanAtom extends Atom { + + protected Atom base; + + public RomanAtom(Atom base) { + this.base = base; + } + + public Box createBox(TeXEnvironment env) { + Box box; + if (base != null) { + env = env.copy(env.getTeXFont().copy()); + env.getTeXFont().setRoman(true); + box = base.createBox(env); + } else { + box = new StrutBox(0, 0, 0, 0); + } + + return box; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RotateAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RotateAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RotateAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,102 @@ +/* RotateAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.util.Map; + +/** + * An atom representing a rotated Atom. + */ +public class RotateAtom extends Atom { + + private Atom base; + private double angle; + private int option = -1; + private int xunit, yunit; + private float x, y; + + public RotateAtom(Atom base, String angle, String option) { + this.type = base.type; + this.base = base; + this.angle = Double.parseDouble(angle); + this.option = RotateBox.getOrigin(option); + } + + public RotateAtom(Atom base, double angle, String option) { + this.type = base.type; + this.base = base; + this.angle = angle; + Map map = ParseOption.parseMap(option); + if (map.containsKey("origin")) { + this.option = RotateBox.getOrigin(map.get("origin")); + } else { + if (map.containsKey("x")) { + float[] xinfo = SpaceAtom.getLength(map.get("x")); + this.xunit = (int) xinfo[0]; + this.x = xinfo[1]; + } else { + this.xunit = TeXConstants.UNIT_POINT; + this.x = 0; + } + if (map.containsKey("y")) { + float[] yinfo = SpaceAtom.getLength(map.get("y")); + this.yunit = (int) yinfo[0]; + this.y = yinfo[1]; + } else { + this.yunit = TeXConstants.UNIT_POINT; + this.y = 0; + } + } + } + + public Box createBox(TeXEnvironment env) { + if (option != -1) { + return new RotateBox(base.createBox(env), angle, option); + } else { + return new RotateBox(base.createBox(env), angle, x * SpaceAtom.getFactor(xunit, env), y * SpaceAtom.getFactor(yunit, env)); + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RotateBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RotateBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RotateBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,212 @@ +/* RotateBox.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009-2011 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Graphics2D; +import java.awt.geom.Point2D; + +/** + * A box representing a rotated box. + */ +public class RotateBox extends Box { + + public static final int BL = 0; + public static final int BC = 1; + public static final int BR = 2; + public static final int TL = 3; + public static final int TC = 4; + public static final int TR = 5; + public static final int BBL = 6; + public static final int BBR = 7; + public static final int BBC = 8; + public static final int CL = 9; + public static final int CC = 10; + public static final int CR = 11; + + protected double angle = 0; + private Box box; + private float xmax, xmin, ymax, ymin; + private int option; + + private float shiftX; + private float shiftY; + + public RotateBox(Box b, double angle, float x, float y) { + this.box = b; + this.angle = angle * Math.PI / 180; + height = b.height; + depth = b.depth; + width = b.width; + double s = Math.sin(this.angle); + double c = Math.cos(this.angle); + shiftX = (float) (x * (1 - c) + y * s); + shiftY = (float) (y * (1 - c) - x * s); + xmax = (float) Math.max(-height * s, Math.max(depth * s, Math.max(width * c + depth * s, width * c - height * s))) + shiftX; + xmin = (float) Math.min(-height * s, Math.min(depth * s, Math.min(width * c + depth * s, width * c - height * s))) + shiftX; + ymax = (float) Math.max(height * c, Math.max(-depth * c, Math.max(width * s - depth * c, width * s + height * c))); + ymin = (float) Math.min(height * c, Math.min(-depth * c, Math.min(width * s - depth * c, width * s + height * c))); + width = xmax - xmin; + height = ymax + shiftY; + depth = -ymin - shiftY; + } + + public RotateBox(Box b, double angle, Point2D.Float origin) { + this(b, angle, origin.x, origin.y); + } + + public RotateBox(Box b, double angle, int option) { + this(b, angle, calculateShift(b, option)); + } + + public static int getOrigin(String option) { + if (option == null || option.length() == 0) { + return BBL; + } + + if (option.length() == 1) { + option += "c"; + } + if (option.equals("bl") || option.equals("lb")) { + return BL; + } else if (option.equals("bc") || option.equals("cb")) { + return BC; + } else if (option.equals("br") || option.equals("rb")) { + return BR; + } else if (option.equals("cl") || option.equals("lc")) { + return CL; + } else if (option.equals("cc")) { + return CC; + } else if (option.equals("cr") || option.equals("cr")) { + return CR; + } else if (option.equals("tl") || option.equals("lt")) { + return TL; + } else if (option.equals("tc") || option.equals("ct")) { + return TC; + } else if (option.equals("tr") || option.equals("rt")) { + return TR; + } else if (option.equals("Bl") || option.equals("lB")) { + return BBL; + } else if (option.equals("Bc") || option.equals("cB")) { + return BBC; + } else if (option.equals("Br") || option.equals("rB")) { + return BBR; + } else + + return BBL; + } + + private static Point2D.Float calculateShift(Box b, int option) { + Point2D.Float p = new Point2D.Float(0, -b.depth); + switch (option) { + case BL : + p.x = 0; + p.y = -b.depth; + break; + case BR : + p.x = b.width; + p.y = -b.depth; + break; + case BC : + p.x = b.width / 2; + p.y = - b.depth; + break; + case TL : + p.x = 0; + p.y = b.height; + break; + case TR : + p.x = b.width; + p.y = b.height; + break; + case TC : + p.x = b.width / 2; + p.y = b.height; + break; + case BBL : + p.x = 0; + p.y = 0; + break; + case BBR : + p.x = b.width; + p.y = 0; + break; + case BBC : + p.x = b.width / 2; + p.y = 0; + break; + case CL : + p.x = 0; + p.y = (b.height - b.depth) / 2; + break; + case CR : + p.x = b.width; + p.y = (b.height - b.depth) / 2; + break; + case CC : + p.x = b.width / 2; + p.y = (b.height - b.depth) / 2; + break; + default : + } + + return p; + } + + public void draw(Graphics2D g2, float x, float y) { + drawDebug(g2, x, y); + box.drawDebug(g2, x, y, true); + y -= shiftY; + x += shiftX - xmin; + g2.rotate(-angle, x, y); + box.draw(g2, x, y); + box.drawDebug(g2, x, y, true); + g2.rotate(angle, x, y); + } + + public int getLastFontId() { + return box.getLastFontId(); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Row.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Row.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/Row.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,65 @@ +/* Row.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * A "composed atom": an atom that consists of child atoms that will be displayed + * next to each other horizontally with glue between them. + */ +public interface Row { + + /** + * Sets the given dummy containing the atom that comes just before + * the first child atom of this "composed atom". This method will allways be called + * by another composed atom, so this composed atom will be a child of it (nested). + * This is necessary to determine the glue to insert between the first child atom + * of this nested composed atom and the atom that the dummy contains. + * + * @param dummy the dummy that comes just before this "composed atom" + */ + public void setPreviousAtom(Dummy dummy); +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RowAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RowAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RowAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,278 @@ +/* RowAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet to handle the case where several ligatures occure*/ + +package org.scilab.forge.jlatexmath; + +import java.util.BitSet; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; + +import org.scilab.forge.jlatexmath.dynamic.DynamicAtom; + +/** + * An atom representing a horizontal row of other atoms, to be seperated by glue. + * It's also responsible for inserting kerns and ligatures. + */ +public class RowAtom extends Atom implements Row { + + // atoms to be displayed horizontally next to eachother + protected LinkedList elements = new LinkedList(); + + public boolean lookAtLastAtom = false; + + // previous atom (for nested Row atoms) + private Dummy previousAtom = null; + + // set of atom types that make a previous bin atom change to ord + private static BitSet binSet; + + // set of atom types that can possibly need a kern or, together with the + // previous atom, be replaced by a ligature + private static BitSet ligKernSet; + + static { + // fill binSet + binSet = new BitSet (16); + binSet.set(TeXConstants.TYPE_BINARY_OPERATOR); + binSet.set(TeXConstants.TYPE_BIG_OPERATOR); + binSet.set(TeXConstants.TYPE_RELATION); + binSet.set(TeXConstants.TYPE_OPENING); + binSet.set(TeXConstants.TYPE_PUNCTUATION); + + // fill ligKernSet + ligKernSet = new BitSet (16); + ligKernSet.set(TeXConstants.TYPE_ORDINARY); + ligKernSet.set(TeXConstants.TYPE_BIG_OPERATOR); + ligKernSet.set(TeXConstants.TYPE_BINARY_OPERATOR); + ligKernSet.set(TeXConstants.TYPE_RELATION); + ligKernSet.set(TeXConstants.TYPE_OPENING); + ligKernSet.set(TeXConstants.TYPE_CLOSING); + ligKernSet.set(TeXConstants.TYPE_PUNCTUATION); + } + + protected RowAtom() { + // empty + } + + public RowAtom(Atom el) { + if (el != null) { + if (el instanceof RowAtom) + // no need to make an mrow the only element of an mrow + elements.addAll(((RowAtom) el).elements); + else + elements.add(el); + } + } + + public Atom getLastAtom() { + if (elements.size() != 0) { + return elements.removeLast(); + } + + return new SpaceAtom(TeXConstants.UNIT_POINT, 0.0f, 0.0f, 0.0f); + } + + public final void add(Atom el) { + if (el != null) { + elements.add(el); + } + } + + /** + * + * @param cur + * current atom being processed + * @param prev + * previous atom + */ + private void changeToOrd(Dummy cur, Dummy prev, Atom next) { + int type = cur.getLeftType(); + if (type == TeXConstants.TYPE_BINARY_OPERATOR && ((prev == null || binSet.get(prev.getRightType())) || next == null)) { + cur.setType(TeXConstants.TYPE_ORDINARY); + } else if (next != null && cur.getRightType() == TeXConstants.TYPE_BINARY_OPERATOR) { + int nextType = next.getLeftType(); + if (nextType == TeXConstants.TYPE_RELATION || nextType == TeXConstants.TYPE_CLOSING || nextType == TeXConstants.TYPE_PUNCTUATION) { + cur.setType(TeXConstants.TYPE_ORDINARY); + } + } + } + + public Box createBox(TeXEnvironment env) { + TeXFont tf = env.getTeXFont(); + HorizontalBox hBox = new HorizontalBox(env.getColor(), env.getBackground()); + int position = 0; + env.reset(); + + // convert atoms to boxes and add to the horizontal box + for (ListIterator it = elements.listIterator(); it.hasNext();) { + Atom at = it.next(); + position++; + + boolean markAdded = false; + while (at instanceof BreakMarkAtom) { + if (!markAdded) { + markAdded = true; + } + if (it.hasNext()) { + at = it.next(); + position++; + } else { + break; + } + } + + if (at instanceof DynamicAtom && ((DynamicAtom) at).getInsertMode()) { + Atom a = ((DynamicAtom) at).getAtom(); + if (a instanceof RowAtom) { + elements.remove(position - 1); + elements.addAll(position - 1, ((RowAtom) a).elements); + it = elements.listIterator(position - 1); + at = it.next(); + } else { + at = a; + } + } + + Dummy atom = new Dummy(at); + + // if necessary, change BIN type to ORD + Atom nextAtom = null; + if (it.hasNext()) { + nextAtom = it.next(); + it.previous(); + } + changeToOrd(atom, previousAtom, nextAtom); + + // check for ligatures or kerning + float kern = 0; + // Calixte : I put a while to handle the case where there are + // several ligatures as in ffi or ffl + while (it.hasNext() && atom.getRightType() == TeXConstants.TYPE_ORDINARY && atom.isCharSymbol()) { + Atom next = it.next(); + position++; + if (next instanceof CharSymbol && ligKernSet.get(next.getLeftType())) { + atom.markAsTextSymbol(); + CharFont l = atom.getCharFont(tf), r = ((CharSymbol) next).getCharFont(tf); + CharFont lig = tf.getLigature(l, r); + if (lig == null) { + kern = tf.getKern(l, r, env.getStyle()); + it.previous(); + position--; + break; // iterator remains unchanged (no ligature!) + } + else { // ligature + atom.changeAtom(new FixedCharAtom(lig)); // go on with the + // ligature + } + } else { + it.previous(); + position--; + break; + }// iterator remains unchanged + } + + // insert glue, unless it's the first element of the row + // OR this element or the next is a Kern. + if (it.previousIndex() != 0 && previousAtom != null && !previousAtom.isKern() && !atom.isKern()) { + hBox.add(Glue.get(previousAtom.getRightType(), atom.getLeftType(), env)); + } + + // insert atom's box + atom.setPreviousAtom(previousAtom); + Box b = atom.createBox(env); + if (atom.isCharInMathMode() && b instanceof CharBox) { + // When we've a single char, we need to add italic correction + // As an example: (TVY) looks crappy... + CharBox cb = (CharBox) b; + cb.addItalicCorrectionToWidth(); + } + if (markAdded || (at instanceof CharAtom && Character.isDigit(((CharAtom) at).getCharacter()))) { + hBox.addBreakPosition(hBox.children.size()); + } + hBox.add(b); + + // set last used fontId (for next atom) + env.setLastFontId(b.getLastFontId()); + + // insert kern + if (Math.abs(kern) > TeXFormula.PREC) { + hBox.add(new StrutBox(kern, 0, 0, 0)); + } + + // kerns do not interfere with the normal glue-rules without kerns + if (!atom.isKern()) { + previousAtom = atom; + } + } + // reset previousAtom + previousAtom = null; + + return hBox; + } + + public void setPreviousAtom(Dummy prev) { + previousAtom = prev; + } + + public int getLeftType() { + if (elements.size() == 0) { + return TeXConstants.TYPE_ORDINARY; + } else { + return (elements.get(0)).getLeftType(); + } + } + + public int getRightType() { + if (elements.size() == 0) { + return TeXConstants.TYPE_ORDINARY; + } else { + return (elements.get(elements.size() - 1)).getRightType(); + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RuleAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RuleAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/RuleAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,69 @@ +/* RuleAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a rule. + */ +public class RuleAtom extends Atom { + + private int wunit, hunit, runit; + private float w, h, r; + private SpaceAtom width, height, raise; + + public RuleAtom(int wunit, float width, int hunit, float height, int runit, float raise) { + this.wunit = wunit; + this.hunit = hunit; + this.runit = runit; + this.w = width; + this.h = height; + this.r = raise; + } + + public Box createBox(TeXEnvironment env) { + return new HorizontalRule(h * SpaceAtom.getFactor(hunit, env), w * SpaceAtom.getFactor(wunit, env), r * SpaceAtom.getFactor(runit, env)); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ScaleAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ScaleAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ScaleAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,81 @@ +/* ScaleAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a scaled Atom. + */ +public class ScaleAtom extends Atom { + + protected Atom base; + private double xscl, yscl; + + public ScaleAtom(Atom base, double xscl, double yscl) { + this.type = base.type; + this.base = base; + this.xscl = xscl; + this.yscl = yscl; + } + + public ScaleAtom(Atom base, double scl) { + this.type = base.type; + this.base = base; + this.xscl = scl; + this.yscl = scl; + } + + public int getLeftType() { + return base.getLeftType(); + } + + public int getRightType() { + return base.getRightType(); + } + + public Box createBox(TeXEnvironment env) { + return new ScaleBox(base.createBox(env), xscl, yscl); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ScaleBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ScaleBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ScaleBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,89 @@ +/* ScaleBox.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Graphics2D; + +/** + * A box representing a scaled box. + */ +public class ScaleBox extends Box { + + private Box box; + private double xscl, yscl; + private float factor = 1; + + public ScaleBox(Box b, double xscl, double yscl) { + this.box = b; + this.xscl = (Double.isNaN(xscl) || Double.isInfinite(xscl)) ? 0 : xscl; + this.yscl = (Double.isNaN(yscl) || Double.isInfinite(yscl)) ? 0 : yscl; + width = b.width * (float) Math.abs(this.xscl); + height = this.yscl > 0 ? b.height * (float) this.yscl : -b.depth * (float) this.yscl; + depth = this.yscl > 0 ? b.depth * (float) this.yscl : -b.height * (float) this.yscl; + shift = b.shift * (float) this.yscl; + } + + public ScaleBox(Box b, float factor) { + this(b, (double) factor, (double) factor); + this.factor = factor; + } + + public void draw(Graphics2D g2, float x, float y) { + drawDebug(g2, x, y); + if (xscl != 0 && yscl != 0) { + float dec = xscl < 0 ? width : 0; + g2.translate(x + dec, y); + g2.scale(xscl, yscl); + box.draw(g2, 0, 0); + g2.scale(1 / xscl, 1 / yscl); + g2.translate(-x - dec, -y); + } + } + + public int getLastFontId() { + return box.getLastFontId(); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ScriptsAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ScriptsAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ScriptsAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,229 @@ +/* ScriptsAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing scripts to be attached to another atom. + */ +public class ScriptsAtom extends Atom { + + // TeX constant: what's the use??? + private final static SpaceAtom SCRIPT_SPACE = new SpaceAtom(TeXConstants.UNIT_POINT, 0.5f, 0, 0); + + // base atom + private final Atom base; + + // subscript and superscript to be attached to the base (if not null) + private final Atom subscript; + private final Atom superscript; + private int align = TeXConstants.ALIGN_LEFT; + + public ScriptsAtom(Atom base, Atom sub, Atom sup) { + this.base = base; + subscript = sub; + superscript = sup; + } + + public ScriptsAtom(Atom base, Atom sub, Atom sup, boolean left) { + this(base, sub, sup); + if (!left) + align = TeXConstants.ALIGN_RIGHT; + } + + public Box createBox(TeXEnvironment env) { + Box b = (base == null ? new StrutBox(0, 0, 0, 0) : base.createBox(env)); + Box deltaSymbol = new StrutBox(0, 0, 0, 0); + if (subscript == null && superscript == null) + return b; + else { + TeXFont tf = env.getTeXFont(); + int style = env.getStyle(); + + if (base.type_limits == TeXConstants.SCRIPT_LIMITS || (base.type_limits == TeXConstants.SCRIPT_NORMAL && style == TeXConstants.STYLE_DISPLAY)) + return new UnderOverAtom(new UnderOverAtom(base, subscript, TeXConstants.UNIT_POINT, 0.3f, true, false), + superscript, TeXConstants.UNIT_POINT, 3.0f, true, true).createBox(env); + + HorizontalBox hor = new HorizontalBox(b); + + int lastFontId = b.getLastFontId(); + // if no last font found (whitespace box), use default "mu font" + if (lastFontId == TeXFont.NO_FONT) + lastFontId = tf.getMuFontId(); + + TeXEnvironment subStyle = env.subStyle(), supStyle = env.supStyle(); + + // set delta and preliminary shift-up and shift-down values + float delta = 0, shiftUp, shiftDown; + + // TODO: use polymorphism? + if (base instanceof AccentedAtom) { // special case : + // accent. This positions superscripts better next to the accent! + Box box = ((AccentedAtom) base).base.createBox(env.crampStyle()); + shiftUp = box.getHeight() - tf.getSupDrop(supStyle.getStyle()); + shiftDown = box.getDepth() + tf.getSubDrop(subStyle.getStyle()); + } else if (base instanceof SymbolAtom + && base.type == TeXConstants.TYPE_BIG_OPERATOR) { // single big operator symbol + Char c = tf.getChar(((SymbolAtom) base).getName(), style); + if (style < TeXConstants.STYLE_TEXT && tf.hasNextLarger(c)) // display + // style + c = tf.getNextLarger(c, style); + Box x = new CharBox(c); + + x.setShift(-(x.getHeight() + x.getDepth()) / 2 + - env.getTeXFont().getAxisHeight(env.getStyle())); + hor = new HorizontalBox(x); + + // include delta in width or not? + delta = c.getItalic(); + deltaSymbol = new SpaceAtom(TeXConstants.MEDMUSKIP).createBox(env); + if (delta > TeXFormula.PREC && subscript == null) + hor.add(new StrutBox(delta, 0, 0, 0)); + + shiftUp = hor.getHeight() - tf.getSupDrop(supStyle.getStyle()); + shiftDown = hor.getDepth() + tf.getSubDrop(subStyle.getStyle()); + } else if (base instanceof CharSymbol) { + shiftUp = shiftDown = 0; + CharFont cf = ((CharSymbol) base).getCharFont(tf); + if (!((CharSymbol) base).isMarkedAsTextSymbol() || !tf.hasSpace(cf.fontId)) { + delta = tf.getChar(cf, style).getItalic(); + } + if (delta > TeXFormula.PREC && subscript == null) { + hor.add(new StrutBox(delta, 0, 0, 0)); + delta = 0; + } + } else { + shiftUp = b.getHeight() - tf.getSupDrop(supStyle.getStyle()); + shiftDown = b.getDepth() + tf.getSubDrop(subStyle.getStyle()); + } + + if (superscript == null) { // only subscript + Box x = subscript.createBox(subStyle); + // calculate and set shift amount + x.setShift(Math.max(Math.max(shiftDown, tf.getSub1(style)), x.getHeight() - 4 * Math.abs(tf.getXHeight(style, lastFontId)) / 5)); + hor.add(x); + hor.add(deltaSymbol); + + return hor; + } else { + Box x = superscript.createBox(supStyle); + float msiz = x.getWidth(); + if (subscript != null && align == TeXConstants.ALIGN_RIGHT) { + msiz = Math.max(msiz, subscript.createBox(subStyle).getWidth()); + } + + HorizontalBox sup = new HorizontalBox(x, msiz, align); + // add scriptspace (constant value!) + sup.add(SCRIPT_SPACE.createBox(env)); + // adjust shift-up + float p; + if (style == TeXConstants.STYLE_DISPLAY) + p = tf.getSup1(style); + else if (env.crampStyle().getStyle() == style) + p = tf.getSup3(style); + else + p = tf.getSup2(style); + shiftUp = Math.max(Math.max(shiftUp, p), x.getDepth() + + Math.abs(tf.getXHeight(style, lastFontId)) / 4); + + if (subscript == null) { // only superscript + sup.setShift(-shiftUp); + hor.add(sup); + } else { // both superscript and subscript + Box y = subscript.createBox(subStyle); + HorizontalBox sub = new HorizontalBox(y, msiz, align); + // add scriptspace (constant value!) + sub.add(SCRIPT_SPACE.createBox(env)); + // adjust shift-down + shiftDown = Math.max(shiftDown, tf.getSub2(style)); + // position both sub- and superscript + float drt = tf.getDefaultRuleThickness(style); + float interSpace = shiftUp - x.getDepth() + shiftDown + - y.getHeight(); // space between sub- en + // superscript + if (interSpace < 4 * drt) { // too small + shiftUp += 4 * drt - interSpace; + // set bottom superscript at least 4/5 of X-height + // above + // baseline + float psi = 4 * Math.abs(tf.getXHeight(style, lastFontId)) + / 5 - (shiftUp - x.getDepth()); + + if (psi > 0) { + shiftUp += psi; + shiftDown -= psi; + } + } + // create total box + + VerticalBox vBox = new VerticalBox(); + sup.setShift(delta); + vBox.add(sup); + // recalculate interspace + interSpace = shiftUp - x.getDepth() + shiftDown - y.getHeight(); + vBox.add(new StrutBox(0, interSpace, 0, 0)); + vBox.add(sub); + vBox.setHeight(shiftUp + x.getHeight()); + vBox.setDepth(shiftDown + y.getDepth()); + hor.add(vBox); + } + hor.add(deltaSymbol); + + return hor; + } + } + } + + public int getLeftType() { + return base.getLeftType(); + } + + public int getRightType() { + return base.getRightType(); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ShadowAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ShadowAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ShadowAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,62 @@ +/* ShadowAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Color; + +/** + * An atom representing a boxed base atom. + */ +public class ShadowAtom extends FBoxAtom { + + public ShadowAtom(Atom base) { + super(base); + } + + public Box createBox(TeXEnvironment env) { + return new ShadowBox((FramedBox) super.createBox(env), env.getTeXFont().getDefaultRuleThickness(env.getStyle()) * 4); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ShadowBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ShadowBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/ShadowBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,101 @@ +/* FramedBox.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Graphics2D; +import java.awt.Stroke; +import java.awt.BasicStroke; +import java.awt.geom.Rectangle2D; + +/** + * A box representing a rotated box. + */ +public class ShadowBox extends FramedBox { + + private float shadowRule; + + public ShadowBox(FramedBox fbox, float shadowRule) { + super(fbox.box, fbox.thickness, fbox.space); + this.shadowRule = shadowRule; + depth += shadowRule; + width += shadowRule; + } + + public void draw(Graphics2D g2, float x, float y) { + float th = thickness / 2; + box.draw(g2, x + space + thickness, y); + Stroke st = g2.getStroke(); + g2.setStroke(new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); + g2.draw(new Rectangle2D.Float(x + th, y - height + th, width - shadowRule - thickness, height + depth - shadowRule - thickness)); + float penth = (float) Math.abs(1 / g2.getTransform().getScaleX()); + g2.setStroke(new BasicStroke(penth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); + g2.fill(new Rectangle2D.Float(x + shadowRule - penth, y + depth - shadowRule - penth, width - shadowRule, shadowRule)); + g2.fill(new Rectangle2D.Float(x + width - shadowRule - penth, y - height + th + shadowRule, shadowRule, depth + height - 2 * shadowRule - th)); + //drawDebug(g2, x, y); + g2.setStroke(st); + } + + public int getLastFontId() { + return box.getLastFontId(); + } +} +/* + + public void draw(Graphics2D g2, float x, float y) { + float th = thickness / 2; + float sh = shadowRule / 2; + box.draw(g2, x + space + thickness, y); + Stroke st = g2.getStroke(); + g2.setStroke(new BasicStroke(shadowRule, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); + g2.draw(new Line2D.Float(x + shadowRule, y + depth - sh, x + width, y + depth - sh)); + g2.draw(new Line2D.Float(x + width - sh, y - height + shadowRule, x + width - sh, y + depth - shadowRule)); + g2.setStroke(new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); + g2.draw(new Rectangle2D.Float(x + th, y - height + th, width - shadowRule - thickness, height + depth - shadowRule - thickness)); + //drawDebug(g2, x, y); + g2.setStroke(st); + } + +*/ Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SmallCapAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SmallCapAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SmallCapAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,66 @@ +/* RomanAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a small capital atom. + */ +public class SmallCapAtom extends Atom { + + protected Atom base; + + public SmallCapAtom(Atom base) { + this.base = base; + } + + public Box createBox(TeXEnvironment env) { + boolean prev = env.getSmallCap(); + env.setSmallCap(true); + Box box = base.createBox(env); + env.setSmallCap(prev); + return box; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SmashedAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SmashedAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SmashedAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,76 @@ +/* SmashedAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a smashed atom (i.e. with no height and no depth). + */ +public class SmashedAtom extends Atom { + + private Atom at; + private boolean h = true, d = true; + + public SmashedAtom(Atom at, String opt) { + this.at = at; + if ("t".equals(opt)) + d = false; + else if ("b".equals(opt)) + h = false; + } + + public SmashedAtom(Atom at) { + this.at = at; + } + + public Box createBox(TeXEnvironment env) { + Box b = at.createBox(env); + if (h) + b.setHeight(0); + if (d) + b.setDepth(0); + return b; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SpaceAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SpaceAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SpaceAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,292 @@ +/* SpaceAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet */ + +package org.scilab.forge.jlatexmath; + +import java.util.HashMap; +import java.util.Map; + +/** + * An atom representing whitespace. The dimension values can be set using different + * unit types. + */ +public class SpaceAtom extends Atom { + + private static Map units = new HashMap(); + static { + units.put("em", TeXConstants.UNIT_EM); + units.put("ex", TeXConstants.UNIT_EX); + units.put("px", TeXConstants.UNIT_PIXEL); + units.put("pix", TeXConstants.UNIT_PIXEL); + units.put("pixel", TeXConstants.UNIT_PIXEL); + units.put("pt", TeXConstants.UNIT_PT); + units.put("bp", TeXConstants.UNIT_POINT); + units.put("pica", TeXConstants.UNIT_PICA); + units.put("pc", TeXConstants.UNIT_PICA); + units.put("mu", TeXConstants.UNIT_MU); + units.put("cm", TeXConstants.UNIT_CM); + units.put("mm", TeXConstants.UNIT_MM); + units.put("in", TeXConstants.UNIT_IN); + units.put("sp", TeXConstants.UNIT_SP); + units.put("dd", TeXConstants.UNIT_DD); + units.put("cc", TeXConstants.UNIT_CC); + } + + private static interface UnitConversion { // NOPMD + public float getPixelConversion(TeXEnvironment env); + } + + private static UnitConversion[] unitConversions = new UnitConversion[] { + + new UnitConversion() {//EM + public float getPixelConversion(TeXEnvironment env) { + return env.getTeXFont().getEM(env.getStyle()); + } + }, + + new UnitConversion() {//EX + public float getPixelConversion(TeXEnvironment env) { + return env.getTeXFont().getXHeight(env.getStyle(), env.getLastFontId()); + } + }, + + new UnitConversion() {//PIXEL + public float getPixelConversion(TeXEnvironment env) { + return 1 / env.getSize(); + } + }, + + new UnitConversion() {//BP (or PostScript point) + public float getPixelConversion(TeXEnvironment env) { + return TeXFormula.PIXELS_PER_POINT / env.getSize(); + } + }, + + new UnitConversion() {//PICA + public float getPixelConversion(TeXEnvironment env) { + return (12 * TeXFormula.PIXELS_PER_POINT) / env.getSize(); + } + }, + + new UnitConversion() {//MU + public float getPixelConversion(TeXEnvironment env) { + TeXFont tf = env.getTeXFont(); + return tf.getQuad(env.getStyle(), tf.getMuFontId()) / 18; + } + }, + + new UnitConversion() {//CM + public float getPixelConversion(TeXEnvironment env) { + return (28.346456693f * TeXFormula.PIXELS_PER_POINT) / env.getSize(); + } + }, + + new UnitConversion() {//MM + public float getPixelConversion(TeXEnvironment env) { + return (2.8346456693f * TeXFormula.PIXELS_PER_POINT) / env.getSize(); + } + }, + + new UnitConversion() {//IN + public float getPixelConversion(TeXEnvironment env) { + return (72 * TeXFormula.PIXELS_PER_POINT) / env.getSize(); + } + }, + + new UnitConversion() {//SP + public float getPixelConversion(TeXEnvironment env) { + return (65536 * TeXFormula.PIXELS_PER_POINT) / env.getSize(); + } + }, + + new UnitConversion() {//PT (or Standard Anglo-American point) + public float getPixelConversion(TeXEnvironment env) { + return (.9962640099f * TeXFormula.PIXELS_PER_POINT) / env.getSize(); + } + }, + + new UnitConversion() {//DD + public float getPixelConversion(TeXEnvironment env) { + return (1.0660349422f * TeXFormula.PIXELS_PER_POINT) / env.getSize(); + } + }, + + new UnitConversion() {//CC + public float getPixelConversion(TeXEnvironment env) { + return (12.7924193070f * TeXFormula.PIXELS_PER_POINT) / env.getSize(); + } + }, + + new UnitConversion() {//X8 + public float getPixelConversion(TeXEnvironment env) { + return env.getTeXFont().getDefaultRuleThickness(env.getStyle()); + } + } + }; + + // whether a hard space should be represented + private boolean blankSpace; + + // thinmuskip, medmuskip, thickmuskip + private int blankType; + + // dimensions + private float width; + private float height; + private float depth; + + // units for the dimensions + private int wUnit; + private int hUnit; + private int dUnit; + + public SpaceAtom() { + blankSpace = true; + } + + public SpaceAtom(int type) { + blankSpace = true; + blankType = type; + } + + public SpaceAtom(int unit, float width, float height, float depth) throws InvalidUnitException { + // check if unit is valid + checkUnit(unit); + + // unit valid + this.wUnit = unit; + this.hUnit = unit; + this.dUnit = unit; + this.width = width; + this.height = height; + this.depth = depth; + } + + /** + * Check if the given unit is valid + * + * @param unit the unit's integer representation (a constant) + * @throws InvalidUnitException if the given integer value does not represent + * a valid unit + */ + public static void checkUnit(int unit) throws InvalidUnitException { + if (unit < 0 || unit >= unitConversions.length) + throw new InvalidUnitException(); + } + + public SpaceAtom(int widthUnit, float width, int heightUnit, float height, + int depthUnit, float depth) throws InvalidUnitException { + // check if units are valid + checkUnit(widthUnit); + checkUnit(heightUnit); + checkUnit(depthUnit); + + // all units valid + wUnit = widthUnit; + hUnit = heightUnit; + dUnit = depthUnit; + this.width = width; + this.height = height; + this.depth = depth; + } + + public static int getUnit(String unit) { + Integer u = (Integer) units.get(unit); + return u == null ? TeXConstants.UNIT_PIXEL : u.intValue(); + } + + public static float[] getLength(String lgth) { + if (lgth == null) { + return new float[]{TeXConstants.UNIT_PIXEL, 0f}; + } + + int i = 0; + for (; i < lgth.length() && !Character.isLetter(lgth.charAt(i)); i++); + float f = 0; + try { + f = Float.parseFloat(lgth.substring(0, i)); + } catch (NumberFormatException e) { + return new float[]{Float.NaN}; + } + + int unit; + if (i != lgth.length()) { + unit = getUnit(lgth.substring(i).toLowerCase()); + } else { + unit = TeXConstants.UNIT_PIXEL; + } + + return new float[]{(float) unit, f}; + } + + public Box createBox(TeXEnvironment env) { + if (blankSpace) { + if (blankType == 0) + return new StrutBox(env.getSpace(), 0, 0, 0); + else { + int bl = blankType < 0 ? -blankType : blankType; + Box b; + if (bl == TeXConstants.THINMUSKIP) { + b = Glue.get(TeXConstants.TYPE_INNER, TeXConstants.TYPE_BIG_OPERATOR, env); + } else if (bl == TeXConstants.MEDMUSKIP) + b = Glue.get(TeXConstants.TYPE_BINARY_OPERATOR, TeXConstants.TYPE_BIG_OPERATOR, env); + else + b = Glue.get(TeXConstants.TYPE_RELATION, TeXConstants.TYPE_BIG_OPERATOR, env); + if (blankType < 0) + b.negWidth(); + return b; + } + } else { + return new StrutBox(width * getFactor(wUnit, env), height * getFactor(hUnit, env), depth * getFactor(dUnit, env), 0); + } + } + + public static float getFactor(int unit, TeXEnvironment env) { + return unitConversions[unit].getPixelConversion(env); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SsAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SsAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SsAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,67 @@ +/* SsAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a sans serif atom. + */ +public class SsAtom extends Atom { + + private Atom base; + + public SsAtom(Atom base) { + this.base = base; + } + + public Box createBox(TeXEnvironment env) { + env = env.copy(env.getTeXFont().copy()); + env.getTeXFont().setSs(true); + Box box = base.createBox(env); + env.getTeXFont().setSs(false); + return box; + } + +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/StrikeThroughAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/StrikeThroughAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/StrikeThroughAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,73 @@ +/* SmashedAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2013 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a smashed atom (i.e. with no height and no depth). + */ +public class StrikeThroughAtom extends Atom { + + private Atom at; + + public StrikeThroughAtom(Atom at) { + this.at = at; + } + + public Box createBox(TeXEnvironment env) { + TeXFont tf = env.getTeXFont(); + int style = env.getStyle(); + float axis = tf.getAxisHeight(style); + float drt = tf.getDefaultRuleThickness(style); + Box b = at.createBox(env); + HorizontalRule rule = new HorizontalRule(drt, b.getWidth(), -axis + drt, false); + HorizontalBox hb = new HorizontalBox(); + hb.add(b); + hb.add(new StrutBox(-b.getWidth(), 0, 0, 0)); + hb.add(rule); + + return hb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/StrutBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/StrutBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/StrutBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,70 @@ +/* StrutBox.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Graphics2D; + +/** + * A box representing whitespace. + */ +public class StrutBox extends Box { + + public StrutBox(float w, float h, float d, float s) { + width = w; + height = h; + depth = d; + shift = s; + } + + public void draw(Graphics2D g2, float x, float y) { + // no visual effect + } + + public int getLastFontId() { + return TeXFont.NO_FONT; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/StyleAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/StyleAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/StyleAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,68 @@ +/* StyleAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a modification of style in a formula (e.g. textstyle or displaystyle). + */ +public class StyleAtom extends Atom { + + private int style; + private Atom at; + + public StyleAtom(int style, Atom at) { + this.style = style; + this.at = at; + } + + public Box createBox(TeXEnvironment env) { + int sstyle = env.getStyle(); + env.setStyle(style); + Box box = at.createBox(env); + env.setStyle(sstyle); + return box; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SymbolAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SymbolAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SymbolAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,206 @@ +/* SymbolAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet */ + +package org.scilab.forge.jlatexmath; + +import java.util.BitSet; +import java.util.Map; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; + +/** + * A box representing a symbol (a non-alphanumeric character). + */ +public class SymbolAtom extends CharSymbol { + + // whether it's is a delimiter symbol + private final boolean delimiter; + + // symbol name + private final String name; + + // contains all defined symbols + public static Map symbols; + + // contains all the possible valid symbol types + private static BitSet validSymbolTypes; + + private char unicode; + + static { + symbols = new TeXSymbolParser().readSymbols(); + + // set valid symbol types + validSymbolTypes = new BitSet(16); + validSymbolTypes.set(TeXConstants.TYPE_ORDINARY); + validSymbolTypes.set(TeXConstants.TYPE_BIG_OPERATOR); + validSymbolTypes.set(TeXConstants.TYPE_BINARY_OPERATOR); + validSymbolTypes.set(TeXConstants.TYPE_RELATION); + validSymbolTypes.set(TeXConstants.TYPE_OPENING); + validSymbolTypes.set(TeXConstants.TYPE_CLOSING); + validSymbolTypes.set(TeXConstants.TYPE_PUNCTUATION); + validSymbolTypes.set(TeXConstants.TYPE_ACCENT); + } + + public SymbolAtom(SymbolAtom s, int type) throws InvalidSymbolTypeException { + if (!validSymbolTypes.get(type)) + throw new InvalidSymbolTypeException( + "The symbol type was not valid! " + + "Use one of the symbol type constants from the class 'TeXConstants'."); + name = s.name; + this.type = type; + if (type == TeXConstants.TYPE_BIG_OPERATOR) + this.type_limits = TeXConstants.SCRIPT_NORMAL; + + delimiter = s.delimiter; + } + + /** + * Constructs a new symbol. This used by "TeXSymbolParser" and the symbol + * types are guaranteed to be valid. + * + * @param name symbol name + * @param type symbol type constant + * @param del whether the symbol is a delimiter + */ + public SymbolAtom(String name, int type, boolean del) { + this.name = name; + this.type = type; + if (type == TeXConstants.TYPE_BIG_OPERATOR) + this.type_limits = TeXConstants.SCRIPT_NORMAL; + + delimiter = del; + } + + public SymbolAtom setUnicode(char c) { + this.unicode = c; + return this; + } + + public char getUnicode() { + return unicode; + } + + public static void addSymbolAtom(String file) { + FileInputStream in; + try { + in = new FileInputStream(file); + } catch (FileNotFoundException e) { + throw new ResourceParseException(file, e); + } + addSymbolAtom(in, file); + } + + public static void addSymbolAtom(InputStream in, String name) { + TeXSymbolParser tsp = new TeXSymbolParser(in, name); + symbols.putAll(tsp.readSymbols()); + } + + public static void addSymbolAtom(SymbolAtom sym) { + symbols.put(sym.name, sym); + } + + /** + * Looks up the name in the table and returns the corresponding SymbolAtom representing + * the symbol (if it's found). + * + * @param name the name of the symbol + * @return a SymbolAtom representing the found symbol + * @throws SymbolNotFoundException if no symbol with the given name was found + */ + public static SymbolAtom get(String name) throws SymbolNotFoundException { + Object obj = symbols.get(name); + if (obj == null) // not found + throw new SymbolNotFoundException(name); + else + return (SymbolAtom) obj; + } + + /** + * + * @return true if this symbol can act as a delimiter to embrace formulas + */ + public boolean isDelimiter() { + return delimiter; + } + + public String getName() { + return name; + } + + public Box createBox(TeXEnvironment env) { + TeXFont tf = env.getTeXFont(); + int style = env.getStyle(); + Char c = tf.getChar(name, style); + Box cb = new CharBox(c); + if (env.getSmallCap() && unicode != 0 && Character.isLowerCase(unicode)) { + try { + cb = new ScaleBox(new CharBox(tf.getChar(TeXFormula.symbolTextMappings[Character.toUpperCase(unicode)], style)), 0.8, 0.8); + } catch (SymbolMappingNotFoundException e) { } + } + + if (type == TeXConstants.TYPE_BIG_OPERATOR) { + if (style < TeXConstants.STYLE_TEXT && tf.hasNextLarger(c)) + c = tf.getNextLarger(c, style); + cb = new CharBox(c); + cb.setShift(-(cb.getHeight() + cb.getDepth()) / 2 - env.getTeXFont().getAxisHeight(env.getStyle())); + float delta = c.getItalic(); + HorizontalBox hb = new HorizontalBox(cb); + if (delta > TeXFormula.PREC) + hb.add(new StrutBox(delta, 0, 0, 0)); + return hb; + } + return cb; + } + + public CharFont getCharFont(TeXFont tf) { + // style doesn't matter here + return tf.getChar(name, TeXConstants.STYLE_DISPLAY).getCharFont(); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SymbolMappingNotFoundException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SymbolMappingNotFoundException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SymbolMappingNotFoundException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,61 @@ +/* SymbolMappingNotFoundException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals a missing symbol mapping. + * + * @author Kurt Vermeulen + */ +public class SymbolMappingNotFoundException extends JMathTeXException { + + protected SymbolMappingNotFoundException(String symbolName) { + super("No mapping found for the symbol '" + symbolName + "'! " + + "Insert a <" + DefaultTeXFontParser.SYMBOL_MAPPING_EL + + ">-element in '" + DefaultTeXFontParser.RESOURCE_NAME + "'."); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SymbolNotFoundException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SymbolNotFoundException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/SymbolNotFoundException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,61 @@ +/* SymbolNotFoundException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals that an unknown symbol was used. + * + * @author Kurt Vermeulen + */ +public class SymbolNotFoundException extends JMathTeXException { + + protected SymbolNotFoundException(String name) { + super("There's no symbol with the name '" + name + "' defined in '" + + TeXSymbolParser.RESOURCE_NAME + "'!"); + } + +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TStrokeAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TStrokeAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TStrokeAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,109 @@ +/* TStrokeAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom with a stroked T + */ +public class TStrokeAtom extends Atom { + + private boolean upper; + + public TStrokeAtom(boolean upper) { + this.upper = upper; + } + + public Box createBox(TeXEnvironment env) { + Char ch = env.getTeXFont().getChar("bar", env.getStyle()); + float italic = ch.getItalic(); + CharBox T = new CharBox(env.getTeXFont().getChar(upper ? 'T' : 't', "mathnormal", env.getStyle())); + CharBox B = new CharBox(ch); + Box y; + if (Math.abs(italic) > TeXFormula.PREC) { + y = new HorizontalBox(new StrutBox(-italic, 0, 0, 0)); + y.add(B); + } else + y = B; + Box b = new HorizontalBox(y, T.getWidth(), TeXConstants.ALIGN_CENTER); + VerticalBox vb = new VerticalBox(); + vb.add(T); + vb.add(new StrutBox(0, -0.5f * T.getHeight(), 0, 0)); + vb.add(b); + return vb; + } +} + /*if (upper) + hb.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.7f, 0, 0).createBox(env)); + else + hb.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.3f, 0, 0).createBox(env)); + hb.add(A); + return hb; + } + + public Box createBox(TeXEnvironment env) { + Box b = base.createBox(env); + VerticalBox vb = new VerticalBox(); + vb.add(b); + Char ch = env.getTeXFont().getChar("ogonek", env.getStyle()); + float italic = ch.getItalic(); + float x = new SpaceAtom(TeXConstants.UNIT_MU, 1f, 0, 0).createBox(env).getWidth(); + Box ogonek = new CharBox(ch); + Box y; + if (Math.abs(italic) > TeXFormula.PREC) { + y = new HorizontalBox(new StrutBox(-italic, 0, 0, 0)); + y.add(ogonek); + } else + y = ogonek; + + Box og = new HorizontalBox(y, b.getWidth(), TeXConstants.ALIGN_RIGHT); + vb.add(new StrutBox(0, -ogonek.getHeight(), 0, 0)); + vb.add(og); + float f = vb.getHeight() + vb.getDepth(); + vb.setHeight(b.getHeight()); + vb.setDepth(f - b.getHeight()); + return vb; + } +}*/ Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXConstants.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXConstants.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXConstants.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,359 @@ +/* TeXConstants.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet */ + +package org.scilab.forge.jlatexmath; + +/** + * The collection of constants that can be used in the methods of the classes of + * this package. + */ +public class TeXConstants { + + // ******************* + // ALIGNMENT CONSTANTS + // ******************* + + /** + * Alignment constant: extra space will be added to the right of the formula + */ + public static final int ALIGN_LEFT = 0; + + /** + * Alignment constant: extra space will be added to the left of the formula + */ + public static final int ALIGN_RIGHT = 1; + + /** + * Alignment constant: the formula will be centered in the middle. This constant + * can be used for both horizontal and vertical alignment. + */ + public static final int ALIGN_CENTER = 2; + + /** + * Alignment constant: extra space will be added under the formula + */ + public static final int ALIGN_TOP = 3; + + /** + * Alignment constant: extra space will be added above the formula + */ + public static final int ALIGN_BOTTOM = 4; + + /** + * Alignment constant: none + */ + public static final int ALIGN_NONE = 5; + + public static final int THINMUSKIP = 1; + public static final int MEDMUSKIP = 2; + public static final int THICKMUSKIP = 3; + public static final int NEGTHINMUSKIP = -1; + public static final int NEGMEDMUSKIP = -2; + public static final int NEGTHICKMUSKIP = -3; + + public static final int QUAD = 3; + + public static final int SCRIPT_NORMAL = 0; + public static final int SCRIPT_NOLIMITS = 1; + public static final int SCRIPT_LIMITS = 2; + + // ********************* + // SYMBOL TYPE CONSTANTS + // ********************* + + /** + * Symbol/Atom type: ordinary symbol, e.g. "slash" + */ + public static final int TYPE_ORDINARY = 0; + + /** + * Symbol/Atom type: big operator (= large operator), e.g. "sum" + */ + public static final int TYPE_BIG_OPERATOR = 1; + + /** + * Symbol/Atom type: binary operator, e.g. "plus" + */ + public static final int TYPE_BINARY_OPERATOR = 2; + + /** + * Symbol/Atom type: relation, e.g. "equals" + */ + public static final int TYPE_RELATION = 3; + + /** + * Symbol/Atom type: opening symbol, e.g. "lbrace" + */ + public static final int TYPE_OPENING = 4; + + /** + * Symbol/Atom type: closing symbol, e.g. "rbrace" + */ + public static final int TYPE_CLOSING = 5; + + /** + * Symbol/Atom type: punctuation symbol, e.g. "comma" + */ + public static final int TYPE_PUNCTUATION = 6; + + /** + * Atom type: inner atom (NOT FOR SYMBOLS!!!) + */ + public static final int TYPE_INNER = 7; + + /** + * Symbol type: accent, e.g. "hat" + */ + public static final int TYPE_ACCENT = 10; + + public static final int TYPE_INTERTEXT = 11; + + public static final int TYPE_MULTICOLUMN = 12; + + public static final int TYPE_HLINE = 13; + + // *************************************** + // OVER AND UNDER DELIMITER TYPE CONSTANTS + // *************************************** + + /** + * Delimiter type constant for putting delimiters over and under formula's: brace + */ + public static final int DELIM_BRACE = 0; + + /** + * Delimiter type constant for putting delimiters over and under formula's: square bracket + */ + public static final int DELIM_SQUARE_BRACKET = 1; + + /** + * Delimiter type constant for putting delimiters over and under formula's: parenthesis + */ + public static final int DELIM_BRACKET = 2; + + /** + * Delimiter type constant for putting delimiters over and under formula's: + * arrow with single line pointing to the left + */ + public static final int DELIM_LEFT_ARROW = 3; + + /** + * Delimiter type constant for putting delimiters over and under formula's: + * arrow with single line pointing to the right + */ + public static final int DELIM_RIGHT_ARROW = 4; + + /** + * Delimiter type constant for putting delimiters over and under formula's: + * arrow with single line pointing to the left and to the right + */ + public static final int DELIM_LEFT_RIGHT_ARROW = 5; + + /** + * Delimiter type constant for putting delimiters over and under formula's: + * arrow with two lines pointing to the left + */ + public static final int DELIM_DOUBLE_LEFT_ARROW = 6; + + /** + * Delimiter type constant for putting delimiters over and under formula's: + * arrow with two lines pointing to the right + */ + public static final int DELIM_DOUBLE_RIGHT_ARROW = 7; + + /** + * Delimiter type constant for putting delimiters over and under formula's: + * arrow with two lines pointing to the left and to the right + */ + public static final int DELIM_DOUBLE_LEFT_RIGHT_ARROW = 8; + + /** + * Delimiter type constant for putting delimiters over and under formula's: + * underline once + */ + public static final int DELIM_SINGLE_LINE = 9; + + /** + * Delimiter type constant for putting delimiters over and under formula's: + * underline twice + */ + public static final int DELIM_DOUBLE_LINE = 10; + + // ******************* + // TEX STYLE CONSTANTS + // ******************* + + /** + * TeX style: display style. + *

+ * The large versions of big operators are used and limits are placed under and over + * these operators (default). Symbols are rendered in the largest size. + */ + public static final int STYLE_DISPLAY = 0; + + /** + * TeX style: text style. + *

+ * The small versions of big operators are used and limits are attached to + * these operators as scripts (default). The same size as in the display style + * is used to render symbols. + */ + public static final int STYLE_TEXT = 2; + + /** + * TeX style: script style. + *

+ * The same as the text style, but symbols are rendered in a smaller size. + */ + public static final int STYLE_SCRIPT = 4; + + /** + * TeX style: script_script style. + *

+ * The same as the script style, but symbols are rendered in a smaller size. + */ + public static final int STYLE_SCRIPT_SCRIPT = 6; + + // ************** + // UNIT CONSTANTS + // ************** + + /** + * Unit constant: em + *

+ * 1 em = the width of the capital 'M' in the current font + */ + public static final int UNIT_EM = 0; + + /** + * Unit constant: ex + *

+ * 1 ex = the height of the character 'x' in the current font + */ + public static final int UNIT_EX = 1; + + /** + * Unit constant: pixel + */ + public static final int UNIT_PIXEL = 2; + + /** + * Unit constant: postscript point + */ + public static final int UNIT_POINT = 3; + + /** + * Unit constant: pica + *

+ * 1 pica = 12 point + */ + public static final int UNIT_PICA = 4; + + /** + * Unit constant: math unit (mu) + *

+ * 1 mu = 1/18 em (em taken from the "mufont") + */ + public static final int UNIT_MU = 5; + + /** + * Unit constant: cm + *

+ * 1 cm = 28.346456693 point + */ + public static final int UNIT_CM = 6; + + /** + * Unit constant: mm + *

+ * 1 mm = 2.8346456693 point + */ + public static final int UNIT_MM = 7; + + /** + * Unit constant: in + *

+ * 1 in = 72 point + */ + public static final int UNIT_IN = 8; + + /** + * Unit constant: sp + *

+ * 1 sp = 65536 point + */ + public static final int UNIT_SP = 9; + + /** + * Unit constant: in + *

+ * 1 in = 72.27 pt + */ + public static final int UNIT_PT = 10; + + /** + * Unit constant: in + *

+ * 1 in = 72 point + */ + public static final int UNIT_DD = 11; + + /** + * Unit constant: in + *

+ * 1 in = 72 point + */ + public static final int UNIT_CC = 12; + + /** + * Unit constant: x8 + *

+ * 1 s8 = 1 default rule thickness + */ + public static final int UNIT_X8 = 13; +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXEnvironment.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXEnvironment.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXEnvironment.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,309 @@ +/* TeXEnvironment.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Color; + +/** + * Contains the used TeXFont-object, color settings and the current style in which a + * formula must be drawn. It's used in the createBox-methods. Contains methods that + * apply the style changing rules for subformula's. + */ +public class TeXEnvironment { + + // colors + private Color background = null, color = null; + + // current style + private int style = TeXConstants.STYLE_DISPLAY; + + // TeXFont used + private TeXFont tf; + + // last used font + private int lastFontId = TeXFont.NO_FONT; + + private float textwidth = Float.POSITIVE_INFINITY; + + private String textStyle; + private boolean smallCap; + private float scaleFactor = 1; + private int interlineUnit; + private float interline; + + public boolean isColored = false; + + public TeXEnvironment(int style, TeXFont tf) { + this(style, tf, null, null); + } + + public TeXEnvironment(int style, TeXFont tf, int widthUnit, float textwidth) { + this(style, tf, null, null); + this.textwidth = textwidth * SpaceAtom.getFactor(widthUnit, this); + } + + private TeXEnvironment(int style, TeXFont tf, Color bg, Color c) { + this.style = style; + this.tf = tf; + background = bg; + color = c; + setInterline(TeXConstants.UNIT_EX, 1f); + } + + private TeXEnvironment(int style, float scaleFactor, TeXFont tf, Color bg, Color c, String textStyle, boolean smallCap) { + this.style = style; + this.scaleFactor = scaleFactor; + this.tf = tf; + this.textStyle = textStyle; + this.smallCap = smallCap; + background = bg; + color = c; + setInterline(TeXConstants.UNIT_EX, 1f); + } + + public void setInterline(int unit, float len) { + this.interline = len; + this.interlineUnit = unit; + } + + public float getInterline() { + return interline * SpaceAtom.getFactor(interlineUnit, this); + } + + public void setTextwidth(int widthUnit, float textwidth) { + this.textwidth = textwidth * SpaceAtom.getFactor(widthUnit, this); + } + + public float getTextwidth() { + return textwidth; + } + + public void setScaleFactor(float f) { + scaleFactor = f; + } + + public float getScaleFactor() { + return scaleFactor; + } + + protected TeXEnvironment copy() { + return new TeXEnvironment(style, scaleFactor, tf, background, color, textStyle, smallCap); + } + + protected TeXEnvironment copy(TeXFont tf) { + TeXEnvironment te = new TeXEnvironment(style, scaleFactor, tf, background, color, textStyle, smallCap); + te.textwidth = textwidth; + te.interline = interline; + te.interlineUnit = interlineUnit; + return te; + } + + /** + * @return a copy of the environment, but in a cramped style. + */ + public TeXEnvironment crampStyle() { + TeXEnvironment s = copy(); + s.style = (style % 2 == 1 ? style : style + 1); + return s; + } + + /** + * + * @return a copy of the environment, but in denominator style. + */ + public TeXEnvironment denomStyle() { + TeXEnvironment s = copy(); + s.style = 2 * (style / 2) + 1 + 2 - 2 * (style / 6); + return s; + } + + /** + * + * @return the background color setting + */ + public Color getBackground() { + return background; + } + + /** + * + * @return the foreground color setting + */ + public Color getColor() { + return color; + } + + /** + * + * @return the point size of the TeXFont + */ + public float getSize() { + return tf.getSize(); + } + + /** + * + * @return the current style + */ + public int getStyle() { + return style; + } + + public void setStyle(int style) { + this.style = style; + } + + /** + * @return the current textStyle + */ + public String getTextStyle() { + return textStyle; + } + + public void setTextStyle(String textStyle) { + this.textStyle = textStyle; + } + + /** + * @return the current textStyle + */ + public boolean getSmallCap() { + return smallCap; + } + + public void setSmallCap(boolean smallCap) { + this.smallCap = smallCap; + } + + /** + * + * @return the TeXFont to be used + */ + public TeXFont getTeXFont() { + return tf; + } + + /** + * + * @return a copy of the environment, but in numerator style. + */ + public TeXEnvironment numStyle() { + TeXEnvironment s = copy(); + s.style = style + 2 - 2 * (style / 6); + return s; + } + + /** + * Resets the color settings. + * + */ + public void reset() { + color = null; + background = null; + } + + /** + * + * @return a copy of the environment, but with the style changed for roots + */ + public TeXEnvironment rootStyle() { + TeXEnvironment s = copy(); + s.style = TeXConstants.STYLE_SCRIPT_SCRIPT; + return s; + } + + /** + * + * @param c the background color to be set + */ + public void setBackground(Color c) { + background = c; + } + + /** + * + * @param c the foreground color to be set + */ + public void setColor(Color c) { + color = c; + } + + /** + * + * @return a copy of the environment, but in subscript style. + */ + public TeXEnvironment subStyle() { + TeXEnvironment s = copy(); + s.style = 2 * (style / 4) + 4 + 1; + return s; + } + + /** + * + * @return a copy of the environment, but in superscript style. + */ + public TeXEnvironment supStyle() { + TeXEnvironment s = copy(); + s.style = 2 * (style / 4) + 4 + (style % 2); + return s; + } + + public float getSpace() { + return tf.getSpace(style) * tf.getScaleFactor(); + } + + public void setLastFontId(int id) { + lastFontId = id; + } + + public int getLastFontId() { + // if there was no last font id (whitespace boxes only), use default "mu font" + return (lastFontId == TeXFont.NO_FONT ? tf.getMuFontId() : lastFontId); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXFont.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXFont.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXFont.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,261 @@ +/* TeXFont.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An interface representing a "TeXFont", which is responsible for all the necessary + * fonts and font information. + * + * @author Kurt Vermeulen + */ +public interface TeXFont { + + public static final int NO_FONT = -1; + + /** + * Derives a new {@link TeXFont} object with the given point size + * + * @param pointSize the new size (in points) of the derived {@link TeXFont} + * @return a copy of this {@link TeXFont} with the new size + */ + public TeXFont deriveFont(float pointSize); + + public TeXFont scaleFont(float factor); + + public float getScaleFactor(); + + public float getAxisHeight(int style); + + public float getBigOpSpacing1(int style); + + public float getBigOpSpacing2(int style); + + public float getBigOpSpacing3(int style); + + public float getBigOpSpacing4(int style); + + public float getBigOpSpacing5(int style); + + /** + * Get a Char-object specifying the given character in the given text style with + * metric information depending on the given "style". + * + * @param c alphanumeric character + * @param textStyle the text style in which the character should be drawn + * @param style the style in which the atom should be drawn + * @return the Char-object specifying the given character in the given text style + * @throws TextStyleMappingNotFoundException if there's no text style defined with + * the given name + */ + public Char getChar(char c, String textStyle, int style) + throws TextStyleMappingNotFoundException; + + /** + * Get a Char-object for this specific character containing the metric information + * + * @param cf CharFont-object determining a specific character of a specific font + * @param style the style in which the atom should be drawn + * @return the Char-object for this character containing metric information + */ + public Char getChar(CharFont cf, int style); + + /** + * Get a Char-object for the given symbol with metric information depending on + * "style". + * + * @param name the symbol name + * @param style the style in which the atom should be drawn + * @return a Char-object for this symbol with metric information + * @throws SymbolMappingNotFoundException if there's no symbol defined with the given + * name + */ + public Char getChar(String name, int style) + throws SymbolMappingNotFoundException; + + /** + * Get a Char-object specifying the given character in the default text style with + * metric information depending on the given "style". + * + * @param c alphanumeric character + * @param style the style in which the atom should be drawn + * @return the Char-object specifying the given character in the default text style + */ + public Char getDefaultChar(char c, int style); + + public float getDefaultRuleThickness(int style); + + public float getDenom1(int style); + + public float getDenom2(int style); + + /** + * Get an Extension-object for the given Char containing the 4 possible parts to + * build an arbitrary large variant. This will only be called if isExtensionChar(Char) + * returns true. + * + * @param c a Char-object for a specific character + * @param style the style in which the atom should be drawn + * @return an Extension object containing the 4 possible parts + */ + public Extension getExtension(Char c, int style); + + /** + * Get the kern value to be inserted between the given characters in the given style. + * + * @param left left character + * @param right right character + * @param style the style in which the atom should be drawn + * @return the kern value between both characters (default 0) + */ + public float getKern(CharFont left, CharFont right, int style); + + /** + * Get the ligature that replaces both characters (if any). + * + * @param left left character + * @param right right character + * @return a ligature replacing both characters (or null: no ligature) + */ + public CharFont getLigature(CharFont left, CharFont right); + + public int getMuFontId(); + + /** + * Get the next larger version of the given character. This is only called if + * hasNextLarger(Char) returns true. + * + * @param c character + * @param style the style in which the atom should be drawn + * @return the next larger version of this character + */ + public Char getNextLarger(Char c, int style); + + public float getNum1(int style); + + public float getNum2(int style); + + public float getNum3(int style); + + public float getQuad(int style, int fontCode); + + /** + * + * @return the point size of this TeXFont + */ + public float getSize(); + + /** + * Get the kern amount of the character defined by the given CharFont followed by the + * "skewchar" of it's font. This is used in the algorithm for placing an accent above + * a single character. + * + * @param cf the character and it's font above which an accent has to be placed + * @param style the render style + * @return the kern amount of the character defined by cf followed by the + * "skewchar" of it's font. + */ + public float getSkew(CharFont cf, int style); + + public float getSpace(int style); + + public float getSub1(int style); + + public float getSub2(int style); + + public float getSubDrop(int style); + + public float getSup1(int style); + + public float getSup2(int style); + + public float getSup3(int style); + + public float getSupDrop(int style); + + public float getXHeight(int style, int fontCode); + + public float getEM(int style); + + /** + * + * @param c a character + * @return true if the given character has a larger version, false otherwise + */ + public boolean hasNextLarger(Char c); + + public boolean hasSpace(int font); + + public void setBold(boolean bold); + + public boolean getBold(); + + public void setRoman(boolean rm); + + public boolean getRoman(); + + public void setTt(boolean tt); + + public boolean getTt(); + + public void setIt(boolean it); + + public boolean getIt(); + + public void setSs(boolean ss); + + public boolean getSs(); + + /** + * + * @param c a character + * @return true if the given character contains extension information to buid + * an arbitrary large version of this character. + */ + public boolean isExtensionChar(Char c); + + public TeXFont copy(); +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXFormula.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXFormula.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXFormula.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,1065 @@ +/* TeXFormula.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet */ + +package org.scilab.forge.jlatexmath; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.List; +import java.util.LinkedList; +import java.util.Set; +import java.util.Stack; +import java.io.InputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.Insets; +import java.awt.image.BufferedImage; +import java.awt.GraphicsEnvironment; +import java.awt.Image; +import java.awt.Toolkit; +import javax.imageio.ImageIO; +import javax.imageio.stream.FileImageOutputStream; +import java.lang.Character.UnicodeBlock; + +/** + * Represents a logical mathematical formula that will be displayed (by creating a + * {@link TeXIcon} from it and painting it) using algorithms that are based on the + * TeX algorithms. + *

+ * These formula's can be built using the built-in primitive TeX parser + * (methods with String arguments) or using other TeXFormula objects. Most methods + * have (an) equivalent(s) where one or more TeXFormula arguments are replaced with + * String arguments. These are just shorter notations, because all they do is parse + * the string(s) to TeXFormula's and call an equivalent method with (a) TeXFormula argument(s). + * Most methods also come in 2 variants. One kind will use this TeXFormula to build + * another mathematical construction and then change this object to represent the newly + * build construction. The other kind will only use other + * TeXFormula's (or parse strings), build a mathematical construction with them and + * insert this newly build construction at the end of this TeXFormula. + * Because all the provided methods return a pointer to this (modified) TeXFormula + * (except for the createTeXIcon method that returns a TeXIcon pointer), + * method chaining is also possible. + *

+ * Important: All the provided methods modify this TeXFormula object, but all the + * TeXFormula arguments of these methods will remain unchanged and independent of + * this TeXFormula object! + */ +public class TeXFormula { + + public static final String VERSION = "1.0.3"; + + public static final int SERIF = 0; + public static final int SANSSERIF = 1; + public static final int BOLD = 2; + public static final int ITALIC = 4; + public static final int ROMAN = 8; + public static final int TYPEWRITER = 16; + + // table for putting delimiters over and under formula's, + // indexed by constants from "TeXConstants" + private static final String[][] delimiterNames = { + { "lbrace", "rbrace" }, + { "lsqbrack", "rsqbrack" }, + { "lbrack", "rbrack" }, + { "downarrow", "downarrow" }, + { "uparrow", "uparrow" }, + { "updownarrow", "updownarrow" }, + { "Downarrow", "Downarrow" }, + { "Uparrow", "Uparrow" }, + { "Updownarrow", "Updownarrow" }, + { "vert", "vert" }, + { "Vert", "Vert" } + }; + + // point-to-pixel conversion + public static float PIXELS_PER_POINT = 1f; + + // used as second index in "delimiterNames" table (over or under) + private static final int OVER_DEL = 0; + private static final int UNDER_DEL = 1; + + // for comparing floats with 0 + protected static final float PREC = 0.0000001f; + + // predefined TeXFormula's + public static Map predefinedTeXFormulas = new HashMap(150); + public static Map predefinedTeXFormulasAsString = new HashMap(150); + + // character-to-symbol and character-to-delimiter mappings + public static String[] symbolMappings = new String[65536]; + public static String[] symbolTextMappings = new String[65536]; + public static String[] symbolFormulaMappings = new String[65536]; + public static Map externalFontMap = new HashMap(); + + public List middle = new LinkedList(); + + protected Map jlmXMLMap; + private TeXParser parser; + + static { + // character-to-symbol and character-to-delimiter mappings + TeXFormulaSettingsParser parser = new TeXFormulaSettingsParser(); + parser.parseSymbolMappings(symbolMappings, symbolTextMappings); + + new PredefinedCommands(); + new PredefinedTeXFormulas(); + new PredefMacros(); + + parser.parseSymbolToFormulaMappings(symbolFormulaMappings, symbolTextMappings); + + try { + DefaultTeXFont.registerAlphabet((AlphabetRegistration) Class.forName("org.scilab.forge.jlatexmath.cyrillic.CyrillicRegistration").newInstance()); + DefaultTeXFont.registerAlphabet((AlphabetRegistration) Class.forName("org.scilab.forge.jlatexmath.greek.GreekRegistration").newInstance()); + } catch (Exception e) { } + + //setDefaultDPI(); + } + + public static void addSymbolMappings(String file) throws ResourceParseException { + FileInputStream in; + try { + in = new FileInputStream(file); + } catch (FileNotFoundException e) { + throw new ResourceParseException(file, e); + } + addSymbolMappings(in, file); + } + + public static void addSymbolMappings(InputStream in, String name) throws ResourceParseException { + TeXFormulaSettingsParser tfsp = new TeXFormulaSettingsParser(in, name); + tfsp.parseSymbolMappings(symbolMappings, symbolTextMappings); + tfsp.parseSymbolToFormulaMappings(symbolFormulaMappings, symbolTextMappings); + } + + public static boolean isRegisteredBlock(Character.UnicodeBlock block) { + return externalFontMap.get(block) != null; + } + + public static FontInfos getExternalFont(Character.UnicodeBlock block) { + FontInfos infos = externalFontMap.get(block); + if (infos == null) { + infos = new FontInfos("SansSerif", "Serif"); + externalFontMap.put(block, infos); + } + + return infos; + } + + public static void registerExternalFont(Character.UnicodeBlock block, String sansserif, String serif) { + if (sansserif == null && serif == null) { + externalFontMap.remove(block); + return; + } + externalFontMap.put(block, new FontInfos(sansserif, serif)); + if (block.equals(Character.UnicodeBlock.BASIC_LATIN)) { + predefinedTeXFormulas.clear(); + } + } + + public static void registerExternalFont(Character.UnicodeBlock block, String fontName) { + registerExternalFont(block, fontName, fontName); + } + + /** + * Set the DPI of target + * @param dpi the target DPI + */ + public static void setDPITarget(float dpi) { + PIXELS_PER_POINT = dpi / 72f; + } + + /** + * Set the default target DPI to the screen dpi (only if we're in non-headless mode) + */ + public static void setDefaultDPI() { + if (!GraphicsEnvironment.isHeadless()) { + setDPITarget((float) Toolkit.getDefaultToolkit().getScreenResolution()); + } + } + + // the root atom of the "atom tree" that represents the formula + public Atom root = null; + + // the current text style + public String textStyle = null; + + public boolean isColored = false; + + /** + * Creates an empty TeXFormula. + * + */ + public TeXFormula() { + parser = new TeXParser("", this, false); + } + + /** + * Creates a new TeXFormula by parsing the given string (using a primitive TeX parser). + * + * @param s the string to be parsed + * @throws ParseException if the string could not be parsed correctly + */ + public TeXFormula(String s, Map map) throws ParseException { + this.jlmXMLMap = map; + this.textStyle = textStyle; + parser = new TeXParser(s, this); + parser.parse(); + } + + /** + * Creates a new TeXFormula by parsing the given string (using a primitive TeX parser). + * + * @param s the string to be parsed + * @throws ParseException if the string could not be parsed correctly + */ + public TeXFormula(String s) throws ParseException { + this(s, (String) null); + } + + public TeXFormula(String s, boolean firstpass) throws ParseException { + this.textStyle = null; + parser = new TeXParser(s, this, firstpass); + parser.parse(); + } + + /* + * Creates a TeXFormula by parsing the given string in the given text style. + * Used when a text style command was found in the parse string. + */ + public TeXFormula(String s, String textStyle) throws ParseException { + this.textStyle = textStyle; + parser = new TeXParser(s, this); + parser.parse(); + } + + public TeXFormula(String s, String textStyle, boolean firstpass, boolean space) throws ParseException { + this.textStyle = textStyle; + parser = new TeXParser(s, this, firstpass, space); + parser.parse(); + } + + /** + * Creates a new TeXFormula that is a copy of the given TeXFormula. + *

+ * Both TeXFormula's are independent of one another! + * + * @param f the formula to be copied + */ + public TeXFormula(TeXFormula f) { + if (f != null) { + addImpl(f); + } + } + + /** + * Creates an empty TeXFormula. + * + */ + protected TeXFormula(TeXParser tp) { + this.jlmXMLMap = tp.formula.jlmXMLMap; + parser = new TeXParser(tp.getIsPartial(), "", this, false); + } + + /** + * Creates a new TeXFormula by parsing the given string (using a primitive TeX parser). + * + * @param s the string to be parsed + * @throws ParseException if the string could not be parsed correctly + */ + protected TeXFormula(TeXParser tp, String s) throws ParseException { + this(tp, s, null); + } + + protected TeXFormula(TeXParser tp, String s, boolean firstpass) throws ParseException { + this.textStyle = null; + this.jlmXMLMap = tp.formula.jlmXMLMap; + boolean isPartial = tp.getIsPartial(); + parser = new TeXParser(isPartial, s, this, firstpass); + if (isPartial) { + try { + parser.parse(); + } catch (Exception e) { } + } else { + parser.parse(); + } + } + + /* + * Creates a TeXFormula by parsing the given string in the given text style. + * Used when a text style command was found in the parse string. + */ + protected TeXFormula(TeXParser tp, String s, String textStyle) throws ParseException { + this.textStyle = textStyle; + this.jlmXMLMap = tp.formula.jlmXMLMap; + boolean isPartial = tp.getIsPartial(); + parser = new TeXParser(isPartial, s, this); + if (isPartial) { + try { + parser.parse(); + } catch (Exception e) { + if (root == null) { + root = new EmptyAtom(); + } + } + } else { + parser.parse(); + } + } + + protected TeXFormula(TeXParser tp, String s, String textStyle, boolean firstpass, boolean space) throws ParseException { + this.textStyle = textStyle; + this.jlmXMLMap = tp.formula.jlmXMLMap; + boolean isPartial = tp.getIsPartial(); + parser = new TeXParser(isPartial, s, this, firstpass, space); + if (isPartial) { + try { + parser.parse(); + } catch (Exception e) { + if (root == null) { + root = new EmptyAtom(); + } + } + } else { + parser.parse(); + } + } + + public static TeXFormula getAsText(String text, int alignment) throws ParseException { + TeXFormula formula = new TeXFormula(); + if (text == null || "".equals(text)) { + formula.add(new EmptyAtom()); + return formula; + } + + String[] arr = text.split("\n|\\\\\\\\|\\\\cr"); + ArrayOfAtoms atoms = new ArrayOfAtoms(); + for (String s : arr) { + TeXFormula f = new TeXFormula(s, "mathnormal", true, false); + atoms.add(new RomanAtom(f.root)); + atoms.addRow(); + } + atoms.checkDimensions(); + formula.add(new MatrixAtom(false, atoms, MatrixAtom.ARRAY, alignment)); + + return formula; + } + + /** + * @param a formula + * @return a partial TeXFormula containing the valid part of formula + */ + public static TeXFormula getPartialTeXFormula(String formula) { + TeXFormula f = new TeXFormula(); + if (formula == null) { + f.add(new EmptyAtom()); + return f; + } + TeXParser parser = new TeXParser(true, formula, f); + try { + parser.parse(); + } catch (Exception e) { + if (f.root == null) { + f.root = new EmptyAtom(); + } + } + + return f; + } + + /** + * @param b true if the fonts should be registered (Java 1.6 only) to be used + * with FOP. + */ + public static void registerFonts(boolean b) { + DefaultTeXFontParser.registerFonts(b); + } + + /** + * Change the text of the TeXFormula and regenerate the root + * + * @param ltx the latex formula + */ + public void setLaTeX(String ltx) throws ParseException { + parser.reset(ltx); + if (ltx != null && ltx.length() != 0) + parser.parse(); + } + + /** + * Inserts an atom at the end of the current formula + */ + public TeXFormula add(Atom el) { + if (el != null) { + if (el instanceof MiddleAtom) + middle.add((MiddleAtom) el); + if (root == null) { + root = el; + } else { + if (!(root instanceof RowAtom)) { + root = new RowAtom(root); + } + ((RowAtom) root).add(el); + if (el instanceof TypedAtom) { + TypedAtom ta = (TypedAtom) el; + int rtype = ta.getRightType(); + if (rtype == TeXConstants.TYPE_BINARY_OPERATOR || rtype == TeXConstants.TYPE_RELATION) { + ((RowAtom) root).add(new BreakMarkAtom()); + } + } + } + } + return this; + } + + /** + * Parses the given string and inserts the resulting formula + * at the end of the current TeXFormula. + * + * @param s the string to be parsed and inserted + * @throws ParseException if the string could not be parsed correctly + * @return the modified TeXFormula + */ + public TeXFormula add(String s) throws ParseException { + if (s != null && s.length() != 0) { + // reset parsing variables + textStyle = null; + // parse and add the string + add(new TeXFormula(s)); + } + return this; + } + + public TeXFormula append(String s) throws ParseException { + return append(false, s); + } + + public TeXFormula append(boolean isPartial, String s) throws ParseException { + if (s != null && s.length() != 0) { + TeXParser tp = new TeXParser(isPartial, s, this); + tp.parse(); + } + return this; + } + + /** + * Inserts the given TeXFormula at the end of the current TeXFormula. + * + * @param f the TeXFormula to be inserted + * @return the modified TeXFormula + */ + public TeXFormula add(TeXFormula f) { + addImpl(f); + return this; + } + + private void addImpl(TeXFormula f) { + if (f.root != null) { + // special copy-treatment for Mrow as a root!! + if (f.root instanceof RowAtom) + add(new RowAtom(f.root)); + else + add(f.root); + } + } + + public void setLookAtLastAtom(boolean b) { + if (root instanceof RowAtom) + ((RowAtom)root).lookAtLastAtom = b; + } + + public boolean getLookAtLastAtom() { + if (root instanceof RowAtom) + return ((RowAtom)root).lookAtLastAtom; + return false; + } + + /** + * Centers the current TeXformula vertically on the axis (defined by the parameter + * "axisheight" in the resource "DefaultTeXFont.xml". + * + * @return the modified TeXFormula + */ + public TeXFormula centerOnAxis() { + root = new VCenteredAtom(root); + return this; + } + + public static void addPredefinedTeXFormula(InputStream xmlFile) throws ResourceParseException { + new PredefinedTeXFormulaParser(xmlFile, "TeXFormula").parse(predefinedTeXFormulas); + } + + public static void addPredefinedCommands(InputStream xmlFile) throws ResourceParseException { + new PredefinedTeXFormulaParser(xmlFile, "Command").parse(MacroInfo.Commands); + } + + /** + * Inserts a strut box (whitespace) with the given width, height and depth (in + * the given unit) at the end of the current TeXFormula. + * + * @param unit a unit constant (from {@link TeXConstants}) + * @param width the width of the strut box + * @param height the height of the strut box + * @param depth the depth of the strut box + * @return the modified TeXFormula + * @throws InvalidUnitException if the given integer value does not represent + * a valid unit + */ + public TeXFormula addStrut(int unit, float width, float height, float depth) + throws InvalidUnitException { + return add(new SpaceAtom(unit, width, height, depth)); + } + + /** + * Inserts a strut box (whitespace) with the given width, height and depth (in + * the given unit) at the end of the current TeXFormula. + * + * @param type thinmuskip, medmuskip or thickmuskip (from {@link TeXConstants}) + * @return the modified TeXFormula + * @throws InvalidUnitException if the given integer value does not represent + * a valid unit + */ + public TeXFormula addStrut(int type) + throws InvalidUnitException { + return add(new SpaceAtom(type)); + } + + /** + * Inserts a strut box (whitespace) with the given width (in widthUnits), height + * (in heightUnits) and depth (in depthUnits) at the end of the current TeXFormula. + * + * @param widthUnit a unit constant used for the width (from {@link TeXConstants}) + * @param width the width of the strut box + * @param heightUnit a unit constant used for the height (from TeXConstants) + * @param height the height of the strut box + * @param depthUnit a unit constant used for the depth (from TeXConstants) + * @param depth the depth of the strut box + * @return the modified TeXFormula + * @throws InvalidUnitException if the given integer value does not represent + * a valid unit + */ + public TeXFormula addStrut(int widthUnit, float width, int heightUnit, + float height, int depthUnit, float depth) throws InvalidUnitException { + return add(new SpaceAtom(widthUnit, width, heightUnit, height, depthUnit, + depth)); + } + + /* + * Convert this TeXFormula into a box, starting form the given style + */ + private Box createBox(TeXEnvironment style) { + if (root == null) + return new StrutBox(0, 0, 0, 0); + else + return root.createBox(style); + } + + private DefaultTeXFont createFont(float size, int type) { + DefaultTeXFont dtf = new DefaultTeXFont(size); + if (type == 0) { + dtf.setSs(false); + } + if ((type & ROMAN) != 0) { + dtf.setRoman(true); + } + if ((type & TYPEWRITER) != 0) { + dtf.setTt(true); + } + if ((type & SANSSERIF) != 0) { + dtf.setSs(true); + } + if ((type & ITALIC) != 0) { + dtf.setIt(true); + } + if ((type & BOLD) != 0) { + dtf.setBold(true); + } + + return dtf; + } + + /** + * Apply the Builder pattern instead of using the createTeXIcon(...) factories + * @author Felix Natter + * + */ + public class TeXIconBuilder { + private Integer style; + private Float size; + private Integer type; + private Color fgcolor; + private boolean trueValues = false; + private Integer widthUnit; + private Float textWidth; + private Integer align; + private boolean isMaxWidth = false; + private Integer interLineUnit; + private Float interLineSpacing; + + /** + * Specify the style for rendering the given TeXFormula + * @param style the style + * @return the builder, used for chaining + */ + public TeXIconBuilder setStyle(final int style) + { + this.style = style; + return this; + } + + /** + * Specify the font size for rendering the given TeXFormula + * @param size the size + * @return the builder, used for chaining + */ + public TeXIconBuilder setSize(final float size) + { + this.size = size; + return this; + } + + /** + * Specify the font type for rendering the given TeXFormula + * @param type the font type + * @return the builder, used for chaining + */ + public TeXIconBuilder setType(final int type) + { + this.type = type; + return this; + } + + /** + * Specify the background color for rendering the given TeXFormula + * @param fgcolor the foreground color + * @return the builder, used for chaining + */ + public TeXIconBuilder setFGColor(final Color fgcolor) + { + this.fgcolor = fgcolor; + return this; + } + + /** + * Specify the "true values" parameter for rendering the given TeXFormula + * @param trueValues the "true values" value + * @return the builder, used for chaining + */ + public TeXIconBuilder setTrueValues(final boolean trueValues) + { + this.trueValues = trueValues; + return this; + } + + /** + * Specify the width of the formula (may be exact or maximum width, see {@link #setIsMaxWidth(boolean)}) + * @param widthUnit the width unit + * @param textWidth the width + * @param align the alignment + * @return the builder, used for chaining + */ + public TeXIconBuilder setWidth(final int widthUnit, final float textWidth, final int align) + { + this.widthUnit = widthUnit; + this.textWidth = textWidth; + this.align = align; + trueValues = true; // TODO: is this necessary? + return this; + } + + /** + * Specifies whether the width is the exact or the maximum width + * @param isMaxWidth whether the width is a maximum width + * @return the builder, used for chaining + */ + public TeXIconBuilder setIsMaxWidth(final boolean isMaxWidth) + { + if (widthUnit == null) + { + throw new IllegalStateException("Cannot set 'isMaxWidth' without having specified a width!"); + } + if (isMaxWidth) + { + // NOTE: Currently isMaxWidth==true does not work with ALIGN_CENTER or ALIGN_RIGHT (see HorizontalBox ctor) + // The case (1) we don't support by setting align := ALIGN_LEFT here is this: + // \text{hello world\\hello} with align=ALIGN_CENTER (but forced to ALIGN_LEFT) and isMaxWidth==true results in: + // [hello world] + // [hello ] + // and NOT: + // [hello world] + // [ hello ] + // However, this case (2) is currently not supported anyway (ALIGN_CENTER with isMaxWidth==false): + // [ hello world ] + // [ hello ] + // and NOT: + // [ hello world ] + // [ hello ] + // => until (2) is solved, we stick with the hack to set align := ALIGN_LEFT! + this.align = TeXConstants.ALIGN_LEFT; + } + this.isMaxWidth = isMaxWidth; + return this; + } + + /** + * Specify the inter line spacing unit and value. NOTE: this is required for automatic linebreaks to work! + * @param interLineUnit the unit + * @param interLineSpacing the value + * @return the builder, used for chaining + */ + public TeXIconBuilder setInterLineSpacing(final int interLineUnit, final float interLineSpacing) + { + if (widthUnit == null) + { + throw new IllegalStateException("Cannot set inter line spacing without having specified a width!"); + } + this.interLineUnit = interLineUnit; + this.interLineSpacing = interLineSpacing; + return this; + } + + /** + * Create a TeXIcon from the information gathered by the (chained) setXXX() methods. + * (see Builder pattern) + * @return the TeXIcon + */ + public TeXIcon build() + { + if (style == null) + { + throw new IllegalStateException("A style is required. Use setStyle()"); + } + if (size == null) + { + throw new IllegalStateException("A size is required. Use setStyle()"); + } + DefaultTeXFont font = (type == null) ? new DefaultTeXFont(size) : createFont(size, type); + TeXEnvironment te; + if (widthUnit != null) + { + te = new TeXEnvironment(style, font, widthUnit, textWidth); + } + else + { + te = new TeXEnvironment(style, font); + } + + if (interLineUnit != null) { + te.setInterline(interLineUnit, interLineSpacing); + } + + Box box = createBox(te); + TeXIcon ti; + if (widthUnit != null) + { + HorizontalBox hb; + if (interLineUnit != null) + { + float il = interLineSpacing * SpaceAtom.getFactor(interLineUnit, te); + Box b = BreakFormula.split(box, te.getTextwidth(), il); + hb = new HorizontalBox(b, isMaxWidth ? b.getWidth() : te.getTextwidth(), align); + } + else + { + hb = new HorizontalBox(box, isMaxWidth ? box.getWidth() : te.getTextwidth(), align); + } + ti = new TeXIcon(hb, size, trueValues); + } + else + { + ti = new TeXIcon(box, size, trueValues); + } + if (fgcolor != null) { + ti.setForeground(fgcolor); + } + ti.isColored = te.isColored; + return ti; + } + } + + /** + * Creates a TeXIcon from this TeXFormula using the default TeXFont in the given + * point size and starting from the given TeX style. If the given integer value + * does not represent a valid TeX style, the default style + * TeXConstants.STYLE_DISPLAY will be used. + * + * @param style a TeX style constant (from {@link TeXConstants}) to start from + * @param size the default TeXFont's point size + * @return the created TeXIcon + */ + public TeXIcon createTeXIcon(int style, float size) { + return new TeXIconBuilder().setStyle(style).setSize(size).build(); + } + + public TeXIcon createTeXIcon(int style, float size, int type) { + return new TeXIconBuilder().setStyle(style).setSize(size).setType(type).build(); + } + + public TeXIcon createTeXIcon(int style, float size, int type, Color fgcolor) { + return new TeXIconBuilder().setStyle(style).setSize(size).setType(type).setFGColor(fgcolor).build(); + } + + public TeXIcon createTeXIcon(int style, float size, boolean trueValues) { + return new TeXIconBuilder().setStyle(style).setSize(size).setTrueValues(trueValues).build(); + } + + public TeXIcon createTeXIcon(int style, float size, int widthUnit, float textwidth, int align) { + return createTeXIcon(style, size, 0, widthUnit, textwidth, align); + } + + public TeXIcon createTeXIcon(int style, float size, int type, int widthUnit, float textwidth, int align) { + return new TeXIconBuilder().setStyle(style).setSize(size).setType(type).setWidth(widthUnit, textwidth, align).build(); + } + + public TeXIcon createTeXIcon(int style, float size, int widthUnit, float textwidth, int align, int interlineUnit, float interline) { + return createTeXIcon(style, size, 0, widthUnit, textwidth, align, interlineUnit, interline); + } + + public TeXIcon createTeXIcon(int style, float size, int type, int widthUnit, float textwidth, int align, int interlineUnit, float interline) { + return new TeXIconBuilder().setStyle(style).setSize(size).setType(type).setWidth(widthUnit, textwidth, align).setInterLineSpacing(interlineUnit, interline).build(); + } + + public void createImage(String format, int style, float size, String out, Color bg, Color fg, boolean transparency) { + TeXIcon icon = createTeXIcon(style, size); + icon.setInsets(new Insets(1, 1, 1, 1)); + int w = icon.getIconWidth(), h = icon.getIconHeight(); + + BufferedImage image = new BufferedImage(w, h, transparency ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB); + Graphics2D g2 = image.createGraphics(); + if (bg != null && !transparency) { + g2.setColor(bg); + g2.fillRect(0, 0, w, h); + } + + icon.setForeground(fg); + icon.paintIcon(null, g2, 0, 0); + try { + FileImageOutputStream imout = new FileImageOutputStream(new File(out)); + ImageIO.write(image, format, imout); + imout.flush(); + imout.close(); + } catch (IOException ex) { + System.err.println("I/O error : Cannot generate " + out); + } + + g2.dispose(); + } + + public void createPNG(int style, float size, String out, Color bg, Color fg) { + createImage("png", style, size, out, bg, fg, bg == null); + } + + public void createGIF(int style, float size, String out, Color bg, Color fg) { + createImage("gif", style, size, out, bg, fg, bg == null); + } + + public void createJPEG(int style, float size, String out, Color bg, Color fg) { + //There is a bug when a BufferedImage has a component alpha so we disabel it + createImage("jpeg", style, size, out, bg, fg, false); + } + + /** + * @param formula the formula + * @param style the style + * @param size the size + * @param transparency, if true the background is transparent + * @return the generated image + */ + public static Image createBufferedImage(String formula, int style, float size, Color fg, Color bg) throws ParseException { + TeXFormula f = new TeXFormula(formula); + TeXIcon icon = f.createTeXIcon(style, size); + icon.setInsets(new Insets(2, 2, 2, 2)); + int w = icon.getIconWidth(), h = icon.getIconHeight(); + + BufferedImage image = new BufferedImage(w, h, bg == null ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB); + Graphics2D g2 = image.createGraphics(); + if (bg != null) { + g2.setColor(bg); + g2.fillRect(0, 0, w, h); + } + + icon.setForeground(fg == null ? Color.BLACK : fg); + icon.paintIcon(null, g2, 0, 0); + g2.dispose(); + + return image; + } + + /** + * @param formula the formula + * @param style the style + * @param size the size + * @param transparency, if true the background is transparent + * @return the generated image + */ + public Image createBufferedImage(int style, float size, Color fg, Color bg) throws ParseException { + TeXIcon icon = createTeXIcon(style, size); + icon.setInsets(new Insets(2, 2, 2, 2)); + int w = icon.getIconWidth(), h = icon.getIconHeight(); + + BufferedImage image = new BufferedImage(w, h, bg == null ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB); + Graphics2D g2 = image.createGraphics(); + if (bg != null) { + g2.setColor(bg); + g2.fillRect(0, 0, w, h); + } + + icon.setForeground(fg == null ? Color.BLACK : fg); + icon.paintIcon(null, g2, 0, 0); + g2.dispose(); + + return image; + } + + public void setDEBUG(boolean b) { + Box.DEBUG = b; + } + + /** + * Changes the background color of the current TeXFormula into the given color. + * By default, a TeXFormula has no background color, it's transparent. + * The backgrounds of subformula's will be painted on top of the background of + * the whole formula! Any changes that will be made to this TeXFormula after this + * background color was set, will have the default background color (unless it will + * also be changed into another color afterwards)! + * + * @param c the desired background color for the current TeXFormula + * @return the modified TeXFormula + */ + public TeXFormula setBackground(Color c) { + if (c != null) { + if (root instanceof ColorAtom) + root = new ColorAtom(c, null, (ColorAtom) root); + else + root = new ColorAtom(root, c, null); + } + return this; + } + + /** + * Changes the (foreground) color of the current TeXFormula into the given color. + * By default, the foreground color of a TeXFormula is the foreground color of the + * component on which the TeXIcon (created from this TeXFormula) will be painted. The + * color of subformula's overrides the color of the whole formula. + * Any changes that will be made to this TeXFormula after this color was set, will be + * painted in the default color (unless the color will also be changed afterwards into + * another color)! + * + * @param c the desired foreground color for the current TeXFormula + * @return the modified TeXFormula + */ + public TeXFormula setColor(Color c) { + if (c != null) { + if (root instanceof ColorAtom) + root = new ColorAtom(null, c, (ColorAtom) root); + else + root = new ColorAtom(root, null, c); + } + return this; + } + + /** + * Sets a fixed left and right type of the current TeXFormula. This has an influence + * on the glue that will be inserted before and after this TeXFormula. + * + * @param leftType atom type constant (from {@link TeXConstants}) + * @param rightType atom type constant (from TeXConstants) + * @return the modified TeXFormula + * @throws InvalidAtomTypeException if the given integer value does not represent + * a valid atom type + */ + public TeXFormula setFixedTypes(int leftType, int rightType) + throws InvalidAtomTypeException { + root = new TypedAtom(leftType, rightType, root); + return this; + } + + /** + * Get a predefined TeXFormula. + * + * @param name the name of the predefined TeXFormula + * @return a copy of the predefined TeXFormula + * @throws FormulaNotFoundException if no predefined TeXFormula is found with the + * given name + */ + public static TeXFormula get(String name) throws FormulaNotFoundException { + TeXFormula formula = predefinedTeXFormulas.get(name); + if (formula == null) { + String f = predefinedTeXFormulasAsString.get(name); + if (f == null) { + throw new FormulaNotFoundException(name); + } + TeXFormula tf = new TeXFormula(f); + if (!(tf.root instanceof RowAtom)) { + // depending of the context a RowAtom can be modified + // so we can't reuse it + predefinedTeXFormulas.put(name, tf); + } + return tf; + } else { + return new TeXFormula(formula); + } + } + + static class FontInfos { + + String sansserif; + String serif; + + FontInfos(String sansserif, String serif) { + this.sansserif = sansserif; + this.serif = serif; + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXFormulaParser.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXFormulaParser.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXFormulaParser.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,500 @@ +/* TeXFormulaParser.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Color; +import java.util.HashMap; +import java.util.Map; +import java.util.List; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.w3c.dom.Node; + +/** + * Parses a "TeXFormula"-element representing a predefined TeXFormula's from an XML-file. + */ +public class TeXFormulaParser { + + private interface ActionParser { // NOPMD + public void parse(Element el) throws ResourceParseException; + } + + private interface ArgumentValueParser { // NOPMD + public Object parseValue(String value, String type) + throws ResourceParseException; + } + + private class MethodInvocationParser implements ActionParser { + + MethodInvocationParser () { + // avoids creation of special accessor type + } + + public void parse(Element el) throws ResourceParseException { + // get required string attributes + String methodName = getAttrValueAndCheckIfNotNull("name", el); + String objectName = getAttrValueAndCheckIfNotNull(ARG_OBJ_ATTR, el); + // check if temporary TeXFormula exists + Object object = tempFormulas.get(objectName); + if (object == null) {// doesn't exist + throw new XMLResourceParseException( + PredefinedTeXFormulaParser.RESOURCE_NAME, "Argument", + ARG_OBJ_ATTR, + "has an unknown temporary TeXFormula name as value : '" + + objectName + "'!"); + } else { + // parse arguments + NodeList args = el.getElementsByTagName("Argument"); + // get argument classes and values + Class[] argClasses = getArgumentClasses(args); + Object[] argValues = getArgumentValues(args); + // invoke method + try { + TeXFormula.class.getMethod(methodName, argClasses).invoke((TeXFormula) object, argValues); + } catch (Exception e) { + throw new XMLResourceParseException( + "Error invoking the method '" + methodName + + "' on the temporary TeXFormula '" + objectName + + "' while constructing the predefined TeXFormula '" + + formulaName + "'!\n" + e.toString()); + } + } + } + } + + private class CreateTeXFormulaParser implements ActionParser { + + CreateTeXFormulaParser () { + // avoids creation of special accessor type + } + + public void parse(Element el) throws ResourceParseException { + // get required string attribute + String name = getAttrValueAndCheckIfNotNull("name", el); + // parse arguments + NodeList args = el.getElementsByTagName("Argument"); + // get argument classes and values + Class[] argClasses = getArgumentClasses(args); + Object[] argValues = getArgumentValues(args); + // create TeXFormula object + //String code = "TeXFormula.predefinedTeXFormulasAsString.put(\"%s\", \"%s\");"; + //System.out.println(String.format(code, formulaName, argValues[0])); + try { + TeXFormula f = TeXFormula.class.getConstructor(argClasses).newInstance(argValues); + // succesfully created, so add to "temporary formula's"-hashtable + tempFormulas.put(name, f); + } catch (Exception e) { + throw new XMLResourceParseException( + "Error creating the temporary TeXFormula '" + name + + "' while constructing the predefined TeXFormula '" + + formulaName + "'!\n" + e.toString()); + } + } + } + + private class CreateCommandParser implements ActionParser { + + CreateCommandParser () { + // avoids creation of special accessor type + } + + public void parse(Element el) throws ResourceParseException { + // get required string attribute + String name = getAttrValueAndCheckIfNotNull("name", el); + // parse arguments + NodeList args = el.getElementsByTagName("Argument"); + // get argument classes and values + Class[] argClasses = getArgumentClasses(args); + Object[] argValues = getArgumentValues(args); + // create TeXFormula object + try { + MacroInfo f = MacroInfo.class.getConstructor(argClasses).newInstance(argValues); + // succesfully created, so add to "temporary formula's"-hashtable + tempCommands.put(name, f); + } catch (IllegalArgumentException e) { + String err = "IllegalArgumentException:\n"; + err += "ClassLoader to load this class (TeXFormulaParser): " + this.getClass().getClassLoader() + "\n"; + for (Class cl : argClasses) { + err += "Created class: " + cl + " loaded with the ClassLoader: " + cl.getClassLoader() + "\n"; + } + for (Object obj : argValues) { + err += "Created object: " + obj + "\n"; + } + throw new XMLResourceParseException( + "Error creating the temporary command '" + name + + "' while constructing the predefined command '" + + formulaName + "'!\n" + err); + } catch (Exception e) { + throw new XMLResourceParseException( + "Error creating the temporary command '" + name + + "' while constructing the predefined command '" + + formulaName + "'!\n" + e.toString()); + } + } + } + + private class FloatValueParser implements ArgumentValueParser { + + FloatValueParser () { + // avoids creation of special accessor type + } + + public Object parseValue(String value, String type) + throws ResourceParseException { + checkNullValue(value, type); + try { + return new Float(Float.parseFloat(value)); + } catch (NumberFormatException e) { + throw new XMLResourceParseException( + PredefinedTeXFormulaParser.RESOURCE_NAME, "Argument", + ARG_VAL_ATTR, "has an invalid '" + type + "'-value : '" + + value + "'!", e); + } + } + } + + private class CharValueParser implements ArgumentValueParser { + + CharValueParser () { + // avoids creation of special accessor type + } + + public Object parseValue(String value, String type) + throws ResourceParseException { + checkNullValue(value, type); + if (value.length() == 1) { + return new Character(value.charAt(0)); + } else { + throw new XMLResourceParseException( + PredefinedTeXFormulaParser.RESOURCE_NAME, "Argument", + ARG_VAL_ATTR, + "must have a value that consists of exactly 1 character!"); + } + } + } + + private class BooleanValueParser implements ArgumentValueParser { + + BooleanValueParser () { + // avoids creation of special accessor type + } + + public Object parseValue(String value, String type) + throws ResourceParseException { + checkNullValue(value, type); + if ("true".equals(value)) { + return Boolean.TRUE; + } else if ("false".equals(value)) { + return Boolean.FALSE; + } else { + throw new XMLResourceParseException( + PredefinedTeXFormulaParser.RESOURCE_NAME, "Argument", + ARG_VAL_ATTR, "has an invalid '" + type + "'-value : '" + + value + "'!"); + } + } + } + + private class IntValueParser implements ArgumentValueParser { + + IntValueParser () { + // avoids creation of special accessor type + } + + public Object parseValue(String value, String type) + throws ResourceParseException { + checkNullValue(value, type); + try { + int val = Integer.parseInt(value); + return new Float(val); + } catch (NumberFormatException e) { + throw new XMLResourceParseException( + PredefinedTeXFormulaParser.RESOURCE_NAME, "Argument", + ARG_VAL_ATTR, "has an invalid '" + type + "'-value : '" + + value + "'!", e); + } + } + } + + private class ReturnParser implements ActionParser { + + ReturnParser () { + // avoids creation of special accessor type + } + + public void parse(Element el) throws ResourceParseException { + // get required string attribute + String name = getAttrValueAndCheckIfNotNull("name", el); + Object res = type == COMMAND ? tempCommands.get(name) : tempFormulas.get(name); + if (res == null) { + throw new XMLResourceParseException( + PredefinedTeXFormulaParser.RESOURCE_NAME, RETURN_EL, "name", + "contains an unknown temporary TeXFormula variable name '" + + name + "' for the predefined TeXFormula '" + + formulaName + "'!"); + } else { + result = res; + } + } + } + + private class StringValueParser implements ArgumentValueParser { + + StringValueParser () { + // avoids creation of special accessor type + } + + public Object parseValue(String value, String type) + throws ResourceParseException { + return value; + } + } + + private class TeXFormulaValueParser implements ArgumentValueParser { + + TeXFormulaValueParser () { + // avoids creation of special accessor type + } + + public Object parseValue(String value, String type) + throws ResourceParseException { + if (value == null) {// null pointer argument + return null; + } else { + Object formula = tempFormulas.get(value); + if (formula == null) {// unknown temporary TeXFormula! + throw new XMLResourceParseException( + PredefinedTeXFormulaParser.RESOURCE_NAME, "Argument", + ARG_VAL_ATTR, + "has an unknown temporary TeXFormula name as value : '" + + value + "'!"); + } else { + return (TeXFormula) formula; + } + } + } + } + + private class TeXConstantsValueParser implements ArgumentValueParser { + + TeXConstantsValueParser () { + // avoids creation of special accessor type + } + + public Object parseValue(String value, String type) + throws ResourceParseException { + checkNullValue(value, type); + try { + // get constant value (if present) + int constant = TeXConstants.class.getDeclaredField(value).getInt( + null); + // return constant integer value + return Integer.valueOf(constant); + } catch (Exception e) { + throw new XMLResourceParseException( + PredefinedTeXFormulaParser.RESOURCE_NAME, "Argument", + ARG_VAL_ATTR, "has an unknown constant name as value : '" + + value + "'!", e); + } + } + } + + private class ColorConstantValueParser implements ArgumentValueParser { + + ColorConstantValueParser () { + // avoids creation of special accessor type + } + + public Object parseValue(String value, String type) + throws ResourceParseException { + checkNullValue(value, type); + try { + // return Color constant (if present) + return Color.class.getDeclaredField(value).get(null); + } catch (Exception e) { + throw new XMLResourceParseException( + PredefinedTeXFormulaParser.RESOURCE_NAME, "Argument", + ARG_VAL_ATTR, + "has an unknown color constant name as value : '" + value + + "'!", e); + } + } + } + + private static final String ARG_VAL_ATTR = "value", RETURN_EL = "Return", + ARG_OBJ_ATTR = "formula"; + + private static Map> classMappings = new HashMap>(); + + private final Map argValueParsers = new HashMap(); + private final Map actionParsers = new HashMap(); + private final Map tempFormulas = new HashMap(); + private final Map tempCommands = new HashMap(); + + private Object result = new Object(); + + private final String formulaName; + + private final Element formula; + + private static final int COMMAND = 0, TEXFORMULA = 1; + private int type; + + static { + // string-to-class mappings + classMappings.put("TeXConstants", int.class); // all integer constants + classMappings.put("TeXFormula", TeXFormula.class); + classMappings.put("String", String.class); + classMappings.put("float", float.class); + classMappings.put("int", int.class); + classMappings.put("boolean", boolean.class); + classMappings.put("char", char.class); + classMappings.put("ColorConstant", Color.class); + } + + public TeXFormulaParser(String name, Element formula, String type) { + formulaName = name; + this.formula = formula; + this.type = "Command".equals(type) ? COMMAND : TEXFORMULA; + + // action parsers + if ("Command".equals(type)) + actionParsers.put("CreateCommand", new CreateCommandParser()); + else + actionParsers.put("CreateTeXFormula", new CreateTeXFormulaParser()); + + actionParsers.put("MethodInvocation", new MethodInvocationParser()); + actionParsers.put(RETURN_EL, new ReturnParser()); + + // argument value parsers + argValueParsers.put("TeXConstants", new TeXConstantsValueParser()); + argValueParsers.put("TeXFormula", new TeXFormulaValueParser()); + argValueParsers.put("String", new StringValueParser()); + argValueParsers.put("float", new FloatValueParser()); + argValueParsers.put("int", new IntValueParser()); + argValueParsers.put("boolean", new BooleanValueParser()); + argValueParsers.put("char", new CharValueParser()); + argValueParsers.put("ColorConstant", new ColorConstantValueParser()); + } + + public Object parse() throws ResourceParseException { + // parse and execute actions + NodeList list = formula.getChildNodes(); + for (int i = 0; i < list.getLength(); i++) { + Node node = list.item(i); + if (node.getNodeType() != Node.TEXT_NODE) { + Element el = (Element)node; + ActionParser p = actionParsers.get(el.getTagName()); + if (p != null) {// ignore unknown elements + p.parse(el); + } + } + } + return result; + } + + private Object[] getArgumentValues(NodeList args) { + Object[] res = new Object[args.getLength()]; + int i = 0; + for (int j = 0; j < args.getLength(); j++) { + Element arg = (Element)args.item(j); + // get required string attribute + String type = getAttrValueAndCheckIfNotNull("type", arg); + // get value, not present means a nullpointer + String value = arg.getAttribute(ARG_VAL_ATTR); + // parse value, hashtable will certainly contain a parser for the class type, + // because the class types have been checked before! + res[i] = argValueParsers.get(type).parseValue(value, type); + i++; + } + return res; + } + + private static Class[] getArgumentClasses(NodeList args) + throws ResourceParseException { + Class[] res = new Class[args.getLength()]; + int i = 0; + for (int j = 0; j < args.getLength(); j++) { + Element arg = (Element)args.item(j); + // get required string attribute + String type = getAttrValueAndCheckIfNotNull("type", arg); + // find class mapping + Object cl = classMappings.get(type); + if (cl == null) {// no class mapping found + throw new XMLResourceParseException( + PredefinedTeXFormulaParser.RESOURCE_NAME, "Argument", "type", + "has an invalid class name value!"); + } else { + res[i] = (Class) cl; + } + i++; + } + return res; + } + + private static void checkNullValue(String value, String type) + throws ResourceParseException { + if (value.equals("")) { + throw new XMLResourceParseException( + PredefinedTeXFormulaParser.RESOURCE_NAME, "Argument", + ARG_VAL_ATTR, "is required for an argument of type '" + type + + "'!"); + } + } + + private static String getAttrValueAndCheckIfNotNull(String attrName, + Element element) throws ResourceParseException { + String attrValue = element.getAttribute(attrName); + if (attrValue.equals("")) { + throw new XMLResourceParseException( + PredefinedTeXFormulaParser.RESOURCE_NAME, element.getTagName(), + attrName, null); + } + return attrValue; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXFormulaSettingsParser.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXFormulaSettingsParser.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXFormulaSettingsParser.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,148 @@ +/* TeXFormulaSettingsParser.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.io.InputStream; + +import javax.xml.parsers.DocumentBuilderFactory; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * Parses predefined TeXFormula's from an XML-file. + */ +public class TeXFormulaSettingsParser { + + public static final String RESOURCE_NAME = "TeXFormulaSettings.xml"; + public static final String CHARTODEL_MAPPING_EL = "Map"; + + private Element root; + + public TeXFormulaSettingsParser() throws ResourceParseException { + this(GlueSettingsParser.class.getResourceAsStream(RESOURCE_NAME), RESOURCE_NAME); + } + + public TeXFormulaSettingsParser(InputStream file, String name) throws ResourceParseException { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setIgnoringElementContentWhitespace(true); + factory.setIgnoringComments(true); + root = factory.newDocumentBuilder().parse(file).getDocumentElement(); + } catch (Exception e) { // JDOMException or IOException + throw new XMLResourceParseException(name, e); + } + } + + public void parseSymbolToFormulaMappings(String[] mappings, String[] textMappings) throws ResourceParseException { + Element charToSymbol = (Element)root.getElementsByTagName("CharacterToFormulaMappings").item(0); + if (charToSymbol != null) // element present + addFormulaToMap(charToSymbol.getElementsByTagName("Map"), mappings, textMappings); + } + + public void parseSymbolMappings(String[] mappings, String[] textMappings) throws ResourceParseException { + Element charToSymbol = (Element)root.getElementsByTagName("CharacterToSymbolMappings").item(0); + if (charToSymbol != null) // element present + addToMap(charToSymbol.getElementsByTagName("Map"), mappings, textMappings); + } + + private static void addToMap(NodeList mapList, String[] tableMath, String[] tableText) throws ResourceParseException { + for (int i = 0; i < mapList.getLength(); i++) { + Element map = (Element) mapList.item(i); + String ch = map.getAttribute("char"); + String symbol = map.getAttribute("symbol"); + String text = map.getAttribute("text"); + // both attributes are required! + if (ch.equals("")) { + throw new XMLResourceParseException(RESOURCE_NAME, map.getTagName(), "char", null); + } else if (symbol.equals("")) { + throw new XMLResourceParseException(RESOURCE_NAME, map.getTagName(), "symbol", null); + } + + if (ch.length() == 1) {// valid element found + tableMath[ch.charAt(0)] = symbol; + } else { + // only single-character mappings allowed, ignore others + throw new XMLResourceParseException(RESOURCE_NAME, map.getTagName(), "char", "must have a value that contains exactly 1 character!"); + } + + if (tableText != null && !text.equals("")) { + tableText[ch.charAt(0)] = text; + } + } + } + + private static void addFormulaToMap(NodeList mapList, String[] tableMath, String[] tableText) throws ResourceParseException { + for (int i = 0; i < mapList.getLength(); i++) { + Element map = (Element)mapList.item(i); + String ch = map.getAttribute("char"); + String formula = map.getAttribute("formula"); + String text = map.getAttribute("text"); + // both attributes are required! + if (ch.equals("")) + throw new XMLResourceParseException(RESOURCE_NAME, map.getTagName(), + "char", null); + else if (formula.equals("")) + throw new XMLResourceParseException(RESOURCE_NAME, map.getTagName(), + "formula", null); + if (ch.length() == 1) {// valid element found + tableMath[ch.charAt(0)] = formula; + } + else + // only single-character mappings allowed, ignore others + throw new XMLResourceParseException(RESOURCE_NAME, map.getTagName(), + "char", + "must have a value that contains exactly 1 character!"); + + if (tableText != null && !text.equals("")) { + tableText[ch.charAt(0)] = text; + } + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXIcon.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXIcon.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXIcon.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,276 @@ +/* TeXIcon.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet */ + + +package org.scilab.forge.jlatexmath; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Insets; +import java.awt.RenderingHints; +import java.awt.geom.AffineTransform; + +import javax.swing.Icon; + +/** + * An {@link javax.swing.Icon} implementation that will paint the TeXFormula + * that created it. + *

+ * 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 = 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 size the point size + */ + protected TeXIcon(Box b, float size) { + 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); + insets.left += (int)(0.18f * size); + insets.right += (int)(0.18f * size); + } + } + + public void setForeground(Color fg) { + this.fg = fg; + } + + /** + * Get the insets of the TeXIcon. + * + * @return the insets + */ + public Insets getInsets() { + 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.left += (int)(0.18f * size); + this.insets.right += (int)(0.18f * size); + } + } + + /** + * Set the insets of the TeXIcon. + * + * @param insets the insets + */ + public void setInsets(Insets insets) { + 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 + * 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); + } + + /** + * 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 + * 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); + } + + /** + * 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)); + } + + /** + * Get the total height of the TeXIcon. This also includes the insets. + */ + public int getIconDepth() { + 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); + } + + public float getTrueIconHeight() { + 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; + } + + /** + * Get the total width of the TeXIcon. This also includes the insets. + */ + + public float getTrueIconWidth() { + 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)); + } + + public Box getBox() { + return box; + } + + /** + * 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 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); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXParser.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXParser.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXParser.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,1499 @@ +/* TeXParser.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/p/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Color; +import java.awt.Font; +import java.lang.Character.UnicodeBlock; +import java.util.HashSet; +import java.util.Set; + +/** + * This class implements a parser for LaTeX' formulas. + */ +public class TeXParser { + + TeXFormula formula; + + private StringBuffer parseString; + private int pos; + private int spos; + private int line; + private int col; + private int len; + private int group; + private boolean insertion; + private int atIsLetter; + private boolean arrayMode; + private boolean ignoreWhiteSpace = true; + private boolean isPartial; + private boolean autoNumberBreaking; + + // the escape character + private static final char ESCAPE = '\\'; + + // grouping characters (for parsing) + private static final char L_GROUP = '{'; + private static final char R_GROUP = '}'; + 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 = '%'; + + // used as second index in "delimiterNames" table (over or under) + private static final int OVER_DEL = 0; + private static final int UNDER_DEL = 1; + + // script characters (for parsing) + private static final char SUB_SCRIPT = '_'; + private static final char SUPER_SCRIPT = '^'; + private static final char PRIME = '\''; + private static final char BACKPRIME = '\u2035'; + private static final char DEGRE = '\u00B0'; + private static final char SUPZERO = '\u2070'; + private static final char SUPONE = '\u00B9'; + private static final char SUPTWO = '\u00B2'; + private static final char SUPTHREE = '\u00B3'; + private static final char SUPFOUR = '\u2074'; + private static final char SUPFIVE = '\u2075'; + private static final char SUPSIX = '\u2076'; + private static final char SUPSEVEN = '\u2077'; + private static final char SUPEIGHT = '\u2078'; + private static final char SUPNINE = '\u2079'; + private static final char SUPPLUS = '\u207A'; + private static final char SUPMINUS = '\u207B'; + private static final char SUPEQUAL = '\u207C'; + private static final char SUPLPAR = '\u207D'; + private static final char SUPRPAR = '\u207E'; + private static final char SUPN = '\u207F'; + private static final char SUBZERO = '\u2080'; + private static final char SUBONE = '\u2081'; + private static final char SUBTWO = '\u2082'; + private static final char SUBTHREE = '\u2083'; + private static final char SUBFOUR = '\u2084'; + private static final char SUBFIVE = '\u2085'; + private static final char SUBSIX = '\u2086'; + private static final char SUBSEVEN = '\u2087'; + private static final char SUBEIGHT = '\u2088'; + private static final char SUBNINE = '\u2089'; + private static final char SUBPLUS = '\u208A'; + private static final char SUBMINUS = '\u208B'; + private static final char SUBEQUAL = '\u208C'; + private static final char SUBLPAR = '\u208D'; + private static final char SUBRPAR = '\u208E'; + + protected static boolean isLoading = false; + + private static final Set unparsedContents = new HashSet(6); + static { + unparsedContents.add("jlmDynamic"); + unparsedContents.add("jlmText"); + unparsedContents.add("jlmTextit"); + unparsedContents.add("jlmTextbf"); + unparsedContents.add("jlmTextitbf"); + unparsedContents.add("jlmExternalFont"); + } + + /** + * Create a new TeXParser + * + * @param parseString the string to be parsed + * @param formula the formula where to put the atoms + * @throws ParseException if the string could not be parsed correctly + */ + public TeXParser(String parseString, TeXFormula formula) { + this(parseString, formula, true); + } + + /** + * Create a new TeXParser + * + * @param isPartial if true certains exceptions are not thrown + * @param parseString the string to be parsed + * @param formula the formula where to put the atoms + * @throws ParseException if the string could not be parsed correctly + */ + public TeXParser(boolean isPartial, String parseString, TeXFormula formula) { + this(parseString, formula, false); + this.isPartial = isPartial; + firstpass(); + } + + /** + * Create a new TeXParser with or without a first pass + * + * @param isPartial if true certains exceptions are not thrown + * @param parseString the string to be parsed + * @param firstpass a boolean to indicate if the parser must replace the user-defined macros by their content + * @throws ParseException if the string could not be parsed correctly + */ + public TeXParser(boolean isPartial, String parseString, TeXFormula formula, boolean firstpass) { + this.formula = formula; + this.isPartial = isPartial; + if (parseString != null) { + this.parseString = new StringBuffer(parseString); + this.len = parseString.length(); + this.pos = 0; + if (firstpass) { + firstpass(); + } + } else { + this.parseString = null; + this.pos = 0; + this.len = 0; + } + } + + /** + * Create a new TeXParser with or without a first pass + * + * @param parseString the string to be parsed + * @param firstpass a boolean to indicate if the parser must replace the user-defined macros by their content + * @throws ParseException if the string could not be parsed correctly + */ + public TeXParser(String parseString, TeXFormula formula, boolean firstpass) { + this(false, parseString, formula, firstpass); + } + + /** + * Create a new TeXParser in the context of an array. When the parser meets a & a new atom is added in the current line and when a \\ is met, a new line is created. + * + * @param isPartial if true certains exceptions are not thrown + * @param parseString the string to be parsed + * @param aoa an ArrayOfAtoms where to put the elements + * @param firstpass a boolean to indicate if the parser must replace the user-defined macros by their content + * @throws ParseException if the string could not be parsed correctly + */ + public TeXParser(boolean isPartial, String parseString, ArrayOfAtoms aoa, boolean firstpass) { + this(isPartial, parseString, (TeXFormula) aoa, firstpass); + arrayMode = true; + } + + /** + * Create a new TeXParser in the context of an array. When the parser meets a & a new atom is added in the current line and when a \\ is met, a new line is created. + * + * @param isPartial if true certains exceptions are not thrown + * @param parseString the string to be parsed + * @param aoa an ArrayOfAtoms where to put the elements + * @param firstpass a boolean to indicate if the parser must replace the user-defined macros by their content + * @throws ParseException if the string could not be parsed correctly + */ + public TeXParser(boolean isPartial, String parseString, ArrayOfAtoms aoa, boolean firstpass, boolean space) { + this(isPartial, parseString, (TeXFormula) aoa, firstpass, space); + arrayMode = true; + } + + /** + * Create a new TeXParser in the context of an array. When the parser meets a & a new atom is added in the current line and when a \\ is met, a new line is created. + * + * @param parseString the string to be parsed + * @param aoa an ArrayOfAtoms where to put the elements + * @param firstpass a boolean to indicate if the parser must replace the user-defined macros by their content + * @throws ParseException if the string could not be parsed correctly + */ + public TeXParser(String parseString, ArrayOfAtoms aoa, boolean firstpass) { + this(false, parseString, (TeXFormula) aoa, firstpass); + } + + /** + * Create a new TeXParser which ignores or not the white spaces, it's useful for mbox command + * + * @param isPartial if true certains exceptions are not thrown + * @param parseString the string to be parsed + * @param firstpass a boolean to indicate if the parser must replace the user-defined macros by their content + * @param space a boolean to indicate if the parser must ignore or not the white space + * @throws ParseException if the string could not be parsed correctly + */ + public TeXParser(boolean isPartial, String parseString, TeXFormula formula, boolean firstpass, boolean space) { + this(isPartial, parseString, formula, firstpass); + this.ignoreWhiteSpace = space; + } + + /** + * Create a new TeXParser which ignores or not the white spaces, it's useful for mbox command + * + * @param parseString the string to be parsed + * @param firstpass a boolean to indicate if the parser must replace the user-defined macros by their content + * @param space a boolean to indicate if the parser must ignore or not the white space + * @throws ParseException if the string could not be parsed correctly + */ + public TeXParser(String parseString, TeXFormula formula, boolean firstpass, boolean space) { + this(false, parseString, formula, firstpass); + this.ignoreWhiteSpace = space; + } + + /** + * Reset the parser with a new latex expression + */ + public void reset(String latex) { + parseString = new StringBuffer(latex); + len = parseString.length(); + formula.root = null; + pos = 0; + spos = 0; + line = 0; + col = 0; + group = 0; + insertion = false; + atIsLetter = 0; + arrayMode = false; + ignoreWhiteSpace = true; + firstpass(); + } + + /** Return true if we get a partial formula + */ + public boolean getIsPartial() { + return isPartial; + } + + /** Get the number of the current line + */ + public int getLine() { + return line; + } + + /** Get the number of the current column + */ + public int getCol() { + return pos - col - 1; + } + + /** Get the last atom of the current formula + */ + public Atom getLastAtom() { + Atom at = formula.root; + if (at instanceof RowAtom) + return ((RowAtom)at).getLastAtom(); + formula.root = null; + return at; + } + + /** Get the atom represented by the current formula + */ + public Atom getFormulaAtom() { + Atom at = formula.root; + formula.root = null; + return at; + } + + /** Put an atom in the current formula + */ + public void addAtom(Atom at) { + formula.add(at); + } + + /** Indicate if the character @ can be used in the command's name + */ + public void makeAtLetter() { + atIsLetter++; + } + + /** Indicate if the character @ can be used in the command's name + */ + public void makeAtOther() { + atIsLetter--; + } + + /** Return a boolean indicating if the character @ is considered as a letter or not + */ + public boolean isAtLetter() { + return (atIsLetter != 0); + } + + /** Return a boolean indicating if the parser is used to parse an array or not + */ + public boolean isArrayMode() { + return arrayMode; + } + + public void setArrayMode(boolean arrayMode) { + this.arrayMode = arrayMode; + } + + /** Return a boolean indicating if the parser must ignore white spaces + */ + public boolean isIgnoreWhiteSpace() { + return ignoreWhiteSpace; + } + + /** Return a boolean indicating if the parser is in math mode + */ + public boolean isMathMode() { + return ignoreWhiteSpace; + } + + /** Return the current position in the parsed string + */ + public int getPos() { + return pos; + } + + /** Rewind the current parsed string + * @param n the number of character to be rewinded + * @return the new position in the parsed string + */ + public int rewind(int n) { + pos -= n; + return pos; + } + + public String getStringFromCurrentPos() { + return parseString.substring(pos); + } + + public void finish() { + pos = parseString.length(); + } + + /** Add a new row when the parser is in array mode + * @throws ParseException if the parser is not in array mode + */ + public void addRow() throws ParseException { + if (!arrayMode) + throw new ParseException("You can add a row only in array mode !"); + ((ArrayOfAtoms)formula).addRow(); + } + + private void firstpass() throws ParseException { + if (len != 0) { + char ch; + String com; + int spos; + String[] args; + MacroInfo mac; + while (pos < len) { + ch = parseString.charAt(pos); + switch (ch) { + case ESCAPE : + spos = pos; + com = getCommand(); + if ("newcommand".equals(com) || "renewcommand".equals(com)) { + args = getOptsArgs(2, 2); + mac = MacroInfo.Commands.get(com); + try { + mac.invoke(this, args); + } catch (ParseException e) { + if (!isPartial) { + throw e; + } + } + parseString.delete(spos, pos); + len = parseString.length(); + pos = spos; + } else if (NewCommandMacro.isMacro(com)) { + mac = MacroInfo.Commands.get(com); + args = getOptsArgs(mac.nbArgs, mac.hasOptions ? 1 : 0); + args[0] = com; + try { + parseString.replace(spos, pos, (String) mac.invoke(this, args)); + } catch (ParseException e) { + if (!isPartial) { + throw e; + } else { + spos += com.length() + 1; + } + } + len = parseString.length(); + pos = spos; + } else if ("begin".equals(com)) { + args = getOptsArgs(1, 0); + mac = MacroInfo.Commands.get(args[1] + "@env"); + if (mac == null) { + if (!isPartial) { + throw new ParseException("Unknown environment: " + args[1] + " at position " + getLine() + ":" + getCol()); + } + } else { + try { + String[] optarg = getOptsArgs(mac.nbArgs - 1, 0); + String grp = getGroup("\\begin{" + args[1] + "}", "\\end{" + args[1] + "}"); + String expr = "{\\makeatletter \\" + args[1] + "@env"; + for (int i = 1; i <= mac.nbArgs - 1; i++) + expr += "{" + optarg[i] + "}"; + expr += "{" + grp + "}\\makeatother}"; + parseString.replace(spos, pos, expr); + len = parseString.length(); + pos = spos; + } catch (ParseException e) { + if (!isPartial) { + throw e; + } + } + } + } else if ("makeatletter".equals(com)) + atIsLetter++; + else if ("makeatother".equals(com)) + atIsLetter--; + else if (unparsedContents.contains(com)) { + getOptsArgs(1, 0); + } + break; + case PERCENT : + spos = pos++; + char chr; + while (pos < len) { + chr = parseString.charAt(pos++); + if (chr == '\r' || chr == '\n') { + break; + } + } + if (pos < len) { + pos--; + } + parseString.replace(spos, pos, ""); + len = parseString.length(); + pos = spos; + break; + case DEGRE : + parseString.replace(pos, pos + 1, "^\\circ"); + len = parseString.length(); + pos++; + break; + case SUPTWO : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{2}"); + len = parseString.length(); + pos++; + break; + case SUPTHREE : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{3}"); + len = parseString.length(); + pos++; + break; + case SUPONE : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{1}"); + len = parseString.length(); + pos++; + break; + case SUPZERO : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{0}"); + len = parseString.length(); + pos++; + break; + case SUPFOUR : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{4}"); + len = parseString.length(); + pos++; + break; + case SUPFIVE : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{5}"); + len = parseString.length(); + pos++; + break; + case SUPSIX : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{6}"); + len = parseString.length(); + pos++; + break; + case SUPSEVEN : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{7}"); + len = parseString.length(); + pos++; + break; + case SUPEIGHT : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{8}"); + len = parseString.length(); + pos++; + break; + case SUPNINE : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{9}"); + len = parseString.length(); + pos++; + break; + case SUPPLUS : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{+}"); + len = parseString.length(); + pos++; + break; + case SUPMINUS : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{-}"); + len = parseString.length(); + pos++; + break; + case SUPEQUAL : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{=}"); + len = parseString.length(); + pos++; + break; + case SUPLPAR : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{(}"); + len = parseString.length(); + pos++; + break; + case SUPRPAR : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{)}"); + len = parseString.length(); + pos++; + break; + case SUPN : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsup{n}"); + len = parseString.length(); + pos++; + break; + case SUBTWO : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{2}"); + len = parseString.length(); + pos++; + break; + case SUBTHREE : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{3}"); + len = parseString.length(); + pos++; + break; + case SUBONE : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{1}"); + len = parseString.length(); + pos++; + break; + case SUBZERO : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{0}"); + len = parseString.length(); + pos++; + break; + case SUBFOUR : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{4}"); + len = parseString.length(); + pos++; + break; + case SUBFIVE : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{5}"); + len = parseString.length(); + pos++; + break; + case SUBSIX : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{6}"); + len = parseString.length(); + pos++; + break; + case SUBSEVEN : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{7}"); + len = parseString.length(); + pos++; + break; + case SUBEIGHT : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{8}"); + len = parseString.length(); + pos++; + break; + case SUBNINE : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{9}"); + len = parseString.length(); + pos++; + break; + case SUBPLUS : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{+}"); + len = parseString.length(); + pos++; + break; + case SUBMINUS : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{-}"); + len = parseString.length(); + pos++; + break; + case SUBEQUAL : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{=}"); + len = parseString.length(); + pos++; + break; + case SUBLPAR : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{(}"); + len = parseString.length(); + pos++; + break; + case SUBRPAR : + parseString.replace(pos, pos + 1, "\\jlatexmathcumsub{)}"); + len = parseString.length(); + pos++; + break; + default : + pos++; + } + } + pos = 0; + len = parseString.length(); + } + } + + /** Parse the input string + * @throws ParseException if an error is encountered during parsing + */ + public void parse() throws ParseException { + if (len != 0) { + char ch; + while (pos < len) { + ch = parseString.charAt(pos); + + switch (ch) { + case '\n' : + line++; + col = pos; + case '\t' : + case '\r' : + pos++; + break; + case ' ' : + pos++; + if (!ignoreWhiteSpace) {// We are in a mbox + formula.add(new SpaceAtom()); + formula.add(new BreakMarkAtom()); + while (pos < len) { + ch = parseString.charAt(pos); + if (ch != ' ' || ch != '\t' || ch != '\r') + break; + pos++; + } + } + break; + case DOLLAR : + pos++; + if (!ignoreWhiteSpace) {// We are in a mbox + int style = TeXConstants.STYLE_TEXT; + boolean doubleDollar = false; + if (parseString.charAt(pos) == DOLLAR) { + style = TeXConstants.STYLE_DISPLAY; + doubleDollar = true; + pos++; + } + + formula.add(new MathAtom(new TeXFormula(this, getDollarGroup(DOLLAR), false).root, style)); + if (doubleDollar) { + if (parseString.charAt(pos) == DOLLAR) { + pos++; + } + } + } + break; + case ESCAPE : + Atom at = processEscape(); + formula.add(at); + if (arrayMode && at instanceof HlineAtom) { + ((ArrayOfAtoms) formula).addRow(); + } + if (insertion) { + insertion = false; + } + break; + case L_GROUP : + Atom atom = getArgument(); + if (atom != null) { + atom.type = TeXConstants.TYPE_ORDINARY; + } + formula.add(atom); + break; + case R_GROUP : + group--; + pos++; + if (group == -1) + throw new ParseException("Found a closing '" + R_GROUP + "' without an opening '" + L_GROUP + "'!"); + return; + case SUPER_SCRIPT : + formula.add(getScripts(ch)); + break; + case SUB_SCRIPT : + if (ignoreWhiteSpace) { + formula.add(getScripts(ch)); + } else { + formula.add(new UnderscoreAtom()); + pos++; + } + break; + case '&' : + if (!arrayMode) + throw new ParseException("Character '&' is only available in array mode !"); + ((ArrayOfAtoms) formula).addCol(); + pos++; + break; + case '~' : + formula.add(new SpaceAtom()); + pos++; + break; + case PRIME : + if (ignoreWhiteSpace) { + formula.add(new CumulativeScriptsAtom(getLastAtom(), null, SymbolAtom.get("prime"))); + } else { + formula.add(convertCharacter(PRIME, true)); + } + pos++; + break; + case BACKPRIME : + if (ignoreWhiteSpace) { + formula.add(new CumulativeScriptsAtom(getLastAtom(), null, SymbolAtom.get("backprime"))); + } else { + formula.add(convertCharacter(BACKPRIME, true)); + } + 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++; + } + } + } + + if (formula.root == null && !arrayMode) { + formula.add(new EmptyAtom()); + } + } + + private Atom getScripts(char f) throws ParseException { + pos++; + Atom first = getArgument(); + Atom second = null; + char s = '\0'; + + if (pos < len) + s = parseString.charAt(pos); + + if (f == SUPER_SCRIPT && s == SUPER_SCRIPT) { + second = first; + first = null; + } else if (f == SUB_SCRIPT && s == SUPER_SCRIPT) { + pos++; + second = getArgument(); + } else if (f == SUPER_SCRIPT && s == SUB_SCRIPT) { + pos++; + second = first; + first = getArgument(); + } else if (f == SUPER_SCRIPT && s != SUB_SCRIPT) { + second = first; + first = null; + } + + Atom at; + if (formula.root instanceof RowAtom) { + at = ((RowAtom)formula.root).getLastAtom(); + } else if (formula.root == null) { + at = new PhantomAtom(new CharAtom('M', "mathnormal"), false, true, true); + } else { + at = formula.root; + formula.root = null; + } + + if (at.getRightType() == TeXConstants.TYPE_BIG_OPERATOR) + return new BigOperatorAtom(at, first, second); + else if (at instanceof OverUnderDelimiter) { + if (((OverUnderDelimiter)at).isOver()) { + if (second != null) { + ((OverUnderDelimiter)at).addScript(second); + return new ScriptsAtom(at, first, null); + } + } else if (first != null) { + ((OverUnderDelimiter)at).addScript(first); + return new ScriptsAtom(at, null, second); + } + } + + return new ScriptsAtom(at, first, second); + } + + /** Get the contents between two delimiters + * @param openclose the opening and closing character (such $) + * @return the enclosed contents + * @throws ParseException if the contents are badly enclosed + */ + public String getDollarGroup(char openclose) throws ParseException { + int spos = pos; + char ch; + + do { + ch = parseString.charAt(pos++); + if (ch == ESCAPE) { + pos++; + } + } while (pos < len && ch != openclose); + + if (ch == openclose) { + return parseString.substring(spos, pos - 1); + } else { + return parseString.substring(spos, pos); + } + } + + /** Get the contents between two delimiters + * @param open the opening character + * @param close the closing character + * @return the enclosed contents + * @throws ParseException if the contents are badly enclosed + */ + public String getGroup(char open, char close) throws ParseException { + if (pos == len) + return null; + + int group, spos; + char ch = parseString.charAt(pos); + + if (pos < len && ch == open) { + group = 1; + spos = pos; + while (pos < len - 1 && group != 0) { + pos++; + ch = parseString.charAt(pos); + if (ch == open) + group++; + else if (ch == close) + group--; + else if (ch == ESCAPE && pos != len - 1) + pos++; + } + + pos++; + + if (group != 0) { + return parseString.substring(spos + 1, pos); + } + + return parseString.substring(spos + 1, pos - 1); + } else { + throw new ParseException("missing '" + open + "'!"); + } + } + + /** Get the contents between two strings as in \begin{foo}...\end{foo} + * @param open the opening string + * @param close the closing string + * @return the enclosed contents + * @throws ParseException if the contents are badly enclosed + */ + public String getGroup(String open, String close) throws ParseException { + int group = 1; + int ol = open.length(), cl = close.length(); + boolean lastO = isValidCharacterInCommand(open.charAt(ol - 1)); + boolean lastC = isValidCharacterInCommand(close.charAt(cl - 1)); + int oc = 0, cc = 0; + int startC = 0; + char prev = '\0'; + StringBuffer buf = new StringBuffer(); + + while (pos < len && group != 0) { + char c = parseString.charAt(pos); + char c1; + + if (prev != ESCAPE && c == ' ') {//Trick to handle case where close == "\end {foo}" + while (pos < len && parseString.charAt(pos++) == ' ') { + buf.append(' '); + } + c = parseString.charAt(--pos); + if (isValidCharacterInCommand(prev) && isValidCharacterInCommand(c)) { + oc = cc = 0; + } + } + + if (c == open.charAt(oc)) + oc++; + else + oc = 0; + + if (c == close.charAt(cc)) { + if (cc == 0) { + startC = pos; + } + cc++; + } else + cc = 0; + + if (pos + 1 < len) { + c1 = parseString.charAt(pos + 1); + + if (oc == ol) { + if (!lastO || !isValidCharacterInCommand(c1)) { + group++; + } + oc = 0; + } + + if (cc == cl) { + if (!lastC || !isValidCharacterInCommand(c1)) { + group--; + } + cc = 0; + } + } else { + if (oc == ol) { + group++; + oc = 0; + } + if (cc == cl) { + group--; + cc = 0; + } + } + + prev = c; + buf.append(c); + pos++; + } + + if (group != 0) { + if (isPartial) { + return buf.toString(); + } + throw new ParseException("The token " + open + " must be closed by " + close); + } + + return buf.substring(0, buf.length() - pos + startC); + } + + /** Get the argument of a command in his atomic format + * @return the corresponding atom + * @throws ParseException if the argument is incorrect + */ + public Atom getArgument() throws ParseException { + skipWhiteSpace(); + char ch; + if (pos < len) { + ch = parseString.charAt(pos); + } else { + return new EmptyAtom(); + } + if (ch == L_GROUP) { + TeXFormula tf = new TeXFormula(); + TeXFormula sformula = this.formula; + this.formula = tf; + pos++; + group++; + parse(); + this.formula = sformula; + if (this.formula.root == null) { + RowAtom at = new RowAtom(); + at.add(tf.root); + return at; + } + return tf.root; + } + + if (ch == ESCAPE) { + Atom at = processEscape(); + if (insertion) { + insertion = false; + return getArgument(); + } + return at; + } + + Atom at = convertCharacter(ch, true); + pos++; + return at; + } + + public String getOverArgument() throws ParseException { + if (pos == len) + return null; + + int ogroup = 1, spos; + char ch = '\0'; + + spos = pos; + while (pos < len && ogroup != 0) { + ch = parseString.charAt(pos); + switch (ch) { + case L_GROUP : + ogroup++; + break; + case '&' : + /* if a & is encountered at the same level as \over + we must break the argument */ + if (ogroup == 1) { + ogroup--; + } + break; + case R_GROUP : + ogroup--; + break; + case ESCAPE : + pos++; + /* if a \\ or a \cr is encountered at the same level as \over + we must break the argument */ + if (pos < len && parseString.charAt(pos) == '\\' && ogroup == 1) { + ogroup--; + pos--; + } else if (pos < len - 1 && parseString.charAt(pos) == 'c' && parseString.charAt(pos + 1) == 'r' && ogroup == 1) { + ogroup--; + pos--; + } + break; + } + pos++; + } + + if (ogroup >= 2) + // end of string reached, but not processed properly + throw new ParseException("Illegal end, missing '}' !"); + + String str; + if (ogroup == 0) { + str = parseString.substring(spos, pos - 1); + } else { + str = parseString.substring(spos, pos); + ch = '\0'; + } + + if (ch == '&' || ch == '\\' || ch == R_GROUP) + pos--; + + 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 + * @throws ParseException if the character is unknown + */ + public Atom convertCharacter(char c, boolean oneChar) throws ParseException { + if (ignoreWhiteSpace) {// The Unicode Greek letters in math mode are not drawn with the Greek font + if (c >= 945 && c <= 969) { + return SymbolAtom.get(TeXFormula.symbolMappings[c]); + } else if (c >= 913 && c <= 937) { + return new TeXFormula(TeXFormula.symbolFormulaMappings[c]).root; + } + } + + c = convertToRomanNumber(c); + if (((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z'))) { + Character.UnicodeBlock block = Character.UnicodeBlock.of(c); + if (!isLoading && !DefaultTeXFont.loadedAlphabets.contains(block)) { + DefaultTeXFont.addAlphabet(DefaultTeXFont.registeredAlphabets.get(block)); + } + + String symbolName = TeXFormula.symbolMappings[c]; + if (symbolName == null && (TeXFormula.symbolFormulaMappings == null || TeXFormula.symbolFormulaMappings[c] == null)) { + TeXFormula.FontInfos fontInfos = null; + boolean isLatin = Character.UnicodeBlock.BASIC_LATIN.equals(block); + if ((isLatin && TeXFormula.isRegisteredBlock(Character.UnicodeBlock.BASIC_LATIN)) || !isLatin) { + fontInfos = TeXFormula.getExternalFont(block); + } + if (fontInfos != null) { + if (oneChar) { + return new JavaFontRenderingAtom(Character.toString(c), fontInfos); + } + int start = pos++; + int end = len - 1; + while (pos < len) { + c = parseString.charAt(pos); + if (!Character.UnicodeBlock.of(c).equals(block)) { + end = --pos; + break; + } + pos++; + } + return new JavaFontRenderingAtom(parseString.substring(start, end + 1), fontInfos); + } + + if (!isPartial) { + throw new ParseException("Unknown character : '" + + Character.toString(c) + "' (or " + ((int) c) + ")"); + } else { + return new ColorAtom(new RomanAtom(new TeXFormula("\\text{(Unknown char " + ((int) c) + ")}").root), null, Color.RED); + } + } else { + if (!ignoreWhiteSpace) {// we are in text mode + if (TeXFormula.symbolTextMappings[c] != null) { + return SymbolAtom.get(TeXFormula.symbolTextMappings[c]).setUnicode(c); + } + } + if (TeXFormula.symbolFormulaMappings != null && TeXFormula.symbolFormulaMappings[c] != null) { + return new TeXFormula(TeXFormula.symbolFormulaMappings[c]).root; + } + + try { + return SymbolAtom.get(symbolName); + } catch (SymbolNotFoundException e) { + throw new ParseException("The character '" + + Character.toString(c) + + "' was mapped to an unknown symbol with the name '" + + symbolName + "'!", e); + } + } + } 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); + } + int start = pos++; + int end = len - 1; + while (pos < len) { + c = parseString.charAt(pos); + if (((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z'))) { + end = --pos; + break; + } + pos++; + } + return new JavaFontRenderingAtom(parseString.substring(start, end + 1), fontInfos); + } + + return new CharAtom(c, formula.textStyle, ignoreWhiteSpace); + } + } + + private String getCommand() { + int spos = ++pos; + char ch = '\0'; + + while (pos < len) { + ch = parseString.charAt(pos); + if ((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (atIsLetter == 0 || ch != '@')) + break; + + pos++; + } + + if (ch == '\0') + return ""; + + if (pos == spos) { + pos++; + } + + String com = parseString.substring(spos, pos); + if ("cr".equals(com) && pos < len && parseString.charAt(pos) == ' ') { + pos++; + } + + return com; + } + + private Atom processEscape() throws ParseException { + spos = pos; + String command = getCommand(); + + if (command.length() == 0) { + return new EmptyAtom(); + } + + if (MacroInfo.Commands.get(command) != null) + return processCommands(command); + + try { + return TeXFormula.get(command).root; + } catch (FormulaNotFoundException e) { + try { + return SymbolAtom.get(command); + } catch (SymbolNotFoundException e1) { } + } + + // not a valid command or symbol or predefined TeXFormula found + if (!isPartial) { + throw new ParseException("Unknown symbol or command or predefined TeXFormula: '" + command + "'"); + } else { + return new ColorAtom(new RomanAtom(new TeXFormula("\\backslash " + command).root), null, Color.RED); + } + } + + private void insert(int beg, int end, String formula) { + parseString.replace(beg, end, formula); + len = parseString.length(); + pos = beg; + insertion = true; + } + + /** Get the arguments ant the options of a command + * @param nbArgs the number of arguments of the command + * @param opts must be 1 if the options are found before the first argument and must be 2 if they must be found before the second argument + * @return an array containing arguments and at the end the options are put + */ + /* Should be improved */ + public String[] getOptsArgs(int nbArgs, int opts) { + //A maximum of 10 options can be passed to a command + String[] args = new String[nbArgs + 10 + 1]; + if (nbArgs != 0) { + + //We get the options just after the command name + if (opts == 1) { + int j = nbArgs + 1; + try { + for (; j < nbArgs + 11; j++) { + skipWhiteSpace(); + args[j] = getGroup(L_BRACK, R_BRACK); + } + } + catch (ParseException e) { + args[j] = null; + } + } + + //We get the first argument + skipWhiteSpace(); + try { + args[1] = getGroup(L_GROUP, R_GROUP); + } catch (ParseException e) { + if (parseString.charAt(pos) != '\\') { + args[1] = "" + parseString.charAt(pos); + pos++; + } + else + args[1] = getCommandWithArgs(getCommand()); + } + + //We get the options after the first argument + if (opts == 2) { + int j = nbArgs + 1; + try { + for (; j < nbArgs + 11; j++) { + skipWhiteSpace(); + args[j] = getGroup(L_BRACK, R_BRACK); + } + } + catch (ParseException e) { + args[j] = null; + } + } + + //We get the next arguments + for (int i = 2; i <= nbArgs; i++) { + skipWhiteSpace(); + try { + args[i] = getGroup(L_GROUP, R_GROUP); + } catch (ParseException e) { + if (parseString.charAt(pos) != '\\') { + args[i] = "" + parseString.charAt(pos); + pos++; + } + else { + args[i] = getCommandWithArgs(getCommand()); + } + } + } + + if (ignoreWhiteSpace) { + skipWhiteSpace(); + } + } + return args; + } + + /** + * return a string with command and options and args + * @param command name of command + * @return + * @author Juan Enrique Escobar Robles + */ + private String getCommandWithArgs(String command) { + if (command.equals("left")){ + return getGroup("\\left", "\\right"); + } + + MacroInfo mac = MacroInfo.Commands.get(command); + if (mac != null) { + int mac_opts = 0; + if (mac.hasOptions) { + mac_opts = mac.posOpts; + } + + String[] mac_args = getOptsArgs(mac.nbArgs, mac_opts); + StringBuffer mac_arg = new StringBuffer("\\"); + mac_arg.append(command); + for (int j = 0; j < mac.posOpts; j++) { + String arg_t = mac_args[mac.nbArgs + j + 1]; + if (arg_t != null) { + mac_arg.append("[").append(arg_t).append("]"); + } + } + + for (int j = 0; j < mac.nbArgs; j++) { + String arg_t = mac_args[j + 1]; + if (arg_t != null) { + mac_arg.append("{").append(arg_t).append("}"); + } + } + + return mac_arg.toString(); + } + + return "\\" + command; + } + + /** + * Processes the given TeX command (by parsing following command arguments + * in the parse string). + */ + private Atom processCommands(String command) throws ParseException { + MacroInfo mac = MacroInfo.Commands.get(command); + int opts = 0; + if (mac.hasOptions) + opts = mac.posOpts; + + String[] args = getOptsArgs(mac.nbArgs, opts); + args[0] = command; + + if (NewCommandMacro.isMacro(command)) { + String ret = (String) mac.invoke(this, args); + insert(spos, pos, ret); + return null; + } + + return (Atom) mac.invoke(this, args); + } + + /** Test the validity of the name of a command. It must contains only alpha characters and eventually a @ if makeAtletter activated + * @param com the command's name + * @return the validity of the name + */ + public final boolean isValidName(String com) { + if (com == null || "".equals(com)) { + return false; + } + + char c = '\0'; + if (com.charAt(0) == '\\') { + int pos = 1; + int len = com.length(); + while (pos < len) { + c = com.charAt(pos); + if (!Character.isLetter(c) && (atIsLetter == 0 || c != '@')) + break; + pos++; + } + } else { + return false; + } + + return Character.isLetter(c); + } + + /** Test the validity of a character in a command. It must contains only alpha characters and eventually a @ if makeAtletter activated + * @param com the command's name + * @return the validity of the name + */ + public final boolean isValidCharacterInCommand(char ch) { + return Character.isLetter(ch) || (atIsLetter != 0 && ch == '@'); + } + + private final void skipWhiteSpace() { + char c; + while (pos < len) { + c = parseString.charAt(pos); + if (c != ' ' && c != '\t' && c != '\n' && c != '\r') + break; + if (c == '\n') { + line++; + col = pos; + } + pos++; + } + } + + /** + * The aim of this method is to convert foreign number into roman ones ! + */ + private static char convertToRomanNumber(char c) { + if (c == 0x66b) {//Arabic dot + return '.'; + } else if (0x660 <= c && c <= 0x669) {//Arabic + return (char) (c - (char) 0x630); + } else if (0x6f0 <= c && c <= 0x6f9) {//Arabic + return (char) (c - (char) 0x6c0); + } else if (0x966 <= c && c <= 0x96f) {//Devanagari + return (char) (c - (char) 0x936); + } else if (0x9e6 <= c && c <= 0x9ef) {//Bengali + return (char) (c - (char) 0x9b6); + } else if (0xa66 <= c && c <= 0xa6f) {//Gurmukhi + return (char) (c - (char) 0xa36); + } else if (0xae6 <= c && c <= 0xaef) {//Gujarati + return (char) (c - (char) 0xab6); + } else if (0xb66 <= c && c <= 0xb6f) {//Oriya + return (char) (c - (char) 0xb36); + } else if (0xc66 <= c && c <= 0xc6f) {//Telugu + return (char) (c - (char) 0xc36); + } else if (0xd66 <= c && c <= 0xd6f) {//Malayalam + return (char) (c - (char) 0xd36); + } else if (0xe50 <= c && c <= 0xe59) {//Thai + return (char) (c - (char) 0xe20); + } else if (0xed0 <= c && c <= 0xed9) {//Lao + return (char) (c - (char) 0xea0); + } else if (0xf20 <= c && c <= 0xf29) {//Tibetan + return (char) (c - (char) 0xe90); + } else if (0x1040 <= c && c <= 0x1049) {//Myanmar + return (char) (c - (char) 0x1010); + } else if (0x17e0 <= c && c <= 0x17e9) {//Khmer + return (char) (c - (char) 0x17b0); + } else if (0x1810 <= c && c <= 0x1819) {//Mongolian + return (char) (c - (char) 0x17e0); + } else if (0x1b50 <= c && c <= 0x1b59) {//Balinese + return (char) (c - (char) 0x1b20); + } else if (0x1bb0 <= c && c <= 0x1bb9) {//Sundanese + return (char) (c - (char) 0x1b80); + } else if (0x1c40 <= c && c <= 0x1c49) {//Lepcha + return (char) (c - (char) 0x1c10); + } else if (0x1c50 <= c && c <= 0x1c59) {//Ol Chiki + return (char) (c - (char) 0x1c20); + } else if (0xa8d0 <= c && c <= 0xa8d9) {//Saurashtra + return (char) (c - (char) 0xa8a0); + } + + return c; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXSymbolParser.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXSymbolParser.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TeXSymbolParser.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,129 @@ +/* TeXSymbolParser.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.util.HashMap; +import java.util.Map; +import java.io.InputStream; + +import javax.xml.parsers.DocumentBuilderFactory; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * Parses TeX symbol definitions from an XML-file. + */ +public class TeXSymbolParser { + + public static final String RESOURCE_NAME = "TeXSymbols.xml", + DELIMITER_ATTR = "del", TYPE_ATTR = "type"; + + private static Map typeMappings = new HashMap(); + + private Element root; + + public TeXSymbolParser() throws ResourceParseException { + this(TeXSymbolParser.class.getResourceAsStream(RESOURCE_NAME), RESOURCE_NAME); + } + + public TeXSymbolParser(InputStream file, String name) throws ResourceParseException { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setIgnoringElementContentWhitespace(true); + factory.setIgnoringComments(true); + root = factory.newDocumentBuilder().parse(file).getDocumentElement(); + // set possible valid symbol type mappings + setTypeMappings(); + } catch (Exception e) { // JDOMException or IOException + throw new XMLResourceParseException(name, e); + } + } + + public Map readSymbols() throws ResourceParseException { + Map res = new HashMap(); + // iterate all "symbol"-elements + NodeList list = root.getElementsByTagName("Symbol"); + for (int i = 0; i < list.getLength(); i++) { + Element symbol = (Element)list.item(i); + // retrieve and check required attributes + String name = getAttrValueAndCheckIfNotNull("name", symbol), type = getAttrValueAndCheckIfNotNull( + TYPE_ATTR, symbol); + // retrieve optional attribute + String del = symbol.getAttribute(DELIMITER_ATTR); + boolean isDelimiter = (del != null && del.equals("true")); + // check if type is known + Object typeVal = typeMappings.get(type); + if (typeVal == null) // unknown type + throw new XMLResourceParseException(RESOURCE_NAME, "Symbol", + "type", "has an unknown value '" + type + "'!"); + // add symbol to the hash table + res.put(name, new SymbolAtom(name, ((Integer) typeVal).intValue(), + isDelimiter)); + } + return res; + } + + private void setTypeMappings() { + typeMappings.put("ord", TeXConstants.TYPE_ORDINARY); + typeMappings.put("op", TeXConstants.TYPE_BIG_OPERATOR); + typeMappings.put("bin", TeXConstants.TYPE_BINARY_OPERATOR); + typeMappings.put("rel", TeXConstants.TYPE_RELATION); + typeMappings.put("open", TeXConstants.TYPE_OPENING); + typeMappings.put("close", TeXConstants.TYPE_CLOSING); + typeMappings.put("punct", TeXConstants.TYPE_PUNCTUATION); + typeMappings.put("acc", TeXConstants.TYPE_ACCENT); + } + + private static String getAttrValueAndCheckIfNotNull(String attrName, + Element element) throws ResourceParseException { + String attrValue = element.getAttribute(attrName); + if (attrValue.equals("")) + throw new XMLResourceParseException(RESOURCE_NAME, element.getTagName(), + attrName, null); + return attrValue; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TextCircledAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TextCircledAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TextCircledAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,68 @@ +/* TextCircledAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom with representing an t with a caron. + */ +public class TextCircledAtom extends Atom { + + private Atom at; + + public TextCircledAtom(Atom at) { + this.at = at; + } + + public Box createBox(TeXEnvironment env) { + Box circle = SymbolAtom.get("bigcirc").createBox(env); + circle.setShift(-0.07f * SpaceAtom.getFactor(TeXConstants.UNIT_EX, env)); + Box box = at.createBox(env); + HorizontalBox hb = new HorizontalBox(box, circle.getWidth(), TeXConstants.ALIGN_CENTER); + hb.add(new StrutBox(-hb.getWidth(), 0, 0, 0)); + hb.add(circle); + return hb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TextStyleAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TextStyleAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TextStyleAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,68 @@ +/* TextStyleAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a modification of style in a formula (e.g. textstyle or displaystyle). + */ +public class TextStyleAtom extends Atom { + + private String style; + private Atom at; + + public TextStyleAtom(Atom at, String style) { + this.style = style; + this.at = at; + } + + public Box createBox(TeXEnvironment env) { + String prevStyle = env.getTextStyle(); + env.setTextStyle(style); + Box box = at.createBox(env); + env.setTextStyle(prevStyle); + return box; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TextStyleMappingNotFoundException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TextStyleMappingNotFoundException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TextStyleMappingNotFoundException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,61 @@ +/* TextStyleMappingNotFoundException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * Signals a missing text style mapping. + * + * @author Kurt Vermeulen + */ +public class TextStyleMappingNotFoundException extends JMathTeXException { + + protected TextStyleMappingNotFoundException(String styleName) { + super("No mapping found for the text style '" + styleName + "'! " + + "Insert a <" + DefaultTeXFontParser.STYLE_MAPPING_EL + + ">-element in '" + DefaultTeXFontParser.RESOURCE_NAME + "'."); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TtAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TtAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TtAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,67 @@ +/* TtAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a typewriter atom. + */ +public class TtAtom extends Atom { + + private Atom base; + + public TtAtom(Atom base) { + this.base = base; + } + + public Box createBox(TeXEnvironment env) { + env = env.copy(env.getTeXFont().copy()); + env.getTeXFont().setTt(true); + Box box = base.createBox(env); + env.getTeXFont().setTt(false); + return box; + } + +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TypedAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TypedAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/TypedAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,84 @@ +/* TypedAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing another atom with an overrided lefttype and righttype. This + * affects the glue inserted before and after this atom. + */ +public class TypedAtom extends Atom { + + // new lefttype and righttype + private final int leftType; + private final int rightType; + + // atom for which new types are set + private final Atom atom; + + public TypedAtom(int leftType, int rightType, Atom atom) { + this.leftType = leftType; + this.rightType = rightType; + this.atom = atom; + this.type_limits = atom.type_limits; + } + + public Atom getBase() { + atom.type_limits = type_limits; + return atom; + } + + public Box createBox(TeXEnvironment env) { + return atom.createBox(env); + } + + public int getLeftType() { + return leftType; + } + + public int getRightType() { + return rightType; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/URLAlphabetRegistration.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/URLAlphabetRegistration.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/URLAlphabetRegistration.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,95 @@ +/* URLAlphabetRegistration.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.lang.Character.UnicodeBlock; +import java.net.URL; +import java.net.URLClassLoader; +import java.lang.ClassLoader; + +public class URLAlphabetRegistration implements AlphabetRegistration { + + private URL url; + private String language; + private AlphabetRegistration pack = null; + private Character.UnicodeBlock[] blocks; + + private URLAlphabetRegistration(URL url, String language, Character.UnicodeBlock[] blocks) { + this.url = url; + this.language = language; + this.blocks = blocks; + } + + public static void register(URL url, String language, Character.UnicodeBlock[] blocks) { + DefaultTeXFont.registerAlphabet(new URLAlphabetRegistration(url, language, blocks)); + } + + public Character.UnicodeBlock[] getUnicodeBlock() { + return blocks; + } + + public Object getPackage() throws AlphabetRegistrationException { + URL urls[] = {url}; + language = language.toLowerCase(); + String name = "org.scilab.forge.jlatexmath." + language + + "." + Character.toString(Character.toUpperCase(language.charAt(0))) + + language.substring(1, language.length()) + "Registration"; + + try { + ClassLoader loader = new URLClassLoader(urls); + pack = (AlphabetRegistration) Class.forName(name, true, loader).newInstance(); + } catch (ClassNotFoundException e) { + throw new AlphabetRegistrationException("Class at " + url + " cannot be got."); + } catch (Exception e) { + throw new AlphabetRegistrationException("Problem in loading the class at " + url + " :\n" + e.getMessage()); + } + return pack; + } + + public String getTeXFontFileName() { + return pack.getTeXFontFileName(); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/UnderOverArrowAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/UnderOverArrowAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/UnderOverArrowAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,104 @@ +/* UnderOverArrowAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing an other atom with an extensible arrow or doublearrow over or under it. + */ +public class UnderOverArrowAtom extends Atom { + + private Atom base; + private String arrow; + private boolean over, left = false, dble = false; + + public UnderOverArrowAtom(Atom base, boolean left, boolean over) { + this.base = base; + this.arrow = left ? "leftarrow" : "rightarrow"; + this.left = left; + this.over = over; + } + + public UnderOverArrowAtom(Atom base, boolean over) { + this.base = base; + this.over = over; + this.dble = true; + } + + public Box createBox(TeXEnvironment env) { + TeXFont tf = env.getTeXFont(); + int style = env.getStyle(); + Box b = base != null ? base.createBox(env) : new StrutBox(0, 0, 0, 0); + float sep = new SpaceAtom(TeXConstants.UNIT_POINT, 1f, 0, 0).createBox(env).getWidth(); + Box arrow; + + if (dble) { + arrow = XLeftRightArrowFactory.create(env, b.getWidth()); + sep = 4 * sep; + } else { + arrow = XLeftRightArrowFactory.create(left, env, b.getWidth()); + sep = -sep; + } + + VerticalBox vb = new VerticalBox(); + if (over) { + vb.add(arrow); + vb.add(new HorizontalBox(b, arrow.getWidth(), TeXConstants.ALIGN_CENTER)); + float h = vb.getDepth() + vb.getHeight(); + vb.setDepth(b.getDepth()); + vb.setHeight(h - b.getDepth()); + } else { + vb.add(new HorizontalBox(b, arrow.getWidth(), TeXConstants.ALIGN_CENTER)); + vb.add(new StrutBox(0, sep, 0, 0)); + vb.add(arrow); + float h = vb.getDepth() + vb.getHeight(); + vb.setDepth(h - b.getHeight()); + vb.setHeight(b.getHeight()); + } + + return vb; + + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/UnderOverAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/UnderOverAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/UnderOverAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,183 @@ +/* UnderOverAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing another atom with an atom above it (if not null) seperated + * by a kern and in a smaller size depending on "overScriptSize" and/or an atom under + * it (if not null) seperated by a kern and in a smaller size depending on "underScriptSize" + */ +public class UnderOverAtom extends Atom { + + // base, underscript and overscript + private final Atom base; + private final Atom under; + private final Atom over; + + // kern between base and under- and overscript + private final float underSpace; + private final float overSpace; + + // units for the kerns + private final int underUnit; // NOPMD + // TODO: seems never to be used? + private final int overUnit; + + // whether the under- and overscript should be drawn in a smaller size + private final boolean underScriptSize; + private final boolean overScriptSize; + + public UnderOverAtom(Atom base, Atom underOver, int underOverUnit, + float underOverSpace, boolean underOverScriptSize, boolean over) { + // check if unit is valid + SpaceAtom.checkUnit(underOverUnit); + // units valid + this.base = base; + + if (over) { + this.under = null; + this.underSpace = 0.0f; + this.underUnit = 0; + this.underScriptSize = false; + this.over = underOver; + this.overUnit = underOverUnit; + this.overSpace = underOverSpace; + this.overScriptSize = underOverScriptSize; + } else { + this.under = underOver; + this.underUnit = underOverUnit; + this.underSpace = underOverSpace; + this.underScriptSize = underOverScriptSize; + this.overSpace = 0.0f; + this.over = null; + this.overUnit = 0; + this.overScriptSize = false; + } + } + + public UnderOverAtom(Atom base, Atom under, int underUnit, float underSpace, + boolean underScriptSize, Atom over, int overUnit, float overSpace, + boolean overScriptSize) throws InvalidUnitException { + // check if units are valid + SpaceAtom.checkUnit(underUnit); + SpaceAtom.checkUnit(overUnit); + + // units valid + this.base = base; + this.under = under; + this.underUnit = underUnit; + this.underSpace = underSpace; + this.underScriptSize = underScriptSize; + this.over = over; + this.overUnit = overUnit; + this.overSpace = overSpace; + this.overScriptSize = overScriptSize; + } + + public Box createBox(TeXEnvironment env) { + // create boxes in right style and calculate maximum width + Box b = (base == null ? new StrutBox(0, 0, 0, 0) : base.createBox(env)); + Box o = null, u = null; + float max = b.getWidth(); + if (over != null) { + o = over.createBox(overScriptSize ? env.subStyle() : env); + max = Math.max(max, o.getWidth()); + } + if (under != null) { + u = under.createBox(underScriptSize ? env.subStyle() : env); + max = Math.max(max, u.getWidth()); + } + + // create vertical box + VerticalBox vBox = new VerticalBox(); + + // last font used by the base (for Mspace atoms following) + env.setLastFontId(b.getLastFontId()); + + // overscript + space + if (over != null) { + vBox.add(changeWidth(o, max)); + // unit will be valid (checked in constructor) + vBox.add(new SpaceAtom(overUnit, 0, overSpace, 0).createBox(env)); + } + + // base + Box c = changeWidth(b, max); + vBox.add(c); + + // calculate future height of the vertical box (to make sure that the base + // stays on the baseline!) + float h = vBox.getHeight() + vBox.getDepth() - c.getDepth(); + + // underscript + space + if (under != null) { + // unit will be valid (checked in constructor) + vBox.add(new SpaceAtom(overUnit, 0, underSpace, 0).createBox(env)); + vBox.add(changeWidth(u, max)); + } + + // set height and depth + vBox.setDepth(vBox.getHeight() + vBox.getDepth() - h); + vBox.setHeight(h); + return vBox; + } + + private static Box changeWidth(Box b, float maxWidth) { + if (b != null && Math.abs(maxWidth - b.getWidth()) > TeXFormula.PREC) + return new HorizontalBox(b, maxWidth, TeXConstants.ALIGN_CENTER); + else + return b; + } + + public int getLeftType() { + return base.getLeftType(); + } + + public int getRightType() { + return base.getRightType(); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/UnderlinedAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/UnderlinedAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/UnderlinedAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,81 @@ +/* UnderlinedAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing another atom with a line under it. + */ +class UnderlinedAtom extends Atom { + + // the base to be underlined + private final Atom base; + + public UnderlinedAtom(Atom f) { + base = f; + type = TeXConstants.TYPE_ORDINARY; // for spacing rules + } + + public Box createBox(TeXEnvironment env) { + float drt = env.getTeXFont().getDefaultRuleThickness(env.getStyle()); + + // create formula box in same style + Box b = (base == null ? new StrutBox(0, 0, 0, 0) : base.createBox(env)); + + // create vertical box + VerticalBox vBox = new VerticalBox(); + vBox.add(b); + vBox.add(new StrutBox(0, 3 * drt, 0, 0)); + vBox.add(new HorizontalRule(drt, b.getWidth(), 0)); + + // baseline vertical box = baseline box b + // there's also an invisible strut of height drt under the rule + vBox.setDepth(b.getDepth() + 5 * drt); + vBox.setHeight(b.getHeight()); + + return vBox; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/UnderscoreAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/UnderscoreAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/UnderscoreAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,65 @@ +/* UnderscoreAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing an underscore. + */ +public class UnderscoreAtom extends Atom { + + public static SpaceAtom w = new SpaceAtom(TeXConstants.UNIT_EM, 0.7f, 0, 0); + public static SpaceAtom s = new SpaceAtom(TeXConstants.UNIT_EM, 0.06f, 0, 0); + + public UnderscoreAtom() { + } + + public Box createBox(TeXEnvironment env) { + float drt = env.getTeXFont().getDefaultRuleThickness(env.getStyle()); + HorizontalBox hb = new HorizontalBox(s.createBox(env)); + hb.add(new HorizontalRule(drt, w.createBox(env).getWidth(), 0)); + return hb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VCenteredAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VCenteredAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VCenteredAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,74 @@ +/* VCenteredAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing another atom vertically centered with respect to the axis + * (determined by a general TeXFont parameter) + */ +public class VCenteredAtom extends Atom { + + // atom to be centered vertically with respect to the axis + private final Atom atom; + + public VCenteredAtom(Atom atom) { + this.atom = atom; + } + + public Box createBox(TeXEnvironment env) { + Box b = atom.createBox(env); + + float total = b.getHeight() + b.getDepth(), axis = env.getTeXFont() + .getAxisHeight(env.getStyle()); + + // center on axis + b.setShift(-(total / 2) - axis); + + // put in horizontal box, so shifting will be vertically! + return new HorizontalBox(b); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VRowAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VRowAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VRowAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,171 @@ +/* VRowAtom.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +/* Modified by Calixte Denizet */ + +package org.scilab.forge.jlatexmath; + +import java.util.BitSet; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; + +/** + * An atom representing a vertical row of other atoms. + */ +public class VRowAtom extends Atom { + + // atoms to be displayed horizontally next to eachother + protected LinkedList elements = new LinkedList(); + private SpaceAtom raise = new SpaceAtom(TeXConstants.UNIT_EX, 0, 0, 0); + protected boolean addInterline = false; + protected boolean vtop = false; + protected int halign = TeXConstants.ALIGN_NONE; + + public VRowAtom() { + // empty + } + + public VRowAtom(Atom el) { + if (el != null) { + if (el instanceof VRowAtom) + // no need to make an mrow the only element of an mrow + elements.addAll(((VRowAtom) el).elements); + else + elements.add(el); + } + } + + public void setAddInterline(boolean addInterline) { + this.addInterline = addInterline; + } + + public boolean getAddInterline() { + return this.addInterline; + } + + public void setHalign(int halign) { + this.halign = halign; + } + + public int getHalign() { + return halign; + } + + public void setVtop(boolean vtop) { + this.vtop = vtop; + } + + public boolean getVtop() { + return vtop; + } + + public void setRaise(int unit, float r) { + raise = new SpaceAtom(unit, r, 0, 0); + } + + public Atom getLastAtom() { + return elements.removeLast(); + } + + public final void add(Atom el) { + if (el != null) + elements.add(0, el); + } + + public final void append(Atom el) { + if (el != null) + elements.add(el); + } + + public Box createBox(TeXEnvironment env) { + VerticalBox vb = new VerticalBox(); + if (halign != TeXConstants.ALIGN_NONE) { + float maxWidth = -Float.POSITIVE_INFINITY; + LinkedList boxes = new LinkedList<>(); + for (ListIterator it = elements.listIterator(); it.hasNext();) { + Box b = ((Atom)it.next()).createBox(env); + boxes.add(b); + if (maxWidth < b.getWidth()) { + maxWidth = b.getWidth(); + } + } + Box interline = new StrutBox(0, env.getInterline(), 0, 0); + + // convert atoms to boxes and add to the horizontal box + for (ListIterator it = boxes.listIterator(); it.hasNext();) { + Box b = (Box) it.next(); + vb.add(new HorizontalBox(b, maxWidth, halign)); + if (addInterline && it.hasNext()) { + vb.add(interline); + } + } + } else { + Box interline = new StrutBox(0, env.getInterline(), 0, 0); + + // convert atoms to boxes and add to the horizontal box + for (ListIterator it = elements.listIterator(); it.hasNext();) { + vb.add(((Atom)it.next()).createBox(env)); + if (addInterline && it.hasNext()) { + vb.add(interline); + } + } + } + + vb.setShift(-raise.createBox(env).getWidth()); + if (vtop) { + float t = vb.getSize() == 0 ? 0 : vb.children.getFirst().getHeight(); + vb.setHeight(t); + vb.setDepth(vb.getDepth() + vb.getHeight() - t); + } else { + float t = vb.getSize() == 0 ? 0 : vb.children.getLast().getDepth(); + vb.setHeight(vb.getDepth() + vb.getHeight() - t); + vb.setDepth(t); + } + + return vb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VdotsAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VdotsAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VdotsAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,70 @@ +/* VdotsAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing vdots. + */ +public class VdotsAtom extends Atom { + + public VdotsAtom() { } + + public Box createBox(TeXEnvironment env) { + Box dot = SymbolAtom.get("ldotp").createBox(env); + VerticalBox vb = new VerticalBox(dot, 0, TeXConstants.ALIGN_BOTTOM); + Box b = new SpaceAtom(TeXConstants.UNIT_MU, 0, 4, 0).createBox(env); + vb.add(b); + vb.add(dot); + vb.add(b); + vb.add(dot); + float d = vb.getDepth(); + float h = vb.getHeight(); + vb.setDepth(0); + vb.setHeight(d + h); + + return vb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VerticalBox.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VerticalBox.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VerticalBox.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,136 @@ +/* VerticalBox.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Graphics2D; +import java.util.ListIterator; + +/** + * A box composed of other boxes, put one above the other. + */ +class VerticalBox extends Box { + + private float leftMostPos = Float.MAX_VALUE; + private float rightMostPos = -Float.MAX_VALUE; + + public VerticalBox() { } + + public VerticalBox(Box b, float rest, int alignment) { + this(); + add(b); + if (alignment == TeXConstants.ALIGN_CENTER) { + StrutBox s = new StrutBox(0, rest / 2, 0, 0); + super.add(0, s); + height += rest / 2; + depth += rest / 2; + super.add(s); + } else if (alignment == TeXConstants.ALIGN_TOP) { + depth += rest; + super.add(new StrutBox(0, rest, 0, 0)); + } else if (alignment == TeXConstants.ALIGN_BOTTOM) { + height += rest; + super.add(0, new StrutBox(0, rest, 0, 0)); + } + } + + public final void add(Box b) { + super.add(b); + if (children.size() == 1) { + height = b.height; + depth = b.depth; + } else + 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); + rightMostPos = Math.max(rightMostPos, b.shift + (b.width > 0 ? b.width : 0)); + width = rightMostPos - leftMostPos; + } + + public void add(int pos, Box b) { + super.add(pos, b); + if (pos == 0) { + depth += b.depth + height; + height = b.height; + } else + depth += b.height + b.depth; + recalculateWidth(b); + } + + public void draw(Graphics2D g2, float x, float y) { + float yPos = y - height; + for (Box b : children) { + yPos += b.getHeight(); + b.draw(g2, x + b.getShift() - leftMostPos, yPos); + yPos += b.getDepth(); + } + } + + public int getSize() { + return children.size(); + } + + public int getLastFontId() { + // iterate from the last child box (the lowest) to the first (the highest) + // untill a font id is found that's not equal to NO_FONT + int fontId = TeXFont.NO_FONT; + for (ListIterator it = children.listIterator(children.size()); fontId == TeXFont.NO_FONT + && it.hasPrevious();) + fontId = ((Box) it.previous()).getLastFontId(); + + return fontId; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VlineAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VlineAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/VlineAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,97 @@ +/* VlineAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing a hline in array environment + */ +public class VlineAtom extends Atom { + + private float height; + private float shift; + private int n; + + public VlineAtom(int n) { + this.n = n; + } + + public void setHeight(float height) { + this.height = height; + } + + public void setShift(float shift) { + this.shift = shift; + } + + public float getWidth(TeXEnvironment env) { + if (n != 0) { + float drt = env.getTeXFont().getDefaultRuleThickness(env.getStyle()); + return drt * (3 * n - 2); + } else + return 0; + } + + public Box createBox(TeXEnvironment env) { + if (n != 0) { + float drt = env.getTeXFont().getDefaultRuleThickness(env.getStyle()); + Box b = new HorizontalRule(height, drt, shift); + Box sep = new StrutBox(2 * drt, 0, 0, 0); + HorizontalBox hb = new HorizontalBox(); + for (int i = 0; i < n - 1; i++) { + hb.add(b); + hb.add(sep); + } + + if (n > 0) { + hb.add(b); + } + + return hb; + } + + return new StrutBox(0, 0, 0, 0); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/WebStartAlphabetRegistration.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/WebStartAlphabetRegistration.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/WebStartAlphabetRegistration.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,84 @@ +/* WebStartAlphabetRegistration.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.lang.Character.UnicodeBlock; + +import org.scilab.forge.jlatexmath.cyrillic.CyrillicRegistration; +import org.scilab.forge.jlatexmath.greek.GreekRegistration; + +public class WebStartAlphabetRegistration implements AlphabetRegistration { + + private Character.UnicodeBlock[] blocks; + private AlphabetRegistration reg; + + private WebStartAlphabetRegistration(Character.UnicodeBlock[] blocks) { + this.blocks = blocks; + } + + public static void register(Character.UnicodeBlock[] blocks) { + DefaultTeXFont.registerAlphabet(new WebStartAlphabetRegistration(blocks)); + } + + public Character.UnicodeBlock[] getUnicodeBlock() { + return blocks; + } + + public Object getPackage() throws AlphabetRegistrationException { + if (blocks == JLM_GREEK) { + reg = new GreekRegistration(); + } else if (blocks == JLM_CYRILLIC) { + reg = new CyrillicRegistration(); + } else { + throw new AlphabetRegistrationException("Invalid Unicode Block"); + } + return reg; + } + + public String getTeXFontFileName() { + return reg.getTeXFontFileName(); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/XArrowAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/XArrowAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/XArrowAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,91 @@ +/* XArrowAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom representing an extensible left or right arrow to handle xleftarrow and xrightarrow commands in LaTeX. + */ +public class XArrowAtom extends Atom { + + private Atom over, under; + private boolean left; + + public XArrowAtom(Atom over, Atom under, boolean left) { + this.over = over; + this.under = under; + this.left = left; + } + + public Box createBox(TeXEnvironment env) { + TeXFont tf = env.getTeXFont(); + int style = env.getStyle(); + Box O = over != null ? over.createBox(env.supStyle()) : new StrutBox(0, 0, 0, 0); + Box U = under != null ? under.createBox(env.subStyle()) : new StrutBox(0, 0, 0, 0); + Box oside = new SpaceAtom(TeXConstants.UNIT_EM, 1.5f, 0, 0).createBox(env.supStyle()); + Box uside = new SpaceAtom(TeXConstants.UNIT_EM, 1.5f, 0, 0).createBox(env.subStyle()); + Box sep = new SpaceAtom(TeXConstants.UNIT_MU, 0, 2f, 0).createBox(env); + float width = Math.max(O.getWidth() + 2 * oside.getWidth(), U.getWidth() + 2 * uside.getWidth()); + Box arrow = XLeftRightArrowFactory.create(left, env, width); + + Box ohb = new HorizontalBox(O, width, TeXConstants.ALIGN_CENTER); + Box uhb = new HorizontalBox(U, width, TeXConstants.ALIGN_CENTER); + + VerticalBox vb = new VerticalBox(); + vb.add(ohb); + vb.add(sep); + vb.add(arrow); + vb.add(sep); + vb.add(uhb); + + float h = vb.getHeight() + vb.getDepth(); + float d = sep.getHeight() + sep.getDepth() + uhb.getHeight() + uhb.getDepth(); + vb.setDepth(d); + vb.setHeight(h - d); + + HorizontalBox hb = new HorizontalBox(vb, vb.getWidth() + 2*sep.getHeight(), TeXConstants.ALIGN_CENTER); + return hb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/XLeftRightArrowFactory.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/XLeftRightArrowFactory.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/XLeftRightArrowFactory.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,138 @@ +/* XLeftRightArrowFactory.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://jlatexmath.sourceforge.net + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +import java.awt.Color; + +/** + * Responsible for creating a box containing a delimiter symbol that exists + * in different sizes. + */ +public class XLeftRightArrowFactory { + + private static final Atom MINUS = SymbolAtom.get("minus"); + private static final Atom LEFT = SymbolAtom.get("leftarrow"); + private static final Atom RIGHT = SymbolAtom.get("rightarrow"); + + public static Box create(boolean left, TeXEnvironment env, float width) { + TeXFont tf = env.getTeXFont(); + int style = env.getStyle(); + Box arr = left ? LEFT.createBox(env) : RIGHT.createBox(env); + float h = arr.getHeight(); + float d = arr.getDepth(); + + float swidth = arr.getWidth(); + if (width <= swidth) { + arr.setDepth(d / 2); + return arr; + } + + Box minus = new SmashedAtom(MINUS, "").createBox(env); + Box kern = new SpaceAtom(TeXConstants.UNIT_MU, -4f, 0, 0).createBox(env); + float mwidth = minus.getWidth() + kern.getWidth(); + swidth += kern.getWidth(); + HorizontalBox hb = new HorizontalBox(); + float w; + for (w = 0; w < width - swidth - mwidth; w += mwidth) { + hb.add(minus); + hb.add(kern); + } + + float sf = (width - swidth - w) / minus.getWidth(); + + hb.add(new SpaceAtom(TeXConstants.UNIT_MU, -2f * sf, 0, 0).createBox(env)); + hb.add(new ScaleAtom(MINUS, sf, 1).createBox(env)); + + if (left) { + hb.add(0, new SpaceAtom(TeXConstants.UNIT_MU, -3.5f, 0, 0).createBox(env)); + hb.add(0, arr); + } else { + hb.add(new SpaceAtom(TeXConstants.UNIT_MU, -2f * sf - 2f, 0, 0).createBox(env)); + hb.add(arr); + } + + hb.setDepth(d / 2); + hb.setHeight(h); + + return hb; + } + + public static Box create(TeXEnvironment env, float width) { + TeXFont tf = env.getTeXFont(); + int style = env.getStyle(); + Box left = LEFT.createBox(env); + Box right = RIGHT.createBox(env); + float swidth = left.getWidth() + right.getWidth(); + + if (width < swidth) { + HorizontalBox hb = new HorizontalBox(left); + hb.add(new StrutBox(-Math.min(swidth - width, left.getWidth()), 0, 0, 0)); + hb.add(right); + return hb; + } + + Box minus = new SmashedAtom(MINUS, "").createBox(env); + Box kern = new SpaceAtom(TeXConstants.UNIT_MU, -3.4f, 0, 0).createBox(env); + float mwidth = minus.getWidth() + kern.getWidth(); + swidth += 2 * kern.getWidth(); + + HorizontalBox hb = new HorizontalBox(); + float w; + for (w = 0; w < width - swidth - mwidth; w += mwidth) { + hb.add(minus); + hb.add(kern); + } + + hb.add(new ScaleBox(minus, (width - swidth - w) / minus.getWidth(), 1)); + + hb.add(0, kern); + hb.add(0, left); + hb.add(kern); + hb.add(right); + + return hb; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/XMLResourceParseException.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/XMLResourceParseException.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/XMLResourceParseException.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,89 @@ +/* XMLResourceParseException.java + * ========================================================================= + * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net + * + * Copyright (C) 2004-2007 Universiteit Gent + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +public class XMLResourceParseException extends ResourceParseException { + + /* + * Attribute problem + */ + public XMLResourceParseException(String resourceName, String elementName, String attributeName, String msg) { + super(resourceName + ": invalid <" + elementName + + ">-element found: attribute '" + attributeName + "' " + + (msg == null ? "is required!" : msg)); + } + + /* + * Attribute problem + */ + public XMLResourceParseException(String resourceName, String elementName, String attributeName, String msg, Throwable e) { + super(resourceName + ": invalid <" + elementName + + ">-element found: attribute '" + attributeName + "' " + + (msg == null ? "is required!" : msg), e); + } + /* + * required element missing + */ + public XMLResourceParseException(String resourceName, String elementName) { + super(resourceName + ": the required <" + elementName + + ">-element is not found!"); + } + + /* + * JDOMException or IOException + */ + public XMLResourceParseException(String resourceName, Throwable e) { + super(resourceName, e); + } + + /* + * for other cases + */ + public XMLResourceParseException(String msg) { + super(msg); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/cache/JLaTeXMathCache.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/cache/JLaTeXMathCache.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/cache/JLaTeXMathCache.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,348 @@ +/* JLaTeXMathCache.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/p/jlatexmath + * + * Copyright (C) 2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath.cache; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Insets; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; +import java.lang.ref.ReferenceQueue; +import java.lang.ref.Reference; +import java.lang.ref.SoftReference; +import java.util.Iterator; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ConcurrentHashMap; + +import org.scilab.forge.jlatexmath.ParseException; +import org.scilab.forge.jlatexmath.TeXFormula; +import org.scilab.forge.jlatexmath.TeXIcon; + +/** + * Class to cache generated image from formulas + * @author Calixte DENIZET + */ +public final class JLaTeXMathCache { + + private static final AffineTransform identity = new AffineTransform(); + private static ConcurrentMap> cache = new ConcurrentHashMap>(128); + private static int max = Integer.MAX_VALUE; + private static ReferenceQueue queue = new ReferenceQueue(); + + private JLaTeXMathCache() { } + + /** + * Set max size. Take care the cache will be reinitialized + * @param max the max size + */ + public static void setMaxCachedObjects(int max) { + JLaTeXMathCache.max = Math.max(max, 1); + cache.clear(); + cache = new ConcurrentHashMap>(JLaTeXMathCache.max); + } + + /** + * @param f a formula + * @param style a style like TeXConstants.STYLE_DISPLAY + * @param size the size of font + * @param inset the inset to add on the top, bottom, left and right + * @return an array of length 3 containing width, height and depth + */ + public static int[] getCachedTeXFormulaDimensions(String f, int style, int type, int size, int inset, Color fgcolor) throws ParseException { + return getCachedTeXFormulaDimensions(new CachedTeXFormula(f, style, type, size, inset, fgcolor)); + } + + public static int[] getCachedTeXFormulaDimensions(String f, int style, int size, int inset) throws ParseException { + return getCachedTeXFormulaDimensions(f, style, 0, size, inset, null); + } + + /** + * @param o an Object to identify the image in the cache + * @return an array of length 3 containing width, height and depth + */ + public static int[] getCachedTeXFormulaDimensions(Object o) throws ParseException { + if (o == null || !(o instanceof CachedTeXFormula)) { + return new int[]{0, 0, 0}; + } + CachedTeXFormula cached = (CachedTeXFormula) o; + SoftReference img = cache.get(cached); + if (img == null || img.get() == null) { + img = makeImage(cached); + } + + return new int[]{cached.width, cached.height, cached.depth}; + } + + /** + * Get a cached formula + * @param f a formula + * @param style a style like TeXConstants.STYLE_DISPLAY + * @param size the size of font + * @param inset the inset to add on the top, bottom, left and right + * @return the key in the map + */ + public static Object getCachedTeXFormula(String f, int style, int type, int size, int inset, Color fgcolor) throws ParseException { + CachedTeXFormula cached = new CachedTeXFormula(f, style, type, size, inset, fgcolor); + SoftReference img = cache.get(cached); + if (img == null || img.get() == null) { + img = makeImage(cached); + } + + return cached; + } + + public static Object getCachedTeXFormula(String f, int style, int size, int inset) throws ParseException { + return getCachedTeXFormula(f, style, 0, size, inset, null); + } + + /** + * Clear the cache + */ + public static void clearCache() { + cache.clear(); + } + + /** + * Remove a formula from the cache + * @param f a formula + * @param style a style like TeXConstants.STYLE_DISPLAY + * @param size the size of font + * @param inset the inset to add on the top, bottom, left and right + */ + public static void removeCachedTeXFormula(String f, int style, int type, int size, int inset, Color fgcolor) throws ParseException { + cache.remove(new CachedTeXFormula(f, style, type, size, inset, fgcolor)); + } + + public static void removeCachedTeXFormula(String f, int style, int size, int inset) throws ParseException { + removeCachedTeXFormula(f, style, 0, size, inset, null); + } + + /** + * Remove a formula from the cache. Take care, remove the Object o, invalidate it ! + * @param o an Object to identify the image in the cache + */ + public static void removeCachedTeXFormula(Object o) throws ParseException { + if (o != null && o instanceof CachedTeXFormula) { + cache.remove((CachedTeXFormula) o); + } + } + + /** + * Paint a cached formula + * @param f a formula + * @param style a style like TeXConstants.STYLE_DISPLAY + * @param size the size of font + * @param inset the inset to add on the top, bottom, left and right + * @return the key in the map + */ + public static Object paintCachedTeXFormula(String f, int style, int type, int size, int inset, Color fgcolor, Graphics2D g) throws ParseException { + return paintCachedTeXFormula(new CachedTeXFormula(f, style, type, size, inset, fgcolor), g); + } + + public static Object paintCachedTeXFormula(String f, int style, int size, int inset, Graphics2D g) throws ParseException { + return paintCachedTeXFormula(f, style, 0, size, inset, null, g); + } + + /** + * Paint a cached formula + * @param o an Object to identify the image in the cache + * @param g the graphics where to paint the image + * @return the key in the map + */ + public static Object paintCachedTeXFormula(Object o, Graphics2D g) throws ParseException { + if (o == null || !(o instanceof CachedTeXFormula)) { + return null; + } + CachedTeXFormula cached = (CachedTeXFormula) o; + SoftReference img = cache.get(cached); + if (img == null || img.get() == null) { + img = makeImage(cached); + } + g.drawImage(img.get().image, identity, null); + + return cached; + } + + /** + * Get a cached formula + * @param f a formula + * @param style a style like TeXConstants.STYLE_DISPLAY + * @param size the size of font + * @param inset the inset to add on the top, bottom, left and right + * @return the cached image + */ + public static Image getCachedTeXFormulaImage(String f, int style, int type, int size, int inset, Color fgcolor) throws ParseException { + return getCachedTeXFormulaImage(new CachedTeXFormula(f, style, type, size, inset, fgcolor)); + } + + public static Image getCachedTeXFormulaImage(String f, int style, int size, int inset) throws ParseException { + return getCachedTeXFormulaImage(f, style, 0, size, inset, null); + } + + /** + * Get a cached formula + * @param o an Object to identify the image in the cache + * @return the cached image + */ + public static Image getCachedTeXFormulaImage(Object o) throws ParseException { + if (o == null || !(o instanceof CachedTeXFormula)) { + return null; + } + CachedTeXFormula cached = (CachedTeXFormula) o; + SoftReference img = cache.get(cached); + if (img == null || img.get() == null) { + img = makeImage(cached); + } + + return img.get().image; + } + + private static SoftReference makeImage(CachedTeXFormula cached) throws ParseException { + TeXFormula formula = new TeXFormula(cached.f); + TeXIcon icon = formula.createTeXIcon(cached.style, cached.size, cached.type, cached.fgcolor); + icon.setInsets(new Insets(cached.inset, cached.inset, cached.inset, cached.inset)); + BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); + Graphics2D g2 = image.createGraphics(); + icon.paintIcon(null, g2, 0, 0); + g2.dispose(); + cached.setDimensions(icon.getIconWidth(), icon.getIconHeight(), icon.getIconDepth()); + SoftReference img = new SoftReference(new CachedImage(image, cached), queue); + + if (cache.size() >= max) { + Reference soft; + while ((soft = queue.poll()) != null) { + CachedImage ci = (CachedImage) soft.get(); + if (ci != null) { + cache.remove(ci.cachedTf); + } + } + Iterator iter = cache.keySet().iterator(); + if (iter.hasNext()) { + CachedTeXFormula c = iter.next(); + SoftReference cachedImage = cache.get(c); + if (cachedImage != null) { + cachedImage.clear(); + } + cache.remove(c); + } + } + cache.put(cached, img); + + return img; + } + + private static class CachedImage { + + Image image; + CachedTeXFormula cachedTf; + + CachedImage(Image image, CachedTeXFormula cachedTf) { + this.image = image; + this.cachedTf = cachedTf; + } + } + + private static class CachedTeXFormula { + + String f; + int style; + int type; + int size; + int inset; + int width = -1; + int height; + int depth; + Color fgcolor; + + CachedTeXFormula(String f, int style, int type, int size, int inset, Color fgcolor) { + this.f = f; + this.style = style; + this.type = type; + this.size = size; + this.inset = inset; + this.fgcolor = fgcolor; + } + + void setDimensions(int width, int height, int depth) { + this.width = width; + this.height = height; + this.depth = depth; + } + + /** + * {@inheritDoc} + */ + public boolean equals(Object o) { + if (o != null && o instanceof CachedTeXFormula) { + CachedTeXFormula c = (CachedTeXFormula) o; + boolean b = (c.f.equals(f) && c.style == style && c.type == type && c.size == size && c.inset == inset && c.fgcolor.equals(fgcolor)); + if (b) { + if (c.width == -1) { + c.width = width; + c.height = height; + c.depth = depth; + } else if (width == -1) { + width = c.width; + height = c.height; + depth = c.depth; + } + } + + return b; + } + + return false; + } + + /** + * {@inheritDoc} + */ + public int hashCode() { + return f.hashCode(); + } + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/cyrillic/CyrillicRegistration.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/cyrillic/CyrillicRegistration.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/cyrillic/CyrillicRegistration.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,68 @@ +/* LaTeXAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath.cyrillic; + +import java.lang.Character.UnicodeBlock; + +import org.scilab.forge.jlatexmath.AlphabetRegistration; + +public class CyrillicRegistration implements AlphabetRegistration { + + public CyrillicRegistration() { + } + + public Character.UnicodeBlock[] getUnicodeBlock() { + return new Character.UnicodeBlock[]{Character.UnicodeBlock.CYRILLIC}; + } + + public Object getPackage() { + return this; + } + + public String getTeXFontFileName() { + return "fonts/language_cyrillic.xml"; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/dynamic/DynamicAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/dynamic/DynamicAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/dynamic/DynamicAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,119 @@ +/* DynamicAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath.dynamic; + +import org.scilab.forge.jlatexmath.Atom; +import org.scilab.forge.jlatexmath.Box; +import org.scilab.forge.jlatexmath.EmptyAtom; +import org.scilab.forge.jlatexmath.StrutBox; +import org.scilab.forge.jlatexmath.TeXEnvironment; +import org.scilab.forge.jlatexmath.TeXFormula; + +/** + * This kind of atom is used to have a dynamic content + * which comes from an other soft such as ggb. + * The goal is to avoid the reparsing (and the reatomization) + * of the expression. + */ +public class DynamicAtom extends Atom { + + private static ExternalConverterFactory ecFactory; + private ExternalConverter converter; + private TeXFormula formula = new TeXFormula(); + private String externalCode; + private boolean insert; + private boolean refreshed; + + public DynamicAtom(String externalCode, String option) { + this.externalCode = externalCode; + if (ecFactory != null) { + this.converter = ecFactory.getExternalConverter(); + } + if (option != null && option.equals("i")) { + insert = true; + } + } + + public static boolean hasAnExternalConverterFactory() { + return ecFactory != null; + } + + public static void setExternalConverterFactory(ExternalConverterFactory factory) { + ecFactory = factory; + } + + public boolean getInsertMode() { + return insert; + } + + public Atom getAtom() { + if (!refreshed) { + formula.setLaTeX(converter.getLaTeXString(externalCode)); + refreshed = true; + } + + if (formula.root == null) { + return new EmptyAtom(); + } + + return formula.root; + } + + public Box createBox(TeXEnvironment env) { + if (converter != null) { + if (refreshed) { + refreshed = false; + } else { + formula.setLaTeX(converter.getLaTeXString(externalCode)); + } + if (formula.root != null) { + return formula.root.createBox(env); + } + } + + return new StrutBox(0, 0, 0, 0); + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/dynamic/ExternalConverter.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/dynamic/ExternalConverter.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/dynamic/ExternalConverter.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,52 @@ +/* ExternalConverter.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath.dynamic; + +public interface ExternalConverter { + + public String getLaTeXString(String externalCode); + +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/dynamic/ExternalConverterFactory.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/dynamic/ExternalConverterFactory.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/dynamic/ExternalConverterFactory.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,51 @@ +/* ExternalConverterFactory.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2010 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath.dynamic; + +public interface ExternalConverterFactory { + + public ExternalConverter getExternalConverter(); +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/greek/GreekRegistration.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/greek/GreekRegistration.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/greek/GreekRegistration.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,51 @@ +/* GreekRegistration.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + */ + +package org.scilab.forge.jlatexmath.greek; + +import java.lang.Character.UnicodeBlock; + +import org.scilab.forge.jlatexmath.AlphabetRegistration; + +public class GreekRegistration implements AlphabetRegistration { + + public GreekRegistration() { + } + + public Character.UnicodeBlock[] getUnicodeBlock() { + return new Character.UnicodeBlock[]{Character.UnicodeBlock.GREEK, Character.UnicodeBlock.GREEK_EXTENDED}; + } + + public Object getPackage() { + return this; + } + + public String getTeXFontFileName() { + return "fonts/language_greek.xml"; + } +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/internal/util/Images.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/internal/util/Images.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/internal/util/Images.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,43 @@ +package org.scilab.forge.jlatexmath.internal.util; + +import java.awt.Color; +import java.awt.image.BufferedImage; + +public final class Images { + + private Images() { + // prevent instantiation + } + + public static double DISTANCE_THRESHOLD = 40; + + public static double distance(BufferedImage imgA, BufferedImage imgB) { + // The images must be the same size. + if (imgA.getWidth() == imgB.getWidth() && imgA.getHeight() == imgB.getHeight()) { + int width = imgA.getWidth(); + int height = imgA.getHeight(); + + double mse = 0; + // Loop over every pixel. + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + Color ca = new Color(imgA.getRGB(x, y)); + Color cb = new Color(imgB.getRGB(x, y)); + double variance = sqr(ca.getRed() - cb.getRed()) // + + sqr(ca.getBlue() - cb.getBlue()) // + + sqr(ca.getGreen() - cb.getGreen()) // + + sqr(ca.getAlpha() - cb.getAlpha()); + mse += variance; + } + } + return Math.sqrt(mse / height / width); + } else { + return -1; + } + } + + private static double sqr(double x) { + return x * x; + } + +} Index: 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/tcaronAtom.java =================================================================== diff -u --- 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/tcaronAtom.java (revision 0) +++ 3rdParty_sources/jlatexmath/org/scilab/forge/jlatexmath/tcaronAtom.java (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -0,0 +1,64 @@ +/* tcaronAtom.java + * ========================================================================= + * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath + * + * Copyright (C) 2009 DENIZET Calixte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * A copy of the GNU General Public License can be found in the file + * LICENSE.txt provided with the source distribution of this program (see + * the META-INF directory in the source jar). This license can also be + * found on the GNU website at http://www.gnu.org/licenses/gpl.html. + * + * If you did not receive a copy of the GNU General Public License along + * with this program, contact the lead developer, or write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce + * an executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. + * An independent module is a module which is not derived from or based + * on this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obliged to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + */ + +package org.scilab.forge.jlatexmath; + +/** + * An atom with representing an t with a caron. + */ +public class tcaronAtom extends Atom { + + public tcaronAtom() { + } + + public Box createBox(TeXEnvironment env) { + CharBox A = new CharBox(env.getTeXFont().getChar("textapos", env.getStyle())); + CharBox t = new CharBox(env.getTeXFont().getChar('t', "mathnormal", env.getStyle())); + HorizontalBox hb = new HorizontalBox(t); + hb.add(new SpaceAtom(TeXConstants.UNIT_EM, -0.3f, 0, 0).createBox(env)); + hb.add(A); + return hb; + } +} Index: 3rdParty_sources/versions.txt =================================================================== diff -u -r2e874fcc582c774efc0294796c69bad5ddc46fcf -r73b462f151f11f9bf53b767213e8dbf7cb3abcc5 --- 3rdParty_sources/versions.txt (.../versions.txt) (revision 2e874fcc582c774efc0294796c69bad5ddc46fcf) +++ 3rdParty_sources/versions.txt (.../versions.txt) (revision 73b462f151f11f9bf53b767213e8dbf7cb3abcc5) @@ -33,6 +33,8 @@ JBoss Web 2.1.3 +jLaTexMath 1.0.6 + JSP API 2.3 lucene 2.4.0