|
Problem This is in response to pbm's post titled "Symbol font in PHP-GTK2"
Suppose you want to display math or greek characters on windows platform as shown below:

Solution On windows, if you have tried displaying math or greek characters using Symbol font, you will get the error message
Pango-WARNING **: Couldn't load font "Symbol 12" falling back to "Sans 12"
The main reason is that Pango works only on unicode, but the standard Symbol font on windows does not have a unicode character mapping.
So to display math and greek characters on windows platform, all you need is to find some symbol-equivalent truetype font that supports unicode.
Below are some pointers that may save you some time:
Sample Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| <?php $window = new GtkWindow(); $window->set_size_request(400, 200); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel("Display Math and Greek Characters\n". "using Symbol Truetype Font on windows\n". "Part 1 - Display the Font"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $title->set_size_request(-1, 60); $title->set_justify(Gtk::JUSTIFY_CENTER); $alignment = new GtkAlignment(0.5, 0, 0, 0); $alignment->add($title); $vbox->pack_start($alignment, 0, 0); $vbox->pack_start(new GtkLabel(), 0, 0);
// display greek characters
$greek_str = urldecode("%EE%82%B7%EE%82%B8%EE%82". // note 1
"%B9%EE%82%BA%EE%82%BB%EE%82%BC%EE%83%81%EE%83%82". "%EE%83%86%EE%83%89"); $greek_label = new GtkLabel($greek_str); $greek_label->modify_font(new PangoFontDescription('OpenSymbol 12')); // note 2
$vbox->pack_start($greek_label);
|
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
Explanation
- Some greek characters in unicode. Note that I have urlencoded the characters. Hence the need to urldecode them.
- Set the font to OpenSymbol.
- Some math characters in unicode. Note that I have urlencoded the characters. Hence the need to urldecode them.
- Set the font to OpenSymbol.
Note
There are also some additional unicode math fonts available here: http://support.wolfram.com/mathematica/systems/windows/general/latestfonts.html
Related Links
|