Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public abstract class PdfFont
- Object
- PdfFont
A font text is drawn and measured with.
The 14 standard PDF fonts (HELVETICA, TIMES_ROMAN, COURIER and
their styles, plus SYMBOL and ZAPF_DINGBATS) are built into every
reader and add nothing to the file, but they cover only the Western
European characters of WinAnsiEncoding; any other character is drawn as
?. For any other script, load a TrueType font with
[#loadTrueType(byte[])]: only the glyphs a document uses are embedded.
PdfDocument doc = new PdfDocument();
PdfCanvas canvas = doc.addPage(PdfPageSize.A4).getCanvas();
PdfFont body = PdfFont.loadTrueType(Util.readInputStream(
CN.getResourceAsStream("/NotoSans-Regular.ttf")));
canvas.setFont(body, 12);
canvas.drawText("Grusse, Jalapeno", 72, 72);A font object holds no per-document state and may be shared by any number of documents, including from different threads on a server.
Fields
Constructors
protected PdfFont() | Subclassed only inside Codename One. |
Methods
public static PdfFont loadTrueType(byte[] data)
throws IOException | Loads a TrueType (.ttf) font, or the TrueType outlines of an OpenType font. |
public abstract String getName() | The PostScript name of the font. |
public abstract float getStringWidth(String text, float size) | The advance width of text at size points, in points. |
public abstract float getAscent(float size) | The height above the baseline of the font’s tallest letters at size points, in points. |
public abstract float getDescent(float size) | The depth below the baseline at size points, as a positive number of points. |
public float getLineHeight(float size) | The recommended distance between two baselines at size points. |
public abstract boolean canDisplay(char c) | True when the font can draw c with a glyph of its own. |
protected abstract FontState createState() | Creates the per-document state that tracks which glyphs a document uses and writes the font objects. |
Inherited methods
Field details
HELVETICA
public static final PdfFont HELVETICAHelvetica, the standard sans serif.
HELVETICA_BOLD
public static final PdfFont HELVETICA_BOLDHelvetica Bold.
HELVETICA_OBLIQUE
public static final PdfFont HELVETICA_OBLIQUEHelvetica Oblique.
HELVETICA_BOLD_OBLIQUE
public static final PdfFont HELVETICA_BOLD_OBLIQUEHelvetica Bold Oblique.
TIMES_ROMAN
public static final PdfFont TIMES_ROMANTimes Roman, the standard serif.
TIMES_BOLD
public static final PdfFont TIMES_BOLDTimes Bold.
TIMES_ITALIC
public static final PdfFont TIMES_ITALICTimes Italic.
TIMES_BOLD_ITALIC
public static final PdfFont TIMES_BOLD_ITALICTimes Bold Italic.
COURIER
public static final PdfFont COURIERCourier, the standard monospaced font.
COURIER_BOLD
public static final PdfFont COURIER_BOLDCourier Bold.
COURIER_OBLIQUE
public static final PdfFont COURIER_OBLIQUECourier Oblique.
COURIER_BOLD_OBLIQUE
public static final PdfFont COURIER_BOLD_OBLIQUECourier Bold Oblique.
SYMBOL
public static final PdfFont SYMBOLSymbol: Greek letters and mathematical signs, by their code in the
font’s own encoding (a char
'a' draws alpha).ZAPF_DINGBATS
public static final PdfFont ZAPF_DINGBATSZapfDingbats: ornaments and arrows, by their code in the font’s own
encoding.
Constructor details
PdfFont
protected PdfFont()Subclassed only inside Codename One.
Method details
loadTrueType
public static PdfFont loadTrueType(byte[] data)
throws IOExceptionLoads a TrueType (
.ttf) font, or the TrueType outlines of an
OpenType font. Fonts whose outlines are CFF (.otf with a CFF table) and collections (.ttc) are rejected with an
IOException, as is a font whose license bits forbid embedding.Throws
getName
public abstract String getName()The PostScript name of the font.
getStringWidth
public abstract float getStringWidth(String text, float size)The advance width of
text at size points, in points.getAscent
public abstract float getAscent(float size)The height above the baseline of the font’s tallest letters at
size points, in points.getDescent
public abstract float getDescent(float size)The depth below the baseline at
size points, as a positive number
of points.getLineHeight
public float getLineHeight(float size)The recommended distance between two baselines at
size points.canDisplay
public abstract boolean canDisplay(char c)True when the font can draw
c with a glyph of its own.createState
protected abstract FontState createState()Creates the per-document state that tracks which glyphs a document
uses and writes the font objects. Internal.