Filtering Font Family

Ribbon for WPF Forum

Posted 15 years ago by Andy Fouse
Version: 9.1.0505
Avatar
There are 18 fonts that throw an exception in our application.

In Vista and XP, we get back a Cooper font which does not appear to be in Word or PowerPoint.

Why is this font showing up in the list?

Is there a way to filter the FontFamilyCombo Box to remove these choices?

Example fonts that throw an exception: Cooper, ERAS ITC, Brittanic, Rage

Thanks

Andy

Comments (15)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Andy,

All we do when populating items in that control is run through a loop like this:
foreach (FontFamily fontFamily in Fonts.SystemFontFamilies) {
  // Add item for the fontFamily here
}
Let me ask, is it a System.IO.FileFormatException that is being thrown? I did some googling and saw a post on that occuring for some Adobe fonts.

I added some code to do some checking before we add a FontFamily from SystemFontFamilies to the list to ensure no exception is thrown from the FontFamily when calling certain members. This should help your scenario and will be in the next maintenance release.


Actipro Software Support

Posted 15 years ago by Andy Fouse
Avatar
Here is the exception we are receiving:

System.ArgumentException was unhandled
Message="Font 'Cooper' cannot be found."
Source="System.Drawing"
StackTrace:
at System.Drawing.FontFamily.CreateFontFamily(String name, FontCollection fontCollection)
at System.Drawing.FontFamily..ctor(String name)


Using this code: FontFamily temp = new FontFamily(fontFamily); //FontFamily=Cooper, which is returned from the FontFamilyComboBox
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Andy,

It looks like you are using the font in WinForms eh? Hopefully our new code in the next build will help filter out the "bad" fonts that are included in SystemFontFamilies.


Actipro Software Support

Posted 15 years ago by Andy Fouse
Avatar
Just checking back to see if a build been created that will fix these issues?
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Not yet, it will likely be in the next couple weeks.


Actipro Software Support

Posted 15 years ago by Andy Fouse
Avatar
Just checking back to see if there has been any progress made with the Fonts and WinForms property.

Thanks in Advance

Andy
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Andy,

The changes we mentioned are in recent builds.


Actipro Software Support

Posted 15 years ago by Andy Fouse
Avatar
Sorry for all the questions ... but...Can you tell me what these changes are or how i need to access them?

[Modified at 01/11/2010 01:26 PM]
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
It's built in, you don't have to do anything.


Actipro Software Support

Posted 15 years ago by Andy Fouse
Avatar
We are using Build 2009.2 and are receiving the same errors with "select" fonts.

The following fonts do not work properly:
- Cooper
- Arial Rounded Bold
- Bernard MT
- Bodoni MT Poster
- Brittanic
- Copperplate Gothic
- Eras ITC
- Footlight MT
- Franklin Gothic
- Gill Sans
- Global Monospace
- Global Sans Serif
- Global Serif
- Global User Interface
- Gloucester MT
- Harlow Solid
- OCR A
- Rage
- Script MT
- Segoe
- Vivaldi
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Andy,

You had originally mentioned you get this error with creating a WinForms FontFamily. What if you do the same with a WPF FontFamily? Does it work then?

If it's a WinForms-only issue, I'm not sure what we can do since the WPF framework is telling us these font families are proper registered system font families.


Actipro Software Support

Posted 15 years ago by Andy Fouse
Avatar
Correct, we get this error when trying to us the WPF ribbon with a WindowsFormsHost. In our scenario, we have a WinForms tool embedded in the WPF Ribbon Window.

So we'd like to see a way to populate the FontFamilyComboBox with only WindowsForms fonts. Is there a way to accomplish this?
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Andy,

The FontFamilyComboBox has a virtual RefreshFontFamilies that you can override. In that you could populate the proper font families that will work for your scenario. Start off in there by clearing the Items, then just add a ComboBoxItem for each font family where the Content is a WPF FontFamily instance. You can set the ComboBoxItem's FontFamily property to the instance too if you want previewing.


Actipro Software Support

Posted 15 years ago by Andy Fouse
Avatar
We can now filter the font families that are added to the Combo Box, using this code.
      foreach (System.Drawing.FontFamily fontFamily in System.Drawing.FontFamily.Families)
            {
                
                System.Windows.Media.FontFamily wpfFontFamily = new System.Windows.Media.FontFamily(fontFamily.Name);
                ComboBoxItem comboBoxItem = new ComboBoxItem();
                comboBoxItem.FontFamily = wpfFontFamily;
                comboBoxItem.FontSize = base.FontSize + 3.0;
                comboBoxItem.Content = wpfFontFamily;
                Items.Add(comboBoxItem);

            }
In the ribbon, we see the correct font in the combo box, but it quickly disappears because we make this calll to validate the font...we need to validate the font to make certain the user doesn't type an invalid font into the combo box....
        private void CanExecuteFontNameCommand(object sender, CanExecuteRoutedEventArgs e)
        {     .....
           if (string.IsNullOrEmpty(fontFamily) || !ActiproSoftware.Windows.Controls.Ribbon.Controls.FontFamilyComboBox.IsValidFontFamilyName(fontFamily))
}
The call to IsValidFontFamilyName returns null and the QC combo box is blanked out even though the appropariate font is applied.

Since IsValidFontFamilyName is Actipro code, we cannot see what is happening inside this call.

Any thoughts?

Thanks in Advance

Andy
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Andy,

That method just scans the Fonts.SystemFontFamilies and looks for a FontFamily.Source property match with the name you pass.


Actipro Software Support

The latest build of this product (v24.1.3) was released 28 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.