Mercurial > dwindows
diff win/dw.c @ 1147:091ed7c20b3f
Implemented dw_pixmap_set_font() on Windows. Added to export files on Windows and OS/2.
Added the function to the template and fixed the comments on several platforms.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 11 Sep 2011 21:56:55 +0000 |
parents | b1b23de965d7 |
children | 58b5374355ab |
line wrap: on
line diff
--- a/win/dw.c Sun Sep 11 21:36:07 2011 +0000 +++ b/win/dw.c Sun Sep 11 21:56:55 2011 +0000 @@ -8618,7 +8618,7 @@ HDC hdc; int mustdelete = 0; HFONT hFont = 0, oldFont = 0; - ColorInfo *cinfo; + ColorInfo *cinfo = NULL; COLORREF background; if(handle) @@ -8630,7 +8630,9 @@ if(handle) cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); - else + else if(pixmap->font) + hFont = pixmap->font; + else if(pixmap->handle) cinfo = (ColorInfo *)GetWindowLongPtr(pixmap->handle, GWLP_USERDATA); if(cinfo) @@ -8988,6 +8990,35 @@ } /* + * Sets the font used by a specified pixmap. + * Normally the pixmap font is obtained from the associated window handle. + * However this can be used to override that, or for pixmaps with no window. + * Parameters: + * pixmap: Handle to a pixmap returned by dw_pixmap_new() or + * passed to the application via a callback. + * fontname: Name and size of the font in the form "size.fontname" + * Returns: + * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. + */ +int API dw_pixmap_set_font(HPIXMAP pixmap, char *fontname) +{ + if(pixmap) + { + HFONT hfont = _acquire_font(pixmap->handle, fontname); + + if(hfont) + { + HFONT oldfont = pixmap->font; + pixmap->font = hfont; + if(oldfont) + DeleteObject(oldfont); + return DW_ERROR_NONE; + } + } + return DW_ERROR_GENERAL; +} + +/* * Destroys an allocated pixmap. * Parameters: * pixmap: Handle to a pixmap returned by @@ -8997,9 +9028,11 @@ { if(pixmap) { - DeleteDC( pixmap->hdc ); - DeleteObject( pixmap->hbm ); - free( pixmap ); + DeleteDC(pixmap->hdc); + DeleteObject(pixmap->hbm); + if(pixmap->font) + DeleteObject(pixmap->font); + free(pixmap); } } @@ -10058,8 +10091,8 @@ if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) return result; - pixmap->width = GetDeviceCaps(p->pd.hDC, PHYSICALWIDTH); - pixmap->height = GetDeviceCaps(p->pd.hDC, PHYSICALHEIGHT); + pixmap->width = GetDeviceCaps(p->pd.hDC, HORZRES); + pixmap->height = GetDeviceCaps(p->pd.hDC, VERTRES); /*pixmap->handle = handle;*/ pixmap->hbm = CreateCompatibleBitmap(p->pd.hDC, pixmap->width, pixmap->height);