Mercurial > dwindows
changeset 1621:0e8c80209c4b
Rewrite of _get_logfont on Windows to use library functions and
not overrun the buffer in Unicode mode.
Also use _strdup() instead of strdup().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 27 Mar 2012 15:57:36 +0000 |
parents | 32b5fba0b00a |
children | fb3c9d7509dd |
files | win/dw.c |
diffstat | 1 files changed, 17 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/win/dw.c Tue Mar 27 15:09:52 2012 +0000 +++ b/win/dw.c Tue Mar 27 15:57:36 2012 +0000 @@ -2820,7 +2820,7 @@ val = (long)SendMessage(cinfo->buddy, UDM_GETPOS32, 0, 0); - _stprintf(tmpbuf, TEXT("%ld"), val); + _sntprintf(tmpbuf, 99, TEXT("%ld"), val); SetWindowText(hWnd, tmpbuf); } } @@ -4396,21 +4396,6 @@ } } -int instring(char *text, char *buffer) -{ - int z, len = (int)strlen(text), buflen = (int)strlen(buffer); - - if(buflen > len) - { - for(z=0;z<=(buflen-len);z++) - { - if(memcmp(text, &buffer[z], len) == 0) - return z; - } - } - return 0; -} - /* * Changes a window's parent to newparent. * Parameters: @@ -4424,20 +4409,19 @@ LOGFONT _get_logfont(HDC hdc, char *fontname) { - int z, size = 9, len = (int)strlen(fontname); - int Italic, Bold; - char *myFontName; + char *Italic, *Bold, *myFontName = strchr(fontname, '.'); + int size = atoi(fontname); LOGFONT lf = {0}; - for(z=0;z<len;z++) - { - if(fontname[z]=='.') - break; - } - size = atoi(fontname); - lf.lfHeight = -MulDiv(size, GetDeviceCaps(hdc, LOGPIXELSY), 72); - Italic = instring(" Italic", &fontname[z+1]); - Bold = instring(" Bold", &fontname[z+1]); + /* If we found a '.' use the location after the . */ + if(myFontName) + myFontName = _strdup(++myFontName); + else /* Otherwise use the whole fontname and default size of 9 */ + myFontName = _strdup(fontname); + + lf.lfHeight = -MulDiv(size ? size : 9, GetDeviceCaps(hdc, LOGPIXELSY), 72); + Italic = strstr(myFontName, " Italic"); + Bold = strstr(myFontName, " Bold"); lf.lfWidth = 0; lf.lfEscapement = 0; lf.lfOrientation = 0; @@ -4450,15 +4434,11 @@ lf.lfClipPrecision = 0; lf.lfQuality = DEFAULT_QUALITY; lf.lfPitchAndFamily = DEFAULT_PITCH | FW_DONTCARE; - /* - * remove any font modifiers - */ - myFontName = _strdup(&fontname[z+1]); if(Italic) - myFontName[Italic] = 0; + *Italic = 0; if(Bold) - myFontName[Bold] = 0; - _tcsncpy(lf.lfFaceName, UTF8toWide(myFontName), sizeof(lf.lfFaceName)-1); + *Bold = 0; + _tcsncpy(lf.lfFaceName, UTF8toWide(myFontName), (sizeof(lf.lfFaceName)/sizeof(TCHAR))-1); free(myFontName); return lf; } @@ -6801,7 +6781,7 @@ * and fill it with the UTF8 text and return it. */ if(tempbuf && (retbuf = WideToUTF8(tempbuf))) - retbuf = strdup(retbuf); + retbuf = _strdup(retbuf); return retbuf; } @@ -8555,7 +8535,7 @@ tvi.hItem = item; if(TreeView_GetItem(handle, &tvi)) - return strdup(WideToUTF8(tvi.pszText)); + return _strdup(WideToUTF8(tvi.pszText)); return NULL; }