• 周四. 12月 1st, 2022

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

A method of transferring MathML to pictures based on Java

[db:作者]

1月 6, 2022
Maven rely on :
<dependency>
<groupId>de.rototor.jeuclid</groupId>
<artifactId>jeuclid-core</artifactId>
<version>3.1.14</version>
</dependency>
Example :
@Test
public void testMathMlToImg() throws IOException {
//MathML character string
String mathStr = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n" +
" <mi>f</mi>\n" +
" <mo>(</mo>\n" +
" <mi>x</mi>\n" +
" <mo>)</mo>\n" +
" <mo>&gt;</mo>\n" +
" <mfrac>\n" +
" <msqrt>\n" +
" <mn>2</mn>\n" +
" </msqrt>\n" +
" <mn>8</mn>\n" +
" </mfrac>\n" +
" <mo>+</mo>\n" +
" <mn>1</mn>\n" +
" </math>";
// Create Converter
Converter converter = Converter.getInstance();
// establish layoutContext And set relevant parameters
// Parameter setting can refer to net.sourceforge.jeuclid.context.Parameter class
// The parameter default value can refer to LayoutContextImpl Class constructor
LayoutContextImpl layoutContext = (LayoutContextImpl) LayoutContextImpl.getDefaultLayoutContext();
// Set the formula font size , Default 12.0pt
layoutContext.setParameter(Parameter.MATHSIZE, 30);
// Set formula color , Default black
layoutContext.setParameter(Parameter.MATHCOLOR, Color.RED);
// transformation
Dimension dimension = converter.convert(mathStr, new FileOutputStream("f:/1.png"), "image/png", layoutContext);
if(dimension != null){
System.out.println(" Image conversion succeeded ! high :" + dimension.getHeight() + " wide :" + dimension.getWidth());
}
}

Output results :

 Image conversion succeeded ! high :70.0 wide :149.0

The conversion result is as follows :

About outFileType Parameter value , The following are supported :

image/png
image/vnd.wap.wbmp
image/x-png
image/jpeg
image/tiff
image/bmp
image/gif

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注