简体   繁体   中英

Render Symbols in WPF application

I need to represent a variety of symbols (mathematics, physics etc) in a WPF application.

Is there any way to read text in a special format and convert it into equations or symbols that can be displayed on a WPF Canvas?

Thank you.

What I would do is roll my own, and its not hard to do. STIX font's has 1700+ math and engineering symbols in the form of a font, and its a free font. You can download a TTF port from here . What you'll want to do is embed the font inside your application. This blog will teach you how to do this. Finally, creating some kind of markup to map text to the appropriate symbol. For example {PI} could map to the unicode character in the font that shows the PI symbol. Install the font on your computer, then you can go to this page to see all the glyphs and what Unicode character they map to. So an example of your mapping function might look like this:

private string MarkupToUnicode(string markup)
{
    markup = markup.Replace("{PI}", "\U000003D6");
    markup = markup.Replace("{PHI}", "\U000003D5");

    return markup;
}

This will correctly map the PI symbol and PHI symbol, according to this page . Of course, you'll have to add extra symbols that you plan to use (and yes, I know its a tedious task)

So once you have your function that replaces your markup code with the appropriate Unicode replacements, set that text to a TextBlock object, set the FontFamily property of your TextBlock to your embedded STIX font, then place the TextBlock on your canvas and viola!

When you want "special characters or symbols" you should probably use images instead of depending on fonts.

I would suggest to look for such symbols as images and use them in your WPF Canvas.

如果您具有此符号的矢量表示,则可以轻松地将其转换为WPF路径(或几何)对象,因此可以在WPF表单上使用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM