Jump to content
  • Advertisement
Sign in to follow this  

[C] - Unicode in GTK.

This topic is 4041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In Visual C 2005 EE, To Compiler: /Od /I "C:\GTK\include\atk-1.0" /I "C:\GTK\include\pango-1.0" /I "C:\GTK\lib\glib-2.0\include" /I "C:\GTK\include\glib-2.0" /I "C:\GTK\include\cairo" /I "C:\GTK\include\gtk-2.0" /I "C:\GTK\lib\gtk-2.0\include" /I "C:\GTK\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /nologo /c /Wp64 /ZI /TC /errorReport:prompt To Linker: /OUT:"C:\Pete's\Projects\Ryerson\COE518\testgtk\Debug\testgtk.exe" /INCREMENTAL /NOLOGO /LIBPATH:"C:\GTK\lib" /MANIFEST /MANIFESTFILE:"Debug\testgtk.exe.intermediate.manifest" /DEBUG /PDB:"c:\pete's\projects\ryerson\coe518\testgtk\debug\testgtk.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 /ERRORREPORT:PROMPT glib-2.0.lib gobject-2.0.lib gthread-2.0.lib gdk-win32-2.0.lib gdk_pixbuf-2.0.lib gtk-win32-2.0.lib atk-1.0.lib pango-1.0.lib kernel32.lib Source Code:
#include <gtk/gtk.h>

 * Terminate the main loop.
static void on_destroy (GtkWidget * widget, gpointer data)
    gtk_main_quit ();

int main (int argc, char *argv[])
    GtkWidget *window;
    GtkWidget *label;

    gtk_init (&argc, &argv);

    /* create the main, top level, window */
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    /* give the window a 20px wide border */
    gtk_container_set_border_width (GTK_CONTAINER (window), 20);

    /* give it the title */
	gtk_window_set_title (GTK_WINDOW (window), "GTK Title");

    /* open it a bit wider so that both the label and title show up */
    gtk_window_set_default_size (GTK_WINDOW (window), 200, 50);

    /* Connect the destroy event of the window with our on_destroy function
     * When the window is about to be destroyed we get a notificaiton and
     * stop the main GTK loop
    g_signal_connect (G_OBJECT (window), "destroy",
                      G_CALLBACK (on_destroy), NULL);

    /* Create the "Hello, World" label  */
    label = gtk_label_new ((const gchar *)L"\u7279");

    /* and insert it into the main window  */
    gtk_container_add (GTK_CONTAINER (window), label);

    /* make sure that everything, window and label, are visible */
    gtk_widget_show_all (window);

    /* start the main loop */
    gtk_main ();

    return 0;

Output: (should render a label with a CJK glyph in the middle, but instead it renders a "yr" string) An image of the window. Notes: pango.alises is found in "etc/pango" from where the DLLs required for GTK are being called (in this case, it's in "debug/" of the project folder. pango.alises contains "mingliu", a font that can render these CJK glyphs. I've tried multibyte encoding, and every iteration of using it and L"..." "..." along with breaking \uXXYY into \xXX\xYY.

Share this post

Link to post
Share on other sites
GTK+ uses UTF-8 for Unicode, while L"..." string literals are wide strings -- usually UTF-16-encoded Unicode on MSVC.

Either use simple "ýáí"-style string literals in your source and fiddle with your compiler flags and source file encoding so that it works right, or just save the strings in an external file and control the encoding yourself.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!