Font management and installation in Silverlight - silverlight

Is there a way to detect if a font has fall back in the list of desired fonts, so that they can be dynamically downloaded and installed in the system?

Silverlight does support font fallback in the FontFamily property -- just comma-seperate the list of fallback fonts. You can also include fonts which you have embedded in your assembly (no need to install fonts).
Unfortunately, there is no way to download a font only if it is required using XAML alone, but the MSDN reference does suggest a code approach.
FontSource
Rather than specify a
FontFamily as a URI in XAML, you can
also specify a FontSource in code.
This gives you more options for
packaging or obtaining a font file.
Basically you obtain a stream of
either a font file or a zip of font
files, and set FontSource using that
stream. This is equivalent to
specifying a URI portion of a
FontFamily value, and makes that font
file available to the object. All you
need to do now is specify a
fontFamilyName to reference one of the
specific families in the current
FontSource value.
http://msdn.microsoft.com/en-us/library/system.windows.media.fontfamily(v=vs.95).aspx

Related

Is it possible to replace the 'native fonts' in the simulator with a specific font?

I would like to record an 'iPhone' demo in the simulator, but the font is not the same as on the device (I know you can't distribute it). However, I found the SF Pro font for download and wanted to give it a try and was wondering if there is a simple way to override the native fonts easily (without having to change e.g. the css file)?
So that I can leave statements like this in my CSS: font-family: "native:MainRegular" but programmatically set this to be my copy of SF Pro font in the Simulator...
I wouldn't do this since font kerning will look "off" and if someone will notice the font he'll notice that as well. The same font will look different in Windows, Mac etc.
But if you insist then the simplest way is to create your own skin file. This is just a simple zip file containing the skin details. E.g. this is the iPhoneX skin. Notice it doesn't include TTF files within...
You need to add the fonts you want then use something like the google pixel skin as a reference. Look in the properties file on defining the fonts. It's pretty simple.
As you can see from the script building the skins is literally just zipping.

Winforms: How to render Fontawesome 5.10 glyphs correctly?

I have been using Fontawesome 5.6 (free) in a winforms project, and rendered glyphs by referencing the character code into a variable. "&HF084" would show the Key character in VB.net for example.
The latest versions of Fontawesome, like 5.10, while still having the same character codes for the same icons, don't always render the icon, even if it's available in the free version I'm using.
I have noticed in a few comments, that specifying weight would fix the issue, at least for css rendering.
Specifying Bold style under a label with the font does fix the issue of non-rendering icons, however they are rendered much more heavy than they should be. Previously specifying Regular font style used to work for all icons, however that is not the case now.
As far as I'm aware I can't specify weight of a font by point in winforms, just specify the style (regular, bold, underlined, etc.)
EDIT: For more information, I am using the ttf font files that come in the web folder of the web zip file of fontawesome. The reason for this is that otf file format doesn't work on Windows server 2003, which is an environment that will run the WinForms app.

How can I tell if a font isn't supported in Silverlight

Suppose the user want to use a specific font to render the text in the textblock, are there some way to detect whether the font is support in Siliverlight?
Fonts are supplied by the operating system or ROM for windows phone. Then depending on the silveright version + target operating system, you will be able to select from those supported.
In Silverlight 4, any font on the local computer can be used.
In Silverlight 3, certain Latin and East Asian fonts will work depending on the Operating System. See: http://msdn.microsoft.com/en-us/library/cc189010(v=vs.95).aspx#silverlight_fonts
In either case, you can deploy the font with your application to ensure it is rendered correctly (by specifying the font source property http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.fontsource(v=vs.95).aspx ).

How to list monospace (fixed-width) fonts in WPF

I need to add font chooser to my WPF text editor. I'm adapting this font chooser.
However, it lists all the installed fonts. I only need a list of fixed-width (monospace) fonts.
How do I check if a given System.Windows.Media.FontFamily is a fixed-width font?
There is a solution that uses System.Drawing.FontFamily but those fonts are not exactly compatible with WPF and the code I'm adapting uses System.Windows.Media.FontFamily.
Maybe you can filter the System.Windows.Media.FontFamily list by creating a System.Drawing.Font with the same name and use inteop and LOGFONT from there.
This is a horrible hack but I believe it will work in most cases (if you only use fonts installed on the system the System.Windows.Media.FontFamily and System.Drawing.FontFamily lists should mostly match)
Using something like this to get font sizing information or information about advanced font properties would be completely useless due to the differences in the font renderer between WPF and GDI - but for basic properties of the font like being fixed-width I expect this should work.

Images in a WPF Custom Control Library

I need to put an image in the default view of a custom control. However, whenever I try to test the control it can't locate the image. I have tried to compile it as an embedded resource and just a plain resource in VS. Neither of these have worked. So is there a correct way to do this?
That's probably because you specified the image path as a relative path. You should use the Pack URI Scheme to specify that the resource is in the current assembly. For instance :
<Image Source="pack://application:,,,/Images/MyImage.png"/>
I have an open-source library that allows you to include country flags in your WPF application via a value converter. The flags images are stored as resources within the assembly.
It's available on NuGet:
Install-Package FamFamFam.Flags.Wpf
The source is up on GitHub:
https://github.com/drewnoakes/famfamfam-flags-wpf
You can take a look to see how the images are embedded and the Pack URI scheme is used.

Resources