This is a migrated thread and some comments may be shown as answers.

FontsRepository.RegisterFont data Parameter

1 Answer 340 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Mi asked on 02 Mar 2015, 10:55 AM
The help is little bit scarce on registering a font: see

There is a data parameter at the end, which should contain the raw data for the font. Looking for more information about the subject I came across where 

public class FontData {
  public bool IsValid { get; set; }
  public byte[] Bytes { get; set; }
  public string FontFamilyName { get; set; }
  public bool IsItalic { get; set; }
  public bool IsBold { get; set; }

is defined. Which is used from to get the Bytes property of the above class to register a font:

PdfFontsServiceFontData result = e.Result;
FontFamily fontFamily = new FontFamily(result.FontFamilyName); FontStyle fontStyle = GetFontStyle(result.IsItalic); FontWeight fontWeight = GetFontWeight(result.IsBold);
FontsRepository.RegisterFont(fontFamily, fontStyle, fontWeight, result.Bytes);

So is this the right way to create the font data:

FontFamily fontFamily = new FontFamily(fontFamilyName);
FontStyle fontStyle = isItalic ? FontStyles.Italic : FontStyles.Normal;
FontWeight fontWeight = isBold ? FontWeights.Bold : FontWeights.Normal;
Typeface typeface = new Typeface(fontFamily, fontStyle, fontWeight, FontStretches.Normal);
GlyphTypeface glyphTypeface;
if (typeface.TryGetGlyphTypeface(out glyphTypeface)) {
   using (var memoryStream = new MemoryStream()) {
       data.Bytes = memoryStream.ToArray();
       data.IsValid = true;



1 Answer, 1 is accepted

Sort by
Telerik team
answered on 04 Mar 2015, 04:56 PM

Thank you for your feedback. We will consider some improvements to the mentioned article. Here is some additional information on the matter.

1. In WPF you don't need to register a font, unless the font is not installed on the machine. The FontsRepository can access all fonts that are installed and register them for you.

2. If you want to use a font that is not installed on the machine, then you should register it. Every font can be described by 3 components: font family - the family of the font; font style - the font style (normal, italic, etc.); the font weight - the weight of the font (normal, bold, narrow, etc.). These components are the key that later is used to create an instance of this font. For example if you have arialitalic.ttf font file, that contains the italic version of the Arial font, and want to register it in your application, your code should look like this:
FontsRepository.RegisterFont(new FontFamily("Arial"), FontStyles.Italic, FontWeights.Normal, File.ReadAllBytes("arialitalic.ttf"));

And you can use it later in your application by calling the following method:
FontsRepository.TryCreateFont(new FontFamily("Arial"), FontStyles.Italic, FontWeights.Normal, out font)

Hope this makes things clearer. If you have other questions do not hesitate to contact us.


Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question