This is a migrated thread and some comments may be shown as answers.
Custom fonts vs Teleric First Look demo
4 Answers 28 Views
This is a migrated thread and some comments may be shown as answers.
Czeshirecat
Top achievements
Rank 1
Czeshirecat asked on 14 Oct 2019, 10:11 AM

I noticed that it was possible to embed custom fonts whilst looking at the webcam firstlook demo source code. I'm rewriting a poorly working web cam module, replacing the old code with your new webcam control.

So I found https://docs.telerik.com/devtools/winforms/telerik-presentation-framework/custom-fonts and generated the following code

/// <summary>
/// Add all fonts to [root]\Properties as embedded resources
/// </summary>
public static class FontFactory
{            
  private static FontFamily ReadFontFromManifest(string fontFileName, string fontName)
  {
    #region Code
    try
    {
      var names = Assembly.GetExecutingAssembly().GetManifestResourceNames();
      var root = Assembly.GetExecutingAssembly().GetName().Name;
      var fontStream = Assembly.GetExecutingAssembly().GetManifestResourceStream($@"{root}.Properties.{fontFileName}");
 
      if (fontStream == null) return null;
 
      ThemeResolutionService.LoadFont(fontStream);
      return ThemeResolutionService.GetCustomFont(fontName);
    }
    catch (Exception err)
    {
      Log4Net.Log.Error(err);
      throw;
    }
    #endregion
  }// function
 
  public static FontFamily Font_Awesome_5_Free_Solid
    => ReadFontFromManifest("Font-Awesome-5-Free-Solid-900.otf", Font_Awsome_5_Free_Solid_FontName);
 
  public static string Font_Awsome_5_Free_Solid_FontName
    => "Font Awesome 5 Free Solid";
}

 

I tested the code and it does seem to return a font family. But I want to ask a question about your first look please.

I was trying to find in the firstlook solution any code that matched the suggestion for embedding fonts shown in your documentation, but couldn't. The only mention of the awsome font above was in your form1.cs file for the webcam demo. So is it already part of your component source? When I removed the call to my font factory the closebutton.textelement.customfont still showed what appeared to be "Font Awesome 5 Free Solid";

Thanks. Just trying to understand what to expect :)

4 Answers, 1 is accepted

Sort by
0
Todor Vyagov
Telerik team
answered on 15 Oct 2019, 07:57 AM

Hello Claire,

We are using the custom "Font Awesome" and "TelerikWebUI" fonts in our WebCam first look example. By custom font, we mean that the font is not necessary to be installed on the client's machine to work correctly. This is achieved by embedding the font to the memory with some predefined static methods in ThemeResolutionService class. We are using several custom fonts in our demo application, controls, and themes. So we have loaded these fonts and you can use them by only setting CustomFont, CustomFontSize and CustomFontStyle properties of any of our elements. 

Here is a list of the loaded font names:
TelerikWebUI
Roboto
Roboto Medium
WebComponentsIcons
Font Awesome 5 Brands Regular
Font Awesome 5 Free Regular
Font Awesome 5 Free Solid

If you need to load another font you can use the approach from your post.

For more information about glyphs refer to the following help article.
https://docs.telerik.com/devtools/winforms/telerik-presentation-framework/glyphs

 

Should you have further questions please let me know.

Regards,
Todor Vyagov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Czeshirecat
Top achievements
Rank 1
answered on 15 Oct 2019, 12:37 PM

Hello Todor. Yes, I understand how to do this from your link in my original post. For testing purposes, I commented out the code where I used the ThemeResolutionService to load font awesome and expected a garbled character on the button, but it showed font awesome. I checked my installed fonts to make sure it wasn't there.

That's when I searched through all the firstlook source to find embedded resources or any code that appeared to load in the font, but couldn't find it. I wondered if it was actually embedded into your radwebcam control for showing buttons and/or settings dialog already. If it was then I wouldn't need to make the app footprint bigger or reinvent the wheel.

0
Accepted
Todor Vyagov
Telerik team
answered on 16 Oct 2019, 08:34 AM

Hi Claire,

I'm sorry for the misunderstanding.

All listed fonts in my previous post are embedded into the Telerik.WinControls assembly, which is referenced by all other our assemblies. This is why you don't need to embed(load) any of these fonts in your application and you can use them directly.

The FirstLook example of RadWebCam in our demo application also uses these embedded fonts and does not need to load them explicitly.
We will also improve the help article about custom fonts to be more clear about the already embedded fonts.

Should you have further questions please let me know.

Regards,
Todor Vyagov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Czeshirecat
Top achievements
Rank 1
answered on 16 Oct 2019, 09:11 AM
Thank you so much :)
Asked by
Czeshirecat
Top achievements
Rank 1
Answers by
Todor Vyagov
Telerik team
Czeshirecat
Top achievements
Rank 1
Share this question
or