Hi,

I am new to batik, and am hoping someone can help me with an issue I am having. I was able to generate an SVG file using the SVGGraphics2D class from my Java program. The file is successfully created, and looks more or less good, but the text is slightly misaligned. I want a text label centered from left to right on the image. By java rendering code has something like this:

// CODE STARTS HERE

// g2 is a Graphics2D
// xFrom and xTo are integers having the left and right limits of the drawing area
Font mediumFont = new Font("SansSerif", Font.PLAIN, 12);
Font largeFont = new Font("SansSerif", Font.PLAIN, 16);
FontMetrics fm;

g2.setFont(largeFont);
fm = g2.getFontMetrics();
labelText = "My Title";
labelWidth = fm.stringWidth(labelText);
labelHeight = fm.getHeight();
g2.drawString(labelText, (xFrom + xTo - labelWidth) / 2, 5 + labelHeight);

g2.setFont(mediumFont);
fm = g2.getFontMetrics();
labelText = "My Subtitle";
labelWidth = fm.stringWidth(labelText);
labelHeight = fm.getHeight();
g2.drawString(labelText, (xFrom + xTo - labelWidth) / 2, 10 + 2 * labelHeight);

// CODE ENDS HERE

The image is correctly rendered when I use non-batik plain-java code to show it on a JFrame or when I export it to an image, but when I use batik to generate an SVG, the title and subtitle are not centered with respect to each other. They are approximately centered on the image, but not exactly, and for my specific application I need precise text alignment. I notice the font on the SVG is slightly different from the plain-java font, and wonder if that has something to do with it. I am using the setEmbeddedFontsOn property of the SVGGeneratorContext.

What am I missing?

I am running Kubuntu 14.04 and using OpenJDK 7.

Thanks in advance,
Gabriel

---------------------------------------------------------------------
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