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.
Related
I am working on an WPF application. WPF allows me to style everything but I just want my app to have the same theme as the other Windows applications. I want it to use the current Windows theme. Is this possible?
Whilst you're doing your styling you will be using brushes and colors.
If you want your styling to conform to the windows theme then you should ensure all your brushes and colors used are based on SystemColors.
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/graphics-multimedia/how-to-paint-an-area-with-a-system-brush?view=netframeworkdesktop-4.8
https://learn.microsoft.com/en-us/dotnet/api/system.windows.systemcolors?view=netcore-3.1
You will find that a number of the default templates do not do this and instead have "hard coded" colors. Hence you will have to provide your own replacement templates for all these.
Unless you have extensive experience of wpf templating you are likely under estimating the amount of work which will be involved.
This is a lot of work.
If you look at custom themes which are available you'll often find the author missed some subtle aspects of controls here and there.
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.
I am trying to build a Ribbon control in WPF. I've downloaded the Visual Studio 2013 Image Library. It's got a lot of images but all the standard ones like Cut, Copy and Paste are only in 16x16 format.
Large ribbon images need to be 32x32 (or even up to 64x64 depending on device resolution, according to Microsoft).
I've found several articles on building a Ribbon control and they all seem to use the same icons. Does anyone know where I can find these icons?
It appears that, while Visual Studio includes a library of toolbar images that make it easier to have your own applications have a similar look and feel, Microsoft did not include a very rich set of images in the correct size for the Ribbon control.
So I guess that answer is that you either 1) Create your own, 2) Scavenge the images off the web, or 3) purchase a ready-made library of images with the correct sizes.
I'm using Visual Studio 2010.
I want to build an application displaying some text with custom fonts.
All the fonts are TrueType fonts, with the editable attribute, and are declared as resource with "Copy Always".
But, even at design time, some fonts are replaced by the standard Silverlight font, in the XAML editor.
For example I have 14 different versions of the Helvetica font (bold, oblique, italic, narrow, condensed... and mix of those). But only 3 are correctly displayed, others are using the fallback font. If I open the ttf files with the windows font preview application everything looks ok.
Any idea of what can be wrong ?
Thanks for your help.
After two months of hair pulling I've finally come with a simple solution :
Don't use - (dash) in your embedded font names
I hope it can help somebody.
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