Hi!

I am trying to generate an SVG file that includes a few Greek letters /
math symbols, but I'm only getting '? (question marks) for those; the rest
of the text is produced OK.

Here is a minimal code sample: the first example, using a rasterized
Graphics2D, has no issue displaying and saving the letters/symbols. The
second example, using Batik's SVGGraphics2D, is the one that can't display
Greek letters / math symbols:

// % java --version

// openjdk version "23.0.2" 2025-01-21

// OpenJDK Runtime Environment (build 23.0.2+7-58)

// OpenJDK 64-Bit Server VM (build 23.0.2+7-58, mixed mode, sharing)

// pom.xml:

// ...

// <dependency>

// <groupId>org.apache.xmlgraphics</groupId>

// <artifactId>batik-all</artifactId>

// <version>1.18</version><!-- Oct 09, 2024 -->

// <exclusions>

// <exclusion>

// <groupId>xml-apis</groupId>

// <artifactId>xml-apis</artifactId>

// </exclusion>

// </exclusions>

// </dependency>

// ...


public static void main(final String [] ARG) {

try {

graphics2DExample();

System.out.println("graphics2DExample() completes OK.");

} catch (Exception e) {

System.out.println("graphics2DExample() aborted with exception: " +
e.getMessage()
+ ".");

}

try {

batikExample();

System.out.println("batikExample() completes OK.");

} catch (SVGGraphics2DIOException e) {

System.out.println("batikExample() aborted with exception: " + e.getMessage()
+ ".");

}

}// main

static void graphics2DExample() throws IOException {

BufferedImage bufferedImage = new BufferedImage(300, 300, BufferedImage.
TYPE_INT_ARGB);

Graphics2D graphics2D = bufferedImage.createGraphics();


String fontName = "DejaVu Math TeX Gyre";

Font dejaVu = new Font(fontName, Font.PLAIN, 24);

graphics2D.setFont(dejaVu);

graphics2D.setColor(Color.black);


graphics2D.drawString("∑ (Σ) - Summation", 10, 30);

graphics2D.drawString("∫ - Integral", 10, 60);

graphics2D.drawString("π (pi) - Pi", 10, 90);

graphics2D.drawString("√ - Square root", 10, 120);

graphics2D.drawString("∞ - Infinity", 10, 150);

File pngfile = new File("math_symbols.png");

ImageIO.write(bufferedImage, "png", pngfile);

}// graphics2DExample

static void batikExample() throws SVGGraphics2DIOException {

DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();

String svgNS = "http://www.w3.org/2000/svg";;

Document document = domImpl.createDocument(svgNS, "svg", null);

SVGGraphics2D graphics2D = new SVGGraphics2D(document);

graphics2D.setSVGCanvasSize(new Dimension(300, 300));


String fontName = "DejaVu Math TeX Gyre";

Font dejaVu = new Font(fontName, Font.PLAIN, 24);

graphics2D.setFont(dejaVu);

graphics2D.setColor(Color.black);


graphics2D.drawString("∑ (Σ) - Summation", 10, 30);

graphics2D.drawString("∫ - Integral", 10, 60);

graphics2D.drawString("π (pi) - Pi", 10, 90);

graphics2D.drawString("√ - Square root", 10, 120);

graphics2D.drawString("∞ - Infinity", 10, 150);

String svgfile = "math_symbols.svg";

graphics2D.stream(svgfile);

}// batikExample

Both examples complete OK. Here are their outputs: (attached).


What am I missing in the Batik code? I've tried several other fonts and

quite a few other (supported) characters from several Unicode planes,

and the results are always the same: Batik displays '?' instead of the

expected symbols. I'm in an Ubuntu 24.04 system, if that matters.


Any help much appreciated. Thanks in advance!
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org

Reply via email to