SharpPlot Reference > SharpPlot Methods > DefineFont Method

SharpPlot.DefineFont Method

Add a short code for a complex font definition to use in many font setters.




Creating a stylesheet

This method may be used simply to define a ‘house style’ of fonts to save possible errors in typing the full name, and to make future change much simpler. You may give each font face a short code, for example:

sp.DefineFont("VN","Verdana,Arial,Sans"); // Try Verdana, then Arial, then fallback to any font of the "sans" family.

Note that as for other Font setters, a list of comma-separated fallbacks fonts can be provided.

From now on, you can use any of the four short codes ‘VN’ ‘VNB’ ‘VNI’ or ‘VNBI’ to get the four variants of this basic font. To have your Captions in Verdana,Italic, (at default size) you simply use:


Adding extra CSS details

SharpPlot allows you to insert any extra CSS properties you want after the font name. These are passed on to charts rendered as SVG or VML, and may be used for various special effects. They are ignored in images and PDF rendering.


You can set any standard font property here, for example letter-spacing to open out heading text slightly, or reference a filter set with IncludeSource.

Setting up PostScript equivalents

If you are generating an EPS document, you may need to map your screen font to a PostScript font known on the printer.


You may also provide the four variants (regular, bold, italic, bold+italic) as a comma-separated list, if they do not have standard postscript variant names. So the line below is equivalent to the above :


Check with the repro house to be sure you get the names exactly correct here!

Embedding PFA font files

A PFA font file can be embedded if a fontname is followed by ‘@’ and then the path to the font file. That allows the Postscript file to be independent of the presence of the font by the displaying device.

sp.DefineFont("VN,"Verdana","","Univers@C:\\fonts\\univers.pfa"; // specify the font file to embed that has the font as described by the name.

A PFA font file can be generated from a TTF file with “ttd2pt1 -e”. Of course a different file can be provided for each of the four variants.

See also ...

SharpPlot Members

Send comments on this topic
© Dyalog Ltd 2016