use of org.scilab.forge.jlatexmath.TeXFormula in project freeplane by freeplane.
the class TeXText method createTeXIcon.
public TeXIcon createTeXIcon(int style, int size, int align, int maxWidth) {
final String predefinedMacros = ResourceController.getResourceController().getProperty(LATEX_MACROS);
StringBuffer sb = new StringBuffer();
if (predefinedMacros != null) {
sb.append(predefinedMacros + "\n\n");
}
sb.append("\n\n").append("\\text{").append(rawText).append("}");
// LogUtils.severe(String.format("TeX='%s'", sb.toString()));
TeXFormula tf = new TeXFormula(sb.toString());
// tf.createTeXIcon(style, size, TeXConstants.UNIT_PIXEL, maxWidth, align, TeXConstants.UNIT_PIXEL, 40f);
return tf.new TeXIconBuilder().setStyle(style).setSize(size).setWidth(TeXConstants.UNIT_PIXEL, maxWidth, align).setIsMaxWidth(true).setInterLineSpacing(TeXConstants.UNIT_PIXEL, /*40f*/
size * 1.2F).build();
}
use of org.scilab.forge.jlatexmath.TeXFormula in project Bean by Xirado.
the class LaTeXCommand method executeCommand.
@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
event.deferReply().queue();
InteractionHook hook = event.getHook();
String formula = event.getOption("formula").getAsString();
TeXFormula tf;
try {
tf = new TeXFormula(formula);
} catch (ParseException exception) {
hook.sendMessageEmbeds(EmbedUtil.errorEmbed("An error occurred while parsing LaTeX formula!\n```\n" + exception.getMessage() + "\n```")).queue();
return;
}
TeXIcon ti = tf.createTeXIcon(TeXConstants.STYLE_DISPLAY, 70);
BufferedImage bimg = new BufferedImage(ti.getIconWidth(), ti.getIconHeight(), BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2d = bimg.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0, ti.getIconWidth(), ti.getIconHeight());
JLabel jl = new JLabel();
jl.setForeground(new Color(0, 0, 0));
ti.paintIcon(jl, g2d, 0, 0);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ImageIO.write(bimg, "png", baos);
} catch (IOException e) {
hook.sendMessageEmbeds(EmbedUtil.errorEmbed("An error occurred!")).queue();
return;
}
hook.sendMessage("").addFile(baos.toByteArray(), "card.png").queue();
}
use of org.scilab.forge.jlatexmath.TeXFormula in project jmathanim by davidgutierrezrubio.
the class LaTeXMathObject method generateDOMTreeFromLaTeX.
private Element generateDOMTreeFromLaTeX(String text) {
Writer out = null;
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
String latexText;
if (mode == CompileMode.JLaTexMath) {
latexText = "\\mbox{" + text + "}";
} else {
latexText = text;
}
TeXFormula formula = new TeXFormula(latexText);
TeXIcon icon = formula.createTeXIcon(TeXConstants.ALIGN_LEFT, 40);
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
// Create an instance of the SVG Generator.
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, true);
ctx.setEmbeddedFontsOn(true);
icon.paintIcon(null, svgGenerator, 0, 0);
DOMTreeManager domTreeManager = svgGenerator.getDOMTreeManager();
Element domFactory = svgGenerator.getRoot();
return domFactory;
}
use of org.scilab.forge.jlatexmath.TeXFormula in project MeteoInfo by meteoinfo.
the class Draw method getStringDimension.
/**
* Get string dimension
*
* @param str String
* @param g Graphics2D
* @param isLaTeX Is LaTeX or not
* @return String dimension
*/
public static Dimension getStringDimension(String str, Graphics2D g, boolean isLaTeX) {
if (isLaTeX) {
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();
// int height = (int) (metrics.getAscent() * 5.f / 6.f);
int height = metrics.getAscent();
// return new Dimension(metrics.stringWidth(str), metrics.getHeight());
return new Dimension(metrics.stringWidth(str), height);
}
}
use of org.scilab.forge.jlatexmath.TeXFormula in project saturnGL by chompa111.
the class Latex method generateExp.
public static List<Gobject> generateExp(String s, double x, double y, Color color) {
TeXFormula a = new TeXFormula(s);
var icon2 = a.createTeXIcon(TeXConstants.STYLE_TEXT, 50);
var img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
var fakeGraphics = new GraphicsdrawCharProxy((Graphics2D) img.getGraphics(), color);
icon2.paintIcon(null, fakeGraphics, (int) x, (int) y);
return fakeGraphics.getCharList();
}
Aggregations