except that (in general) FOP does not use AWT to obtain font metrics
On Fri, Nov 16, 2012 at 4:29 PM, Bonekrusher <[email protected]> wrote:
> You can right an extension in Java and use Font Metrics... I wrote this a
> while back, so it might need to be updated. This example will return the
> width of a String.
>
>
> import java.awt.Font;
> import java.awt.FontMetrics;
> import java.awt.Toolkit;
>
> public class StringLength {
>
>
> public static void main(String[] args) throws
> NumberFormatException {
>
> if(args.length < 2){
> System.out.println("StringLength <string> <int
> font size>");
> System.exit(0);
> }else{
> getStringLength(args[0],
> Integer.parseInt(args[1]));
> }
>
> }
>
> @SuppressWarnings("deprecation")
> public static int getStringLength(String str, int size){
>
> Toolkit toolkit = Toolkit.getDefaultToolkit();
> int stringlen = 0;
> Font font = new Font("Arial", Font.PLAIN, 9);
> FontMetrics fontMetrics = toolkit.getFontMetrics(font);
> System.out.println ("[Stylesheet Info] Calculating width
> for: " + str + ":
> " + fontMetrics.stringWidth(str));
> stringlen = fontMetrics.stringWidth(str);
> return stringlen;
> }
>
>
> }
>
>
>
>
> --
> View this message in context:
> http://apache-fop.1065347.n5.nabble.com/Extract-font-width-using-FOP-tp37360p37361.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>