本文整理汇总了Java中org.scilab.forge.jlatexmath.TeXIcon.paintIcon方法的典型用法代码示例。如果您正苦于以下问题:Java TeXIcon.paintIcon方法的具体用法?Java TeXIcon.paintIcon怎么用?Java TeXIcon.paintIcon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.scilab.forge.jlatexmath.TeXIcon
的用法示例。
在下文中一共展示了TeXIcon.paintIcon方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawLaTeX
import org.scilab.forge.jlatexmath.TeXIcon; //导入方法依赖的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);
}
示例2: convertToImage
import org.scilab.forge.jlatexmath.TeXIcon; //导入方法依赖的package包/类
/**
* The convertToImage method is used to convert a LaTeX string to an PNG image file.
*
* @param imageFile
* @param latexString
* @throws Exception
*/
public static void convertToImage(File imageFile, String latexString) throws Exception
{
TeXFormula formula = new TeXFormula(latexString);
TeXIcon icon = formula.new TeXIconBuilder().setStyle(TeXConstants.STYLE_DISPLAY).setSize(20).build();
icon.setInsets(new Insets(5, 5, 5, 5));
BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.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);
ImageIO.write(image, "png", imageFile.getAbsoluteFile());
}
示例3: LatexImage
import org.scilab.forge.jlatexmath.TeXIcon; //导入方法依赖的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;
}
示例4: generate_image_from_icon
import org.scilab.forge.jlatexmath.TeXIcon; //导入方法依赖的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());
}
示例5: saveToSVG
import org.scilab.forge.jlatexmath.TeXIcon; //导入方法依赖的package包/类
/**
* Parses a mathematical formula like "(a+b)/c" to a pretty image and saves
* it as an SVG file.
*
* @param formula A raw formula input String.
* @param file The SVG file to save to.
* @throws ParseException When parsing the LaTeX formula failed.
* @throws IOException When writing the file failed.
* @throws DetailedParseCancellationException When parsing the raw formula to
* LaTeX failed.
*/
public static void saveToSVG(String formula, File file)
throws ParseException, IOException, DetailedParseCancellationException {
String latexFormula = FormulaParser.parseToLatex(formula);
TeXIcon icon = FormulaParser.getTeXIcon(latexFormula);
DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
Document document =domImpl.createDocument(
SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", null);
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
SVGGraphics2D g2 = new SVGGraphics2D(ctx, true);
g2.setSVGCanvasSize(new Dimension(icon.getIconWidth(),icon.getIconHeight()));
icon.paintIcon(null, g2, 0, 0);
try (FileOutputStream svgs = new FileOutputStream(file)) {
Writer out = new OutputStreamWriter(svgs, "UTF-8");
g2.stream(out, false);
svgs.flush();
}
}
示例6: parseToImage
import org.scilab.forge.jlatexmath.TeXIcon; //导入方法依赖的package包/类
/**
* Parses a mathematical formula String like "(a+b)/c" to a pretty image.
*
* @param formula A raw formula input String.
* @return An image object containing the rendered formula.
* @throws ParseException When the formula rendering fails.
* @throws DetailedParseCancellationException when the formula parsing fails.
*/
public static BufferedImage parseToImage(String formula)
throws ParseException, DetailedParseCancellationException {
String latexFormula = FormulaParser.parseToLatex(formula);
TeXIcon icon = FormulaParser.getTeXIcon(latexFormula);
// now create an actual image of the rendered equation
BufferedImage image = new BufferedImage(icon.getIconWidth(),
icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics();
g2.setColor(Color.white);
g2.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
icon.paintIcon(null, g2, 0, 0);
return image;
}
示例7: getLatexImage
import org.scilab.forge.jlatexmath.TeXIcon; //导入方法依赖的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;
}
示例8: plot
import org.scilab.forge.jlatexmath.TeXIcon; //导入方法依赖的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.TeXIcon; //导入方法依赖的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: paint
import org.scilab.forge.jlatexmath.TeXIcon; //导入方法依赖的package包/类
public void paint( Graphics g )
{
if( reparseSrcOnRepaint )
{
this.setLaTeXSrc( this.texSrc, false );
reparseSrcOnRepaint = false;
}
super.paint( g );
if( this.isOpaque() )
{
g.setColor( this.getBackground() );
g.fillRect(0, 0, this.getWidth(), this.getHeight() );
}
// scale font size according to ratio of actual size vs. preferred size
float xScale = this.getPreferredSize() != null ? this.getWidth() / ( float ) this.getPreferredSize().width : 1.0f;
float yScale = this.getPreferredSize() != null ? this.getHeight() / ( float ) this.getPreferredSize().height : 1.0f;
float scale = ( xScale < yScale ? xScale : yScale );
// System.out.println( scale );
TeXIcon texIcon = texFormula.createTeXIcon( TeXConstants.STYLE_TEXT, 0.88f * 30f * scale, TeXFormula.SANSSERIF, TeXConstants.UNIT_PIXEL, 1920f, TeXConstants.ALIGN_CENTER );
texIcon.setInsets( this.getInsets() );
int x, y;
switch( halign )
{
case LEFT: x = 0; break;
case RIGHT: x = this.getWidth() - texIcon.getIconWidth(); break;
case CENTER:
default: x = ( this.getWidth() - texIcon.getIconWidth() ) / 2; break;
}
switch( valign )
{
case TOP: y = 0; break;
case BOTTOM: y = this.getHeight() - texIcon.getIconHeight(); break;
case CENTER_BASELINE: y = ( this.getHeight() - texIcon.getIconHeight() + texIcon.getIconDepth() ) / 2; break;
case CENTER:
default: y = ( this.getHeight() - texIcon.getIconHeight() ) / 2; break;
}
texIcon.paintIcon( this, g, x, y );
}
示例11: emit
import org.scilab.forge.jlatexmath.TeXIcon; //导入方法依赖的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);
}
}