Hi, my name is Chris Han, I’m the program manager in Windows Presentation Foundation working on text and globalization. You might have seen our recent MSDN TV episode “Overview of text and flow layout in Windows Presentation Foundation” where I demonstrated a text box with a context menu which allows a user to turn on and off certain OpenType features. The code to achieve this is attached below.
I want to point out a few parts of this code… let’s look at Page1.xaml first. Here we’re creating a RichTextBox and a ContextMenu to pop up whenever you right click on text (or left click if you’re left handed like me).
<!– Populated with C# –>
Notice that in the Visual Studio project, the font files under ‘fonts’ folder have build action set to ‘Resource’. Setting it to ‘Resource’ embeds these files in the assembly. You can make this work too by setting build action to ‘Content’ and Copy to Output to ‘Copy if newer’ which would keep the fonts as loose files in the directory that your application is deployed.
In Page1.xaml.cs there are two event handlers which enable this OpenType menu. In ContextMenuOpen, we’re creating new MenuItems on the fly to give the user a preview of what the text would look like if they applied a particular OpenType feature. In ContextMenuClick we’re actually applying the property to the selected text in MyRichTextBox.
The font you see is in the screenshot above is one of the many cool OpenType sample fonts Ascender Corp created for our SDK. All of which you can download here today:
Check out some of features below. I only hooked up 3 of them in the code above. Note this is a sample font so there are some limitations. Most of Pericles’ features are only available on capital letters.
Here are some relevant articles:
Packaging Fonts with Applications:
OpenType Font Features:
Sample Font Pack: