[]
Fallback fonts are fonts used to draw glyphs that are not present in a font specified by the application. DsPdf provides a default list of fallback font families that are automatically initialized, and includes large fonts that are usually suitable to be used as fallbacks for many languages, where some common fonts do not have the glyphs.
These automatically added fallback font families are available via methods on the FontCollection.SystemFonts static collection. You can customize the default (and system-dependent) behavior by providing your own fallback fonts and by adding them either to fallbacks managed by the global FontCollection.SystemFonts, by adding them to your own instance of the FontCollection, or directly to specific fonts that you are using. Through these options, the fallback font behavior can be finely tuned and be completely system independent.
Refer to the following code sample to see a demonstration of fallback fonts:
public int CreatePDF(Stream stream)
{
var gabriola = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "Gabriola.ttf"));
if (gabriola == null)
throw new Exception("Could not load font Gabriola");
// Now that we have our font, use it to render some text:
var tf = new TextFormat() { Font = gabriola, FontSize = 16 };
var doc = new GcPdfDocument();
var g = doc.NewPage().Graphics;
g.DrawString($"Sample text drawn with font {gabriola.FontFamilyName}.", tf, new PointF(72, 72));
// We can change the font size:
tf.FontSize += 4;
g.DrawString("The quick brown fox jumps over the lazy dog.", tf, new PointF(72, 72 * 2));
// We can force DsPdf to emulate bold or italic style with a non-bold (non-italic) font, e.g.:
tf.FontStyle = GCTEXT.FontStyle.Bold;
g.DrawString("This line prints with the same font, using emulated bold style.", tf, new PointF(72, 72 * 3));
// But of course rather than emulated, it is much better to use real bold/italic fonts.
// So finally, get a real bold italic font and print a line with it:
var timesbi = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "timesbi.ttf"));
tf.Font = timesbi ?? throw new Exception("Could not load font timesbi");
tf.FontStyle = GCTEXT.FontStyle.Regular;
g.DrawString($"This line prints with {timesbi.FullFontName}.", tf, new PointF(72, 72 * 4));
// Done:
doc.Save(stream);
return doc.Pages.Count;
}