Class PdfFont
java.lang.Object
com.codename1.pdf.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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PdfFontCourier, the standard monospaced font.static final PdfFontCourier Bold.static final PdfFontCourier Bold Oblique.static final PdfFontCourier Oblique.static final PdfFontHelvetica, the standard sans serif.static final PdfFontHelvetica Bold.static final PdfFontHelvetica Bold Oblique.static final PdfFontHelvetica Oblique.static final PdfFontSymbol: Greek letters and mathematical signs, by their code in the font's own encoding (a char'a'draws alpha).static final PdfFontTimes Bold.static final PdfFontTimes Bold Italic.static final PdfFontTimes Italic.static final PdfFontTimes Roman, the standard serif.static final PdfFontZapfDingbats: ornaments and arrows, by their code in the font's own encoding. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleancanDisplay(char c) True when the font can drawcwith a glyph of its own.protected abstract com.codename1.impl.pdf.FontStateCreates the per-document state that tracks which glyphs a document uses and writes the font objects.abstract floatgetAscent(float size) The height above the baseline of the font's tallest letters atsizepoints, in points.abstract floatgetDescent(float size) The depth below the baseline atsizepoints, as a positive number of points.floatgetLineHeight(float size) The recommended distance between two baselines atsizepoints.abstract StringgetName()The PostScript name of the font.abstract floatgetStringWidth(String text, float size) The advance width oftextatsizepoints, in points.static PdfFontloadTrueType(byte[] data) Loads a TrueType (.ttf) font, or the TrueType outlines of an OpenType font.
-
Field Details
-
HELVETICA
Helvetica, the standard sans serif. -
HELVETICA_BOLD
Helvetica Bold. -
HELVETICA_OBLIQUE
Helvetica Oblique. -
HELVETICA_BOLD_OBLIQUE
Helvetica Bold Oblique. -
TIMES_ROMAN
Times Roman, the standard serif. -
TIMES_BOLD
Times Bold. -
TIMES_ITALIC
Times Italic. -
TIMES_BOLD_ITALIC
Times Bold Italic. -
COURIER
Courier, the standard monospaced font. -
COURIER_BOLD
Courier Bold. -
COURIER_OBLIQUE
Courier Oblique. -
COURIER_BOLD_OBLIQUE
Courier Bold Oblique. -
SYMBOL
Symbol: Greek letters and mathematical signs, by their code in the font's own encoding (a char'a'draws alpha). -
ZAPF_DINGBATS
ZapfDingbats: 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
Loads a TrueType (.ttf) font, or the TrueType outlines of an OpenType font. Fonts whose outlines are CFF (.otfwith aCFFtable) and collections (.ttc) are rejected with anIOException, as is a font whose license bits forbid embedding.- Throws:
IOException
-
getName
The PostScript name of the font. -
getStringWidth
The advance width oftextatsizepoints, in points. -
getAscent
public abstract float getAscent(float size) The height above the baseline of the font's tallest letters atsizepoints, in points. -
getDescent
public abstract float getDescent(float size) The depth below the baseline atsizepoints, as a positive number of points. -
getLineHeight
public float getLineHeight(float size) The recommended distance between two baselines atsizepoints. -
canDisplay
public abstract boolean canDisplay(char c) True when the font can drawcwith a glyph of its own. -
createState
protected abstract com.codename1.impl.pdf.FontState createState()Creates the per-document state that tracks which glyphs a document uses and writes the font objects. Internal.
-