PHP-GTK2 Newsletter
PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou
Sample Code 269: How to display math and greek characters using symbol font - Part 2 - input unicode characters? |
|
Written by kksou
|
|
Tuesday, 19 June 2007 |
|
Problem In Part 1, we have learned how to display math and greek characters on windows platform.
In this Part 2, I will show you how to input those math and greek characters as unicode characters as shown below:

Solution
Below are the steps to input math and greek characters as unicode characters. (Note: The following steps are only tested on winxp. However, I believe it should work on other windows platform too.)
- First you need to have a text editor that supports utf-8. If you don't have a favorite utf-8 editor, you can just use the standard windows Notepad.
- Copy the sample code below and paste them into a new file.
- Save the file by choosing File - Save As. For Encoding, MAKE SURE you choose "UTF-8" as shown below:

- Now open the program "Character Map". It's usually located in Program - Accessories - System Tools. If you cannot find it, try locating it in "c:\windows\system32\charmap.exe"
- In the Character Map, select the font "OpenSymbol". (Note: If you haven't installed the font yet, please follow the steps as outlined in How to display math and greek characters using symbol font - Part 1?
- Select the math and greek characters that you need by double-clicking on the character as shown below:

- When you're done, click "Copy".
- Now go back to the text editor. Paste the string into the variable $greek_str as shown below:

- Important Note: You will most likely see the string appearing as empty spaces as shown above. Don't worry. It's because the Notepad cannot display these unicode characters.
- Now try to run it. You should be able to see the math or greek characters that you have selected appear in your php-gtk2 script.
Sample Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <?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 2 - Input unicode characters"); $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 =""; // note 1
|
- 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 The sample code above is based on How to display math and greek characters using symbol font - Part 1?
What's new here:
- As explained above, the Notepad cannot display unicode characters. In your browser, it's displayed as some garbage characters. On your Notepad, it should be displayed as just empty spaces.
Related Links
|
Add comment
|