Mercurial > dwindows
changeset 1146:9d97610b2140
Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
When drawing to pixmaps, normally the font is obtained from the associated window handle.
This will allow overriding of the font for this pixmap, and will allow setting fonts on
pixmaps that don't have associated window handles.
This commit has the Mac support. Other platforms coming in the next hour.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 11 Sep 2011 21:36:07 +0000 |
parents | 9c47a0245872 |
children | 091ed7c20b3f |
files | dw.h dwtest.c mac/dw.m |
diffstat | 3 files changed, 62 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/dw.h Sun Sep 11 20:52:44 2011 +0000 +++ b/dw.h Sun Sep 11 21:36:07 2011 +0000 @@ -306,7 +306,7 @@ typedef struct _hpixmap { unsigned long width, height; - void *image; + void *image, *font; HWND handle; } *HPIXMAP; @@ -636,6 +636,7 @@ HWND handle; void *bits; unsigned long depth; + HFONT font; } *HPIXMAP; typedef HWND HMENUI; @@ -1257,6 +1258,8 @@ typedef struct _hpixmap { unsigned long width, height; + HWND handle; + void *font; #if GTK_MAJOR_VERSION > 2 GdkPixbuf *pixbuf; /* the actual image */ cairo_surface_t *image; /* Going to have dual storage for now */ @@ -1264,7 +1267,6 @@ GdkPixmap *pixmap; /* the actual image */ GdkBitmap *bitmap; /* if not null, the image mask representing the transparency mask */ #endif - HWND handle; } *HPIXMAP; typedef GtkWidget *HMENUI; @@ -1647,6 +1649,7 @@ HPIXMAP API dw_pixmap_new_from_data(HWND handle, char *data, int len); HPIXMAP API dw_pixmap_grab(HWND handle, ULONG id); void API dw_pixmap_set_transparent_color( HPIXMAP pixmap, ULONG color ); +int API dw_pixmap_set_font(HPIXMAP pixmap, char *fontname); void API dw_pixmap_destroy(HPIXMAP pixmap); void API dw_beep(int freq, int dur); int API dw_messagebox(char *title, int flags, char *format, ...);
--- a/dwtest.c Sun Sep 11 20:52:44 2011 +0000 +++ b/dwtest.c Sun Sep 11 21:36:07 2011 +0000 @@ -380,6 +380,7 @@ int DWSIGNAL draw_page(HPRINT print, HPIXMAP pixmap, int page_num, void *data) { + dw_pixmap_set_font(pixmap, FIXEDFONT); draw_shapes(FALSE, pixmap); return TRUE; }
--- a/mac/dw.m Sun Sep 11 20:52:44 2011 +0000 +++ b/mac/dw.m Sun Sep 11 21:36:07 2011 +0000 @@ -4803,9 +4803,9 @@ } if(pixmap) { - NSFont *font = nil; + NSFont *font = pixmap->font; DWRender *render = pixmap->handle; - if([render isMemberOfClass:[DWRender class]]) + if(!font && [render isMemberOfClass:[DWRender class]]) { font = [render font]; } @@ -6074,6 +6074,24 @@ return retval; } +/* Internal function to convert fontname to NSFont */ +NSFont *_dw_font_by_name(char *fontname) +{ + char *fontcopy = strdup(fontname); + char *name = strchr(fontcopy, '.'); + NSFont *font = nil; + + if(name) + { + int size = atoi(fontcopy); + *name = 0; + name++; + font = [NSFont fontWithName:[ NSString stringWithUTF8String:name ] size:(float)size]; + } + free(fontcopy); + return font; +} + /* * Create a bitmap object to be packed. * Parameters: @@ -6276,6 +6294,35 @@ return pixmap; } + +/* + * 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" + */ +int API dw_pixmap_set_font(HPIXMAP pixmap, char *fontname) +{ + if(pixmap) + { + NSFont *font = _dw_font_by_name(fontname); + + if(font) + { + NSFont *oldfont = pixmap->font; + [font retain]; + pixmap->font = font; + if(oldfont) + [oldfont release]; + return DW_ERROR_NONE; + } + } + return DW_ERROR_GENERAL; +} + /* * Destroys an allocated pixmap. * Parameters: @@ -6284,11 +6331,13 @@ */ void API dw_pixmap_destroy(HPIXMAP pixmap) { - if ( pixmap ) - { - NSBitmapImageRep *image = (NSBitmapImageRep *)pixmap->image; - [image release]; - free(pixmap); + if(pixmap) + { + NSBitmapImageRep *image = (NSBitmapImageRep *)pixmap->image; + NSFont *font = pixmap->font; + [image release]; + [font release]; + free(pixmap); } } @@ -7266,23 +7315,6 @@ } } -NSFont *_dw_font_by_name(char *fontname) -{ - char *fontcopy = strdup(fontname); - char *name = strchr(fontcopy, '.'); - NSFont *font = nil; - - if(name) - { - int size = atoi(fontcopy); - *name = 0; - name++; - font = [NSFont fontWithName:[ NSString stringWithUTF8String:name ] size:(float)size]; - } - free(fontcopy); - return font; -} - /* Allows the user to choose a font using the system's font chooser dialog. * Parameters: * currfont: current font