Mercurial > dwindows
diff gtk/dw.c @ 49:bf42d08d72d7
Added font text extent querying code, and made it so winmain.c can be used
without Dynamic Windows.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 09 Nov 2001 13:49:44 +0000 |
parents | 16eac0f8b45f |
children | d97de82f0b6e |
line wrap: on
line diff
--- a/gtk/dw.c Mon Nov 05 10:56:39 2001 +0000 +++ b/gtk/dw.c Fri Nov 09 13:49:44 2001 +0000 @@ -3478,6 +3478,9 @@ GdkFont *font; char *fontname = "fixed"; + if(!text) + return; + DW_MUTEX_LOCK; if(handle) { @@ -3505,6 +3508,41 @@ DW_MUTEX_UNLOCK; } +/* Query the width and height of a text string. + * Parameters: + * handle: Handle to the window. + * pixmap: Handle to the pixmap. (choose only one of these) + * text: Text to be queried. + * width: Pointer to a variable to be filled in with the width. + * height Pointer to a variable to be filled in with the height. + */ +void dw_font_text_extents(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height) +{ + int _locked_by_me = FALSE; + GdkFont *font; + char *fontname = NULL; + + if(!text) + return; + + DW_MUTEX_LOCK; + if(handle) + fontname = (char *)gtk_object_get_data(GTK_OBJECT(handle), "fontname"); + else if(pixmap) + fontname = (char *)gtk_object_get_data(GTK_OBJECT(pixmap->handle), "fontname"); + + font = gdk_font_load(fontname ? fontname : "fixed"); + if(font) + { + if(width) + *width = gdk_string_width(font, text); + if(height) + *height = gdk_string_height(font, text); + gdk_font_unref(font); + } + DW_MUTEX_UNLOCK; +} + /* * Creates a pixmap with given parameters. * Parameters: