本文整理汇总了Java中org.scilab.forge.jlatexmath.TeXIcon.getIconWidth方法的典型用法代码示例。如果您正苦于以下问题:Java TeXIcon.getIconWidth方法的具体用法?Java TeXIcon.getIconWidth怎么用?Java TeXIcon.getIconWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.scilab.forge.jlatexmath.TeXIcon
的用法示例。
在下文中一共展示了TeXIcon.getIconWidth方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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;
}
示例3: 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());
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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 );
}
示例8: 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);
}
}