msi: Improve font version parsing.

This commit is contained in:
Hans Leidekker 2011-09-23 11:12:40 +02:00 committed by Alexandre Julliard
parent 7c7e0bd51d
commit 19a965f581
1 changed files with 21 additions and 18 deletions

View File

@ -145,25 +145,18 @@ static WCHAR *load_ttf_name_id( const WCHAR *filename, DWORD id )
ttRecord.uNameID = SWAPWORD(ttRecord.uNameID); ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
if (ttRecord.uNameID == id) if (ttRecord.uNameID == id)
{ {
int nPos;
LPSTR buf; LPSTR buf;
ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength); ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset); ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
SetFilePointer(handle, tblDir.uOffset + ttRecord.uStringOffset + ttNTHeader.uStorageOffset, SetFilePointer(handle, tblDir.uOffset + ttRecord.uStringOffset + ttNTHeader.uStorageOffset,
NULL, FILE_BEGIN); NULL, FILE_BEGIN);
buf = msi_alloc_zero( ttRecord.uStringLength + 1 ); if (!(buf = msi_alloc_zero( ttRecord.uStringLength + 1 ))) goto end;
ReadFile(handle, buf, ttRecord.uStringLength, &dwRead, NULL); ReadFile(handle, buf, ttRecord.uStringLength, &dwRead, NULL);
if (strlen(buf) > 0)
{
ret = strdupAtoW(buf); ret = strdupAtoW(buf);
msi_free(buf); msi_free(buf);
break; break;
} }
msi_free(buf);
SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
}
} }
end: end:
@ -179,6 +172,12 @@ static WCHAR *font_name_from_file( const WCHAR *filename )
if ((name = load_ttf_name_id( filename, NAME_ID_FULL_FONT_NAME ))) if ((name = load_ttf_name_id( filename, NAME_ID_FULL_FONT_NAME )))
{ {
if (!name[0])
{
WARN("empty font name\n");
msi_free( name );
return NULL;
}
ret = msi_alloc( (strlenW( name ) + strlenW( truetypeW ) + 1 ) * sizeof(WCHAR) ); ret = msi_alloc( (strlenW( name ) + strlenW( truetypeW ) + 1 ) * sizeof(WCHAR) );
strcpyW( ret, name ); strcpyW( ret, name );
strcatW( ret, truetypeW ); strcatW( ret, truetypeW );
@ -189,22 +188,26 @@ static WCHAR *font_name_from_file( const WCHAR *filename )
WCHAR *msi_font_version_from_file( const WCHAR *filename ) WCHAR *msi_font_version_from_file( const WCHAR *filename )
{ {
static const WCHAR dotzerodotzeroW[] = {'.','0','.','0',0}; static const WCHAR fmtW[] = {'%','u','.','%','u','.','0','.','0',0};
WCHAR *version, *p, *ret = NULL; WCHAR *version, *p, *q, *ret = NULL;
int len;
if ((version = load_ttf_name_id( filename, NAME_ID_VERSION ))) if ((version = load_ttf_name_id( filename, NAME_ID_VERSION )))
{ {
int len, major = 0, minor = 0;
if ((p = strchrW( version, ';' ))) *p = 0; if ((p = strchrW( version, ';' ))) *p = 0;
p = version; p = version;
while (*p && !isdigitW( *p )) p++; while (*p && !isdigitW( *p )) p++;
len = strlenW( p ) + strlenW(dotzerodotzeroW) + 1; if ((q = strchrW( p, '.' )))
ret = msi_alloc( len * sizeof(WCHAR) );
strcpyW( ret, p );
if ((p = strchrW( p, '.' )) && !(p = strchrW( p + 1, '.' )))
{ {
strcatW( ret, dotzerodotzeroW ); major = atoiW( p );
p = ++q;
while (*q && isdigitW( *q )) q++;
if (!*q || *q == ' ') minor = atoiW( p );
else major = 0;
} }
len = strlenW( fmtW ) + 20;
ret = msi_alloc( len * sizeof(WCHAR) );
sprintfW( ret, fmtW, major, minor );
msi_free( version ); msi_free( version );
} }
return ret; return ret;