Mercurial > dwindows
changeset 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 | 267b382442d6 |
files | dw.def dw.h dww.def gtk/dw.c os2/dw.c win/dw.c winmain.c |
diffstat | 7 files changed, 140 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/dw.def Mon Nov 05 10:56:39 2001 +0000 +++ b/dw.def Fri Nov 09 13:49:44 2001 +0000 @@ -203,3 +203,5 @@ dw_tree_clear @372 dw_tree_delete @373 + dw_font_text_extents @380 +
--- a/dw.h Mon Nov 05 10:56:39 2001 +0000 +++ b/dw.h Fri Nov 09 13:49:44 2001 +0000 @@ -727,6 +727,7 @@ void dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2); void dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height); void dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text); +void dw_font_text_extents(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height); void dw_flush(void); void dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc); HPIXMAP dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth);
--- a/dww.def Mon Nov 05 10:56:39 2001 +0000 +++ b/dww.def Fri Nov 09 13:49:44 2001 +0000 @@ -199,3 +199,6 @@ dw_tree_insert @371 dw_tree_clear @372 dw_tree_delete @373 + + dw_font_text_extents @380 +
--- 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:
--- a/os2/dw.c Mon Nov 05 10:56:39 2001 +0000 +++ b/os2/dw.c Fri Nov 09 13:49:44 2001 +0000 @@ -5406,8 +5406,45 @@ WinReleasePS(hps); } - - +/* 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) +{ + HPS hps; + POINTL aptl[TXTBOX_COUNT]; + + if(handle) + { + hps = _set_colors(handle); + } + else if(pixmap) + { + HPS pixmaphps = WinGetPS(pixmap->handle); + + hps = _set_hps(pixmap->hps); + _CopyFontSettings(pixmaphps, hps); + WinReleasePS(pixmaphps); + } + else + return; + + GpiQueryTextBox(hps, strlen(text), text, TXTBOX_COUNT, aptl); + + if(width) + *width = aptl[TXTBOX_TOPRIGHT].x - aptl[TXTBOX_TOPLEFT].x; + + if(height) + *height = aptl[TXTBOX_TOPLEFT].y - aptl[TXTBOX_BOTTOMLEFT].y; + + if(!pixmap) + WinReleasePS(hps); +} /* Draw a rectangle on a window (preferably a render window). * Parameters:
--- a/win/dw.c Mon Nov 05 10:56:39 2001 +0000 +++ b/win/dw.c Fri Nov 09 13:49:44 2001 +0000 @@ -5400,6 +5400,59 @@ ReleaseDC(handle, hdc); } +/* 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) +{ + HDC hdc; + int mustdelete = 0; + HFONT hFont, oldFont; + SIZE sz; + + if(handle) + hdc = GetDC(handle); + else if(pixmap) + hdc = pixmap->hdc; + else + return; + + { + ColorInfo *cinfo; + + if(handle) + cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA); + else + cinfo = (ColorInfo *)GetWindowLong(pixmap->handle, GWL_USERDATA); + + if(cinfo) + { + hFont = _aquire_font(cinfo->fontname); + mustdelete = 1; + } + } + oldFont = SelectObject(hdc, hFont); + + GetTextExtentPoint32(hdc, text, strlen(text), &sz); + + if(width) + *width = sz.cx; + + if(height) + *height = sz.cy; + + SelectObject(hdc, oldFont); + if(mustdelete) + DeleteObject(hFont); + if(!pixmap) + ReleaseDC(handle, hdc); +} + /* Call this after drawing to the screen to make sure * anything you have drawn is visible. */
--- a/winmain.c Mon Nov 05 10:56:39 2001 +0000 +++ b/winmain.c Fri Nov 09 13:49:44 2001 +0000 @@ -8,7 +8,9 @@ #include <stdio.h> #include <process.h> +#ifndef NODW void Win32_Set_Instance(HINSTANCE hInstance); +#endif char **_convertargs(int *count, char *start, HINSTANCE DWInstance) { @@ -100,7 +102,9 @@ char **argv; int argc; +#ifndef NODW Win32_Set_Instance(hInstance); +#endif argv = _convertargs(&argc, lpCmdLine, hInstance);