当前位置: 首页>>代码示例>>Java>>正文


Java TeXIcon.getIconHeight方法代码示例

本文整理汇总了Java中org.scilab.forge.jlatexmath.TeXIcon.getIconHeight方法的典型用法代码示例。如果您正苦于以下问题:Java TeXIcon.getIconHeight方法的具体用法?Java TeXIcon.getIconHeight怎么用?Java TeXIcon.getIconHeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.scilab.forge.jlatexmath.TeXIcon的用法示例。


在下文中一共展示了TeXIcon.getIconHeight方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getStringDimension

import org.scilab.forge.jlatexmath.TeXIcon; //导入方法依赖的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());
    }
}
 
开发者ID:meteoinfo,项目名称:MeteoInfoLib,代码行数:30,代码来源:Draw.java

示例2: 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);
}
 
开发者ID:meteoinfo,项目名称:MeteoInfoLib,代码行数:31,代码来源:Draw.java

示例3: 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());
}
 
开发者ID:bclemenzi,项目名称:latex-converter,代码行数:27,代码来源:LaTeXConverter.java

示例4: 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;

}
 
开发者ID:scalalab,项目名称:scalalab,代码行数:22,代码来源:LatexImage.java

示例5: 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());
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:20,代码来源:TeXFormulaTest.java

示例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;
}
 
开发者ID:mzur,项目名称:pretty-formula,代码行数:24,代码来源:FormulaParser.java

示例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;
	}
 
开发者ID:tbluche,项目名称:MERStructure,代码行数:17,代码来源:LatexParser.java

示例8: 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;
}
 
开发者ID:crro,项目名称:GoogleGlassServerHeroku,代码行数:15,代码来源:Main.java

示例9: 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 );
	}
 
开发者ID:IMAGINARY,项目名称:FormulaMorph,代码行数:43,代码来源:LaTeXLabel.java

示例10: 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);
    }

}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:38,代码来源:SourceCodeLaTeXExtension.java


注:本文中的org.scilab.forge.jlatexmath.TeXIcon.getIconHeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。