Top Description Fields Constructors Methods
org.antlr.v4.gui

public abstract Class BasicFontMetrics

extends Object
Class Inheritance
Known Direct Subclasses
org.antlr.v4.gui.SystemFontMetrics

Font metrics. The only way to generate accurate images in any format that contain text is to know the font metrics. Specifically, we need to know the width of every character and the maximum height (since we want all characters to fit within same line height). I used ttf2tfm to dump the font metrics from Mac TrueType fonts and then converted that to a Java class for use in a PostScript generator for trees. Commands:
	 $ ttf2tfm /Library/Fonts/Arial\ Black.ttf > metrics
 
Then run metrics into python code after stripping header/footer:
	 #
	 # Process lines from ttf2tfm that look like this:
	 # Glyph  Code   Glyph Name                Width  llx    lly      urx    ury
	 # ------------------------------------------------------------------------
	 #     3  00020  space                       333  0,     0 --     0,     0
	 #
	 lines = open("metrics").read().split('\n')
	 print "public class FontName {"
	 print "    {"
	 maxh = 0;
	 for line in lines[4:]: # skip header 0..3
			 all = line.split(' ')
			 words = [x for x in all if len(x)>0]
			 ascii = int(words[1], 16)
			 height = int(words[8])
			 if height>maxh: maxh = height
			 if ascii>=128: break
			 print "        widths[%d] = %s; // %s" % (ascii, words[3], words[2])

	 print "        maxCharHeight = "+str(maxh)+";"
	 print "    }"
	 print "}"
 
Units are 1000th of an 'em'.

Field Summary

Modifier and TypeField and Description
public static final int
protected int
protected int[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public double
getLineHeight(int fontSize)

public double
getWidth(String s, int fontSize)

public double
getWidth(char c, int fontSize)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

MAX_CHARback to summary
public static final int MAX_CHAR
maxCharHeightback to summary
protected int maxCharHeight
widthsback to summary
protected int[] widths

Constructor Detail

BasicFontMetricsback to summary
public BasicFontMetrics()

Method Detail

getLineHeightback to summary
public double getLineHeight(int fontSize)
getWidthback to summary
public double getWidth(String s, int fontSize)
getWidthback to summary
public double getWidth(char c, int fontSize)