Package com.teamten.font
Class TrackingFont
java.lang.Object
com.teamten.font.AbstractFont
com.teamten.font.TrackingFont
- All Implemented Interfaces:
Font
A font that wraps another font and adds tracking (inter-letter spacing). The tracking is defined in
units of the font size. Tracking of 0.1 on an 11pt font, for example, would add 1.1pt of space after
each letter.
Note that the space is added after each letter, not between letters, because the font abstraction does not know where the string of letter ends. This will cause right-aligned text to have a bit of space between it and the margin, and centered text to be slightly to the left of where it should be. You can fix this by using the underlying font for the last letter, at the cost of proper kerning and hyphenation.
The font does not support ligatures, and kerning is optionally respected.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.teamten.font.Font
Font.Metrics
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SizedFont
Utility method to create a SizedFont incorporating the TrackingFont and the same size.void
draw
(String text, double fontSize, long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents) Draw the text.getCharacterMetrics
(int ch, double fontSize) Return the size of a code point in the specified font size.long
getKerning
(int leftChar, int rightChar, double fontSize) Get the kerning between the two code points.long
The width of a space for a 1pt font, in scaled points.boolean
hasCharacter
(int ch) Whether this font handles this character.Methods inherited from class com.teamten.font.AbstractFont
setLigatures, transformLigatures
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.teamten.font.Font
getStringMetrics
-
Constructor Details
-
TrackingFont
- Parameters:
underlyingFont
- the font to draw.tracking
- fraction of font size to space out characters. Practical Typography recommends 5% to 12%. We tend to use around 10% (0.1).kerning
- how much to kern, from 0.0 (no kerning) to 1.0 (full kerning). A value of 0.5 is recommended.
-
-
Method Details
-
hasCharacter
public boolean hasCharacter(int ch) Description copied from interface:Font
Whether this font handles this character. -
create
Utility method to create a SizedFont incorporating the TrackingFont and the same size. -
getKerning
public long getKerning(int leftChar, int rightChar, double fontSize) Description copied from interface:Font
Get the kerning between the two code points. The result is in scaled points.- Specified by:
getKerning
in interfaceFont
- Overrides:
getKerning
in classAbstractFont
fontSize
- the size of the font in points.
-
getSpaceWidth
public long getSpaceWidth()Description copied from interface:Font
The width of a space for a 1pt font, in scaled points. -
getCharacterMetrics
Description copied from interface:Font
Return the size of a code point in the specified font size. -
draw
public void draw(String text, double fontSize, long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents) throws IOException Description copied from interface:Font
Draw the text.- Parameters:
text
- the text to draw.fontSize
- the size in points.x
- the left-hand edge of the text in scaled points.y
- the baseline of the text in scaled points.contents
- the stream to write to.- Throws:
IOException
-