comparison win/dw.c @ 1060:efa7d527adea

Use the actual Windows point size for a device... doing conversion as necessary.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 02 Jun 2011 23:55:38 +0000
parents 2f79f183ff03
children 28e63fe64167
comparison
equal deleted inserted replaced
1059:2f79f183ff03 1060:efa7d527adea
3993 void API dw_window_reparent(HWND handle, HWND newparent) 3993 void API dw_window_reparent(HWND handle, HWND newparent)
3994 { 3994 {
3995 SetParent(handle, newparent); 3995 SetParent(handle, newparent);
3996 } 3996 }
3997 3997
3998 LOGFONT _get_logfont(char *fontname) 3998 LOGFONT _get_logfont(HWND handle, char *fontname)
3999 { 3999 {
4000 int Italic, Bold; 4000 int Italic, Bold;
4001 char *myFontName; 4001 char *myFontName;
4002 int z, size = 9; 4002 int z, size = 9;
4003 LOGFONT lf; 4003 LOGFONT lf;
4004 HDC hdc = GetDC(handle);
4005
4004 for(z=0;z<strlen(fontname);z++) 4006 for(z=0;z<strlen(fontname);z++)
4005 { 4007 {
4006 if(fontname[z]=='.') 4008 if(fontname[z]=='.')
4007 break; 4009 break;
4008 } 4010 }
4009 size = atoi(fontname) + 5; /* no idea why this 5 needs to be added */ 4011 size = atoi(fontname);
4012 lf.lfHeight = -MulDiv(size, GetDeviceCaps(hdc, LOGPIXELSY), 72);
4013 ReleaseDC(handle, hdc);
4010 Italic = instring(" Italic", &fontname[z+1]); 4014 Italic = instring(" Italic", &fontname[z+1]);
4011 Bold = instring(" Bold", &fontname[z+1]); 4015 Bold = instring(" Bold", &fontname[z+1]);
4012 lf.lfHeight = size;
4013 lf.lfWidth = 0; 4016 lf.lfWidth = 0;
4014 lf.lfEscapement = 0; 4017 lf.lfEscapement = 0;
4015 lf.lfOrientation = 0; 4018 lf.lfOrientation = 0;
4016 lf.lfItalic = Italic ? TRUE : FALSE; 4019 lf.lfItalic = Italic ? TRUE : FALSE;
4017 lf.lfUnderline = 0; 4020 lf.lfUnderline = 0;
4039 { 4042 {
4040 HFONT hfont = 0; 4043 HFONT hfont = 0;
4041 4044
4042 if(fontname != DefaultFont && fontname[0]) 4045 if(fontname != DefaultFont && fontname[0])
4043 { 4046 {
4044 LOGFONT lf = _get_logfont(fontname); 4047 LOGFONT lf = _get_logfont(handle, fontname);
4045 hfont = CreateFontIndirect(&lf); 4048 hfont = CreateFontIndirect(&lf);
4046 } 4049 }
4047 if(!hfont) 4050 if(!hfont)
4048 hfont = GetStockObject(DEFAULT_GUI_FONT); 4051 hfont = GetStockObject(DEFAULT_GUI_FONT);
4049 return hfont; 4052 return hfont;
4117 char *str = NULL; 4120 char *str = NULL;
4118 char *bold = ""; 4121 char *bold = "";
4119 char *italic = ""; 4122 char *italic = "";
4120 4123
4121 if(currfont && *currfont) 4124 if(currfont && *currfont)
4122 lf = _get_logfont(currfont); 4125 lf = _get_logfont(NULL, currfont);
4123 4126
4124 cf.lStructSize = sizeof(cf); 4127 cf.lStructSize = sizeof(cf);
4125 cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT; 4128 cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT;
4126 cf.lpLogFont = &lf; 4129 cf.lpLogFont = &lf;
4127 4130
4129 { 4132 {
4130 str = (char *)malloc( 100 ); 4133 str = (char *)malloc( 100 );
4131 if ( str ) 4134 if ( str )
4132 { 4135 {
4133 int height; 4136 int height;
4137 HDC hdc = GetDC(NULL);
4138
4134 if ( lf.lfWeight > FW_MEDIUM ) 4139 if ( lf.lfWeight > FW_MEDIUM )
4135 bold = " Bold"; 4140 bold = " Bold";
4136 if ( lf.lfItalic ) 4141 if ( lf.lfItalic )
4137 italic = " Italic"; 4142 italic = " Italic";
4138 if ( lf.lfHeight <= 0 ) 4143 height = MulDiv(abs(lf.lfHeight), 72, GetDeviceCaps (hdc, LOGPIXELSY));
4139 height = abs (lf.lfHeight ); 4144 ReleaseDC(NULL, hdc);
4140 else
4141 /*
4142 * we subtract 5 from a positive font height, because we (presumably)
4143 * added 5 (in _acquire_font() above - don't know why )
4144 */
4145 height = lf.lfHeight - 5;
4146 sprintf( str, "%d.%s%s%s", height, lf.lfFaceName, bold, italic ); 4145 sprintf( str, "%d.%s%s%s", height, lf.lfFaceName, bold, italic );
4147 } 4146 }
4148 } 4147 }
4149 return str; 4148 return str;
4150 } 4149 }
4180 { 4179 {
4181 str = (char *)malloc( 100 ); 4180 str = (char *)malloc( 100 );
4182 if ( str ) 4181 if ( str )
4183 { 4182 {
4184 int height; 4183 int height;
4184 HDC hdc = GetDC(handle);
4185
4185 if ( lf.lfWeight > FW_MEDIUM ) 4186 if ( lf.lfWeight > FW_MEDIUM )
4186 bold = " Bold"; 4187 bold = " Bold";
4187 if ( lf.lfItalic ) 4188 if ( lf.lfItalic )
4188 italic = " Italic"; 4189 italic = " Italic";
4189 if ( lf.lfHeight <= 0 ) 4190 height = MulDiv(abs(lf.lfHeight), 72, GetDeviceCaps (hdc, LOGPIXELSY));
4190 height = abs (lf.lfHeight ); 4191 ReleaseDC(handle, hdc);
4191 else
4192 /*
4193 * we subtract 5 from a positive font height, because we (presumably)
4194 * added 5 (in _acquire_font() above - don't know why )
4195 */
4196 height = lf.lfHeight - 5;
4197 sprintf( str, "%d.%s%s%s", height, lf.lfFaceName, bold, italic ); 4192 sprintf( str, "%d.%s%s%s", height, lf.lfFaceName, bold, italic );
4198 } 4193 }
4199 } 4194 }
4200 if ( oldfont ) 4195 if ( oldfont )
4201 DeleteObject( oldfont ); 4196 DeleteObject( oldfont );