/*
Jaxe - Editeur XML en Java
Copyright (C) 2003 Observatoire de Paris-Meudon
Ce programme est un logiciel libre ; vous pouvez le redistribuer et/ou le modifier conformément aux dispositions de la Licence Publique Générale GNU, telle que publiée par la Free Software Foundation ; version 2 de la licence, ou encore (à votre choix) toute version ultérieure.
Ce programme est distribué dans l'espoir qu'il sera utile, mais SANS AUCUNE GARANTIE ; sans même la garantie implicite de COMMERCIALISATION ou D'ADAPTATION A UN OBJET PARTICULIER. Pour plus de détail, voir la Licence Publique Générale GNU .
Vous devez avoir reçu un exemplaire de la Licence Publique Générale GNU en même temps que ce programme ; si ce n'est pas le cas, écrivez à la Free Software Foundation Inc., 675 Mass Ave, Cambridge, MA 02139, Etats-Unis.
*/
package jaxe.equations;
//import org.w3c.dom.*;
//import org.apache.xerces.parsers.*;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.font.GlyphVector;
import java.util.Vector;
import jaxe.equations.element.MathRootElement;
/**
* The base for creating a MathElement tree
*
* @author Stephan Michels
* @author Marco Sielaff
* @version %I%, %G%
*/
public class MathBase
{
private String fontname = "Default";
private int fontstyle = Font.PLAIN;
private int inlinefontsize = 12;
private int displayfontsize = 14;
private int minfontsize = 8;
private int maxfontsize = 60;
private Font[] fonts = new Font[maxfontsize];
private FontMetrics[] fontmetrics = new FontMetrics[maxfontsize];
private Font[] symbolFonts = new Font[maxfontsize];
private FontMetrics[] symbolFontmetrics = new FontMetrics[maxfontsize];
private boolean debug = false;
/** Inline mathematical expression */
public final static int INLINE = 0;
/** Non inline mathematical expression */
public final static int DISPLAY = 1;
private int mode = INLINE;
private MathRootElement rootElement;
// mega-bug: Windows does not include any Unicode equivalence for its Symbol font: we have to do it by hand...
public boolean windaube;
private char[] Symbol_chars = {'\u239B', '\u239C', '\u239D',
'\u239E', '\u239F', '\u23A0',
'\u23A1', '\u23A2', '\u23A3',
'\u23A4', '\u23A5', '\u23A6',
'\u23A7', '\u23A8', '\u23AA', '\u23A9',
'\u23AB', '\u23AC', '\u23AD',
'\u2320', '\u2321',
'\u2211', '\u220F'};
private int[] MS_Symbol_codes = {167, 168, 169,
183, 184, 185,
170, 171, 172,
186, 187, 188,
173, 174, 176, 175,
189, 190, 191,
180, 182,
166, 150};
private Vector goodFonts; // cache for findfont
/**
* Creates a MathBase
*
* @param element Root element of a math tree
* @param fontname Name of the preferred font
* @param fontstyle Style of the preferred font, see java.awt.Font
* @param inlinefontsize Size of the preferred font used by inline equations
* @param displayfontsize Size of the preferred font used by non inline equations
*/
public MathBase(MathRootElement element, String fontname, int fontstyle,
int inlinefontsize, int displayfontsize)
{
this(fontname, fontstyle, inlinefontsize, displayfontsize);
setRootElement(element);
}
/**
* Creates a MathBase
*
* @param element Root element of a math tree
*/
public MathBase(MathRootElement element)
{
this(element, "Default", Font.PLAIN, 12, 14);
}
/**
* Creates a MathBase
*
* @param fontname Name of the preferred font
* @param fontstyle Style of the preferred font, see java.awt.Font
* @param inlinefontsize Size of the preferred font used by inline equations
* @param displayfontsize Size of the preferred font used by non inline equations
*/
public MathBase(String fontname, int fontstyle, int inlinefontsize,
int displayfontsize)
{
this.fontname = fontname;
this.fontstyle = fontstyle;
this.inlinefontsize = inlinefontsize;
this.displayfontsize = displayfontsize;
windaube = System.getProperty("os.name").startsWith("Windows");
for (int i = 0; i < maxfontsize; i++)
{
fonts[i] = new Font(fontname, fontstyle, i);
fontmetrics[i] = Toolkit.getDefaultToolkit().getFontMetrics(fonts[i]);
}
goodFonts = new Vector();
String symbolFontName = "Symbol";
if (!windaube) {
// check if Symbol has all the glyphs we use
Font testfont = new Font("Symbol", fontstyle, displayfontsize);
boolean testok = true;
for (int i=0; i