I want to write some extensions that will produce SVG code and perform calcuations based on the bounding box for a text string given a font and its position. I have no interest in creating a window: this is strictly a command line operation.
Can someone point me to an example that uses a function (usually called GetBoundingBox or GetBBox or GetTextExtent) to calculate the width and height (in millimeeters) of a string and correctly position it above another string printed in a different font and center the two strings in a rectangle without creating a Frame or JFrame? I want to use it in the apache XML extensions what will create SVG code for me.
I'm still not clear on how I do it! Do I just code up a GUI app that displays a little window (JApplet?) that passes a graphics object to my paint function I perform the font calcuations I need and then recompile it with that system property? Do I call show for my JApplet so it will call my paint function?
Is there a simpler way to get a graphics object that letting JApplet or JFrame pass one to me? All I want is a graphics object, not a window!
What is the name of the function that will give the bounding box for a text string?
Does it matter where the box is drawn? The important thing is how big the box is, no? You can check whether it's the right size by inspecting its width and height.
If you want to make this code draw correctly, you should change the rectangle coordinates by the same offsets as the string, i.e. centerX - width / 2 and baselineY, respectively.
Joined: Aug 11, 2000
I think I found what I am looking for in "Java Servlet Programming" by Jason Hunter. He has several example servlets that create a AWT frame and from the frame create an image. Hmmm... I'm wondering if I can get millimeter dimensions out of that?