本文整理汇总了Java中org.scilab.forge.jlatexmath.TeXFormula.createTeXIcon方法的典型用法代码示例。如果您正苦于以下问题:Java TeXFormula.createTeXIcon方法的具体用法?Java TeXFormula.createTeXIcon怎么用?Java TeXFormula.createTeXIcon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.scilab.forge.jlatexmath.TeXFormula
的用法示例。
在下文中一共展示了TeXFormula.createTeXIcon方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStringDimension
import org.scilab.forge.jlatexmath.TeXFormula; //导入方法依赖的package包/类
/**
* Get string dimension
*
* @param str String
* @param g Graphics2D
* @return String dimension
*/
public static Dimension getStringDimension(String str, Graphics2D g) {
if (isLaTeX(str)) {
float size = g.getFont().getSize2D();
// create a formula
TeXFormula formula = new TeXFormula(str);
// render the formla to an icon of the same size as the formula.
TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_TEXT, size);
// insert a border
//icon.setInsets(new Insets(5, 5, 5, 5));
//return new Dimension(icon.getIconWidth(), icon.getIconHeight());
int width = (int) icon.getTrueIconWidth() + 10;
//int height = (int)icon.getTrueIconHeight();
int height = icon.getIconHeight();
return new Dimension(width, height);
} else {
FontMetrics metrics = g.getFontMetrics();
//return new Dimension(metrics.stringWidth(str), metrics.getHeight());
return new Dimension(metrics.stringWidth(str), metrics.getAscent());
}
}
示例2: drawLaTeX
import org.scilab.forge.jlatexmath.TeXFormula; //导入方法依赖的package包/类
/**
* Draw LaTeX string
*
* @param g Graphics2D
* @param str String
* @param size Size
* @param x X
* @param y Y
* @param useExternalFont If use external font
*/
public static void drawLaTeX(Graphics2D g, String str, float size, float x, float y, boolean useExternalFont) {
if (useExternalFont) {
//Set font
TeXFormula.registerExternalFont(Character.UnicodeBlock.BASIC_LATIN, g.getFont().getName());
} else {
TeXFormula.registerExternalFont(Character.UnicodeBlock.BASIC_LATIN, null, null);
}
// create a formula
TeXFormula formula = new TeXFormula(str);
// render the formla to an icon of the same size as the formula.
TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_TEXT, size);
// insert a border
icon.setInsets(new Insets(5, 5, 5, 5));
icon.setForeground(g.getColor());
y = y - (icon.getIconHeight() * 2.0f / 3.f);
icon.paintIcon(null, g, (int) x, (int) y);
}
示例3: latexRender
import org.scilab.forge.jlatexmath.TeXFormula; //导入方法依赖的package包/类
public static void latexRender(String latex) {
TeXFormula tf = new TeXFormula(latex);
TeXIcon icontf = tf.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
icontf.setInsets(new Insets(5, 5, 5, 5));
OutputTextPane otp = new OutputTextPane();
otp.addIcon(icontf, 0, true);
JPanel jp = new JPanel();
jp.add(otp);
JFrame tstF = new JFrame("test");
tstF.add(jp);
tstF.setSize(200, 200);
tstF.setVisible(true);
}
示例4: LatexImage
import org.scilab.forge.jlatexmath.TeXFormula; //导入方法依赖的package包/类
public LatexImage(String _latexStr, int x, int y) {
plotAbsolute = true;
xcoord = x;
ycoord = y;
latexStr = _latexStr;
TeXFormula formula = new TeXFormula(true, latexStr);
TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
icon.setInsets(new Insets(5, 5, 5, 5));
img = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = img.createGraphics();
g2.setColor(Color.white);
g2.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
JLabel jl = new JLabel();
jl.setForeground(new Color(0, 0, 0));
icon.paintIcon(jl, g2, 0, 0);
alpha = (float) 0.5;
}
示例5: generate_image_from_icon
import org.scilab.forge.jlatexmath.TeXFormula; //导入方法依赖的package包/类
@Test
public void generate_image_from_icon() throws IOException {
String formula = "" +
"\\Re{z} =\\frac{n\\pi \\dfrac{\\theta +\\psi}{2}}{\n" +
" \\left(\\dfrac{\\theta +\\psi}{2}\\right)^2 + \\left( \\dfrac{1}{2}\n" +
" \\log \\left\\vert\\dfrac{B}{A}\\right\\vert\\right)^2}.";
TeXFormula teXFormula = new TeXFormula(formula);
TeXIcon teXIcon = teXFormula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 14f);
BufferedImage image = new BufferedImage(teXIcon.getIconWidth(), teXIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D)image.getGraphics();
teXIcon.paintIcon(null, g2, 0, 0);
g2.dispose();
File output = new File(settings.workingDir(), "TeXFormulaTest__generate_image_from_icon.png");
ImageIO.write(image, "png", output);
System.out.println("TeXFormulaTest.generate_image_from_icon::" + output.getAbsolutePath());
}
示例6: getLatexImage
import org.scilab.forge.jlatexmath.TeXFormula; //导入方法依赖的package包/类
public static BufferedImage getLatexImage(String latex) {
TeXFormula formula = new TeXFormula(latex);
TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 48);
icon.setInsets(new Insets(5, 5, 5, 5));
BufferedImage image = new BufferedImage(icon.getIconWidth()+75, icon.getIconHeight()+75, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics();
g2.setColor(Color.white);
g2.fillRect(0,0,icon.getIconWidth()+75,icon.getIconHeight()+75);
JLabel jl = new JLabel();
jl.setForeground(new Color(0, 0, 0));
icon.paintIcon(jl, g2, 37, 37);
return image;
}
示例7: latexCodeToImageIcon
import org.scilab.forge.jlatexmath.TeXFormula; //导入方法依赖的package包/类
/**
*
* @param codeLaTEX
* @return une image qui représente ce qu'affiche LaTEX à la place du code codeLaTEX
*/
static Icon latexCodeToImageIcon(String codeLaTEX)
{
TeXFormula formula = new TeXFormula(codeLaTEX);
TeXIcon ti = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
return ti;
}
示例8: plot
import org.scilab.forge.jlatexmath.TeXFormula; //导入方法依赖的package包/类
/**
* see Text for formatted text output
*/
public void plot(AbstractDrawer draw) {
if (!visible) return;
TeXFormula formula = new TeXFormula(label);
TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, size);
icon.setTeXIconColor(plotColor);
//icon.setInsets(new Insets(5, 5, 5, 5));
Graphics2D g2 = draw.getGraphics();
g2.setColor(plotColor);
JLabel jl = new JLabel();
jl.setForeground(plotColor); // GlobalValues.defaultFormulaColor);
if (useLogical == false) // do not use logical coordinates
icon.paintIcon(jl, g2, coordx, coordy);
else // use logical coordinates to place the formula
{
double[] logicalCoords = {logicalx, logicaly};
int[] screenCoords = draw.project(logicalCoords[0], logicalCoords[1]);
icon.paintIcon(jl, g2, screenCoords[0], screenCoords[1]);
}
}
示例9: createImage
import org.scilab.forge.jlatexmath.TeXFormula; //导入方法依赖的package包/类
/**
* This method creates the image from the equation given.
* @param equation - The equation to parse
* @return
*/
public static BufferedImage createImage(String equation) {
TeXFormula fomule = new TeXFormula(equation);
TeXIcon ti = fomule.createTeXIcon(
TeXConstants.STYLE_DISPLAY, 40);
BufferedImage b = new BufferedImage(ti.getIconWidth(), ti
.getIconHeight(), BufferedImage.TYPE_4BYTE_ABGR);
ti.paintIcon(new JLabel(), b.getGraphics(), 0, 0);
return b;
}
示例10: emit
import org.scilab.forge.jlatexmath.TeXFormula; //导入方法依赖的package包/类
@Override
public void emit(SourceCode sourceCode, ITextContext context) {
String lang = sourceCode.lang();
String code = sourceCode.content();
try {
String trimmed = Strings.unindentBlock(code);
log.debug("Initializing text grid");
TeXFormula formula = new TeXFormula(trimmed);
TeXIcon teXIcon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 14f);
teXIcon.setInsets(new Insets(1, 1, 1, 1));
teXIcon.setForeground(foreground);
PdfWriter pdfWriter = context.getPdfWriter();
PdfContentByte cb = pdfWriter.getDirectContent();
float width = (float) teXIcon.getIconWidth();
float height = (float) teXIcon.getIconHeight();
PdfTemplate template = cb.createTemplate(width, height);
Graphics2D g2 = new PdfGraphics2D(template, width, height, new JLaTeXmathFontMapper());
log.debug("Rendering formula");
teXIcon.paintIcon(null, g2, 0, 0);
g2.dispose();
log.debug("Rendering diagram done");
ImgTemplate imgTemplate = new ImgTemplate(template);
scaleToFit(imgTemplate, context.getDocumentArtBox());
context.append(imgTemplate);
} catch (Exception e) {
throw new WrappedRuntimeException(e);
}
}
示例11: getTeXIcon
import org.scilab.forge.jlatexmath.TeXFormula; //导入方法依赖的package包/类
/**
* Renders a valid LaTeX math formula to an icon.
*
* @param formula Valid LaTeX formula.
* @return Rendered Icon.
* @throws ParseException When rendering has failed (e.g. the formula was
* not valid).
*/
private static TeXIcon getTeXIcon(String formula) throws ParseException {
TeXFormula latexFormula = new TeXFormula(formula);
// render the formla to an icon of the same size as the formula.
TeXIcon icon = latexFormula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
// insert a border
icon.setInsets(new Insets(5, 5, 5, 5));
return icon;
}
示例12: InsertionButton
import org.scilab.forge.jlatexmath.TeXFormula; //导入方法依赖的package包/类
public InsertionButton(Editor editorTextArea, final String codeToInsert, final String latex, ArrayList<Integer> snipets) {
this.editorTextArea = editorTextArea;
this.codeToInsert = codeToInsert;
this.snipets = snipets;
this.latex = latex;
this.setContentAreaFilled(false);
//this.setBorderPainted(false);
addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
switch(((MainFrame)(getRootPane().getParent())).state) {
case EDITION :
((MainFrame)(getRootPane().getParent())).state = State.EDITION;
insertAtCaret(codeToInsert + "\n");
break;
case EDITION_ERROR :
((MainFrame)(getRootPane().getParent())).state = State.EDITION_ERROR;
insertAtCaret(codeToInsert + "\n");
break;
case NO_RESULT :
// impossible
break;
case SINGLE_RESULT :
// impossible
break;
case FIRST_RESULT :
// impossible
break;
case MIDDLE_RESULT :
// impossible
break;
case LAST_RESULT :
// impossible
break;
default :
System.out.println("Undefined action set for the state : " + ((MainFrame)(getRootPane().getParent())).state);
}
}
});
try {
TeXFormula formula = new TeXFormula(this.latex);
TeXIcon ti = formula.createTeXIcon(TeXConstants.ALIGN_TOP, 15);
this.setIcon(ti);
} catch (Exception ex) {
System.err.println("Erreur lors de la traduction dun bouton "+codeToInsert);
}
this.setFocusable(false);
this.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
this.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
}
示例13: setLatex
import org.scilab.forge.jlatexmath.TeXFormula; //导入方法依赖的package包/类
public void setLatex(String latex) {
TeXFormula formula = new TeXFormula(latex);
TeXIcon ti = formula.createTeXIcon(TeXConstants.ALIGN_TOP, 20+zoom);
latexLabel.setIcon(ti);
}