comparison win/dw.c @ 1238:700ce342aab8

Divided _acquire_font() into two parts on Windows. Allowing us to use the HDC of the pixmap to set the font... allowing for better sized fonts on printer contexts.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 18 Oct 2011 08:26:36 +0000
parents 4a7a9f102a5f
children c191a562c14a
comparison
equal deleted inserted replaced
1237:f8673299ec37 1238:700ce342aab8
3887 void API dw_window_reparent(HWND handle, HWND newparent) 3887 void API dw_window_reparent(HWND handle, HWND newparent)
3888 { 3888 {
3889 SetParent(handle, newparent); 3889 SetParent(handle, newparent);
3890 } 3890 }
3891 3891
3892 LOGFONT _get_logfont(HWND handle, char *fontname) 3892 LOGFONT _get_logfont(HDC hdc, char *fontname)
3893 { 3893 {
3894 int Italic, Bold; 3894 int Italic, Bold;
3895 char *myFontName; 3895 char *myFontName;
3896 int z, size = 9; 3896 int z, size = 9;
3897 LOGFONT lf; 3897 LOGFONT lf;
3898 HDC hdc = GetDC(handle);
3899 3898
3900 for(z=0;z<strlen(fontname);z++) 3899 for(z=0;z<strlen(fontname);z++)
3901 { 3900 {
3902 if(fontname[z]=='.') 3901 if(fontname[z]=='.')
3903 break; 3902 break;
3904 } 3903 }
3905 size = atoi(fontname); 3904 size = atoi(fontname);
3906 lf.lfHeight = -MulDiv(size, GetDeviceCaps(hdc, LOGPIXELSY), 72); 3905 lf.lfHeight = -MulDiv(size, GetDeviceCaps(hdc, LOGPIXELSY), 72);
3907 ReleaseDC(handle, hdc);
3908 Italic = instring(" Italic", &fontname[z+1]); 3906 Italic = instring(" Italic", &fontname[z+1]);
3909 Bold = instring(" Bold", &fontname[z+1]); 3907 Bold = instring(" Bold", &fontname[z+1]);
3910 lf.lfWidth = 0; 3908 lf.lfWidth = 0;
3911 lf.lfEscapement = 0; 3909 lf.lfEscapement = 0;
3912 lf.lfOrientation = 0; 3910 lf.lfOrientation = 0;
3942 } 3940 }
3943 3941
3944 /* Create a font handle from specified font name.. 3942 /* Create a font handle from specified font name..
3945 * or return a handle to the default font. 3943 * or return a handle to the default font.
3946 */ 3944 */
3947 HFONT _acquire_font(HWND handle, char *fontname) 3945 HFONT _acquire_font2(HDC hdc, char *fontname)
3948 { 3946 {
3949 HFONT hfont = 0; 3947 HFONT hfont = 0;
3950 3948
3951 if(fontname != DefaultFont && fontname[0]) 3949 if(fontname != DefaultFont && fontname[0])
3952 { 3950 {
3953 LOGFONT lf = _get_logfont(handle, fontname); 3951 LOGFONT lf = _get_logfont(hdc, fontname);
3954 hfont = CreateFontIndirect(&lf); 3952 hfont = CreateFontIndirect(&lf);
3955 } 3953 }
3956 if(!hfont && _DefaultFont) 3954 if(!hfont && _DefaultFont)
3957 hfont = _DupFontHandle(_DefaultFont); 3955 hfont = _DupFontHandle(_DefaultFont);
3958 if(!hfont) 3956 if(!hfont)
3959 hfont = GetStockObject(DEFAULT_GUI_FONT); 3957 hfont = GetStockObject(DEFAULT_GUI_FONT);
3958 return hfont;
3959 }
3960
3961 /* Create a font handle from specified font name..
3962 * or return a handle to the default font.
3963 */
3964 HFONT _acquire_font(HWND handle, char *fontname)
3965 {
3966 HDC hdc = GetDC(handle);
3967 HFONT hfont = _acquire_font2(hdc, fontname);
3968 ReleaseDC(handle, hdc);
3960 return hfont; 3969 return hfont;
3961 } 3970 }
3962 3971
3963 /* 3972 /*
3964 * Sets the default font used on text based widgets. 3973 * Sets the default font used on text based widgets.
8965 */ 8974 */
8966 int API dw_pixmap_set_font(HPIXMAP pixmap, char *fontname) 8975 int API dw_pixmap_set_font(HPIXMAP pixmap, char *fontname)
8967 { 8976 {
8968 if(pixmap) 8977 if(pixmap)
8969 { 8978 {
8970 HFONT hfont = _acquire_font(pixmap->handle, fontname); 8979 HFONT hfont = _acquire_font2(pixmap->hdc, fontname);
8971 8980
8972 if(hfont) 8981 if(hfont)
8973 { 8982 {
8974 HFONT oldfont = pixmap->font; 8983 HFONT oldfont = pixmap->font;
8975 pixmap->font = hfont; 8984 pixmap->font = hfont;
10059 return result; 10068 return result;
10060 10069
10061 pixmap->width = GetDeviceCaps(p->pd.hDC, HORZRES); 10070 pixmap->width = GetDeviceCaps(p->pd.hDC, HORZRES);
10062 pixmap->height = GetDeviceCaps(p->pd.hDC, VERTRES); 10071 pixmap->height = GetDeviceCaps(p->pd.hDC, VERTRES);
10063 10072
10064 /*pixmap->handle = handle;*/
10065 pixmap->hbm = CreateCompatibleBitmap(p->pd.hDC, pixmap->width, pixmap->height); 10073 pixmap->hbm = CreateCompatibleBitmap(p->pd.hDC, pixmap->width, pixmap->height);
10066 pixmap->hdc = p->pd.hDC; 10074 pixmap->hdc = p->pd.hDC;
10067 pixmap->transcolor = DW_RGB_TRANSPARENT; 10075 pixmap->transcolor = DW_RGB_TRANSPARENT;
10068 10076
10069 SelectObject(pixmap->hdc, pixmap->hbm); 10077 SelectObject(pixmap->hdc, pixmap->hbm);