xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bonekrusher <djs...@yahoo.com>
Subject Re: Extract font width using FOP
Date Fri, 16 Nov 2012 23:29:46 GMT
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: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Mime
View raw message