Commit c07f4cbd authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

Added support for BTrees in file header reading.

Fixed bogus palette length computation while reading bitmap. Fixed rendering while starting a page with a bitmap.
parent 45af4922
...@@ -185,6 +185,7 @@ LONG HLPFILE_Hash(LPCSTR lpszContext) ...@@ -185,6 +185,7 @@ LONG HLPFILE_Hash(LPCSTR lpszContext)
} }
return lHash; return lHash;
} }
/*********************************************************************** /***********************************************************************
* *
* HLPFILE_ReadHlpFile * HLPFILE_ReadHlpFile
...@@ -513,7 +514,10 @@ static BOOL HLPFILE_LoadPictureByAddr(HLPFILE *hlpfile, char* ref, ...@@ -513,7 +514,10 @@ static BOOL HLPFILE_LoadPictureByAddr(HLPFILE *hlpfile, char* ref,
unsigned nc = bi->bmiHeader.biClrUsed; unsigned nc = bi->bmiHeader.biClrUsed;
unsigned i; unsigned i;
if (!nc) nc = 1 << bi->bmiHeader.biBitCount; /* not quite right, especially for bitfields type of compression */
if (!nc && bi->bmiHeader.biBitCount <= 8)
nc = 1 << bi->bmiHeader.biBitCount;
bi = HeapReAlloc(GetProcessHeap(), 0, bi, sizeof(*bi) + nc * sizeof(RGBQUAD)); bi = HeapReAlloc(GetProcessHeap(), 0, bi, sizeof(*bi) + nc * sizeof(RGBQUAD));
if (!bi) return FALSE; if (!bi) return FALSE;
for (i = 0; i < nc; i++) for (i = 0; i < nc; i++)
...@@ -614,7 +618,7 @@ static BOOL HLPFILE_LoadPictureByIndex(HLPFILE *hlpfile, unsigned index, uns ...@@ -614,7 +618,7 @@ static BOOL HLPFILE_LoadPictureByIndex(HLPFILE *hlpfile, unsigned index, uns
BYTE *ref, *end; BYTE *ref, *end;
WINE_TRACE("Loading picture #%d\n", index); WINE_TRACE("Loading picture #%d\n", index);
sprintf(tmp, "bm%u", index); sprintf(tmp, "|bm%u", index);
if (!HLPFILE_FindSubFile(tmp, &ref, &end)) {WINE_WARN("no sub file\n"); return FALSE;} if (!HLPFILE_FindSubFile(tmp, &ref, &end)) {WINE_WARN("no sub file\n"); return FALSE;}
...@@ -949,7 +953,7 @@ static BOOL HLPFILE_ReadFont(HLPFILE* hlpfile) ...@@ -949,7 +953,7 @@ static BOOL HLPFILE_ReadFont(HLPFILE* hlpfile)
unsigned face_num, dscr_num, face_offset, dscr_offset; unsigned face_num, dscr_num, face_offset, dscr_offset;
BYTE flag, family; BYTE flag, family;
if (!HLPFILE_FindSubFile("FONT", &ref, &end)) if (!HLPFILE_FindSubFile("|FONT", &ref, &end))
{ {
WINE_WARN("no subfile FONT\n"); WINE_WARN("no subfile FONT\n");
hlpfile->numFonts = 0; hlpfile->numFonts = 0;
...@@ -1055,6 +1059,10 @@ static BOOL HLPFILE_ReadFileToBuffer(HFILE hFile) ...@@ -1055,6 +1059,10 @@ static BOOL HLPFILE_ReadFileToBuffer(HFILE hFile)
if (_hread(hFile, header, 16) != 16) {WINE_WARN("header\n"); return FALSE;}; if (_hread(hFile, header, 16) != 16) {WINE_WARN("header\n"); return FALSE;};
/* sanity checks */
if (GET_UINT(header, 0) != 0x00035F3F)
{WINE_WARN("wrong header\n"); return FALSE;};
size = GET_UINT(header, 12); size = GET_UINT(header, 12);
file_buffer = HeapAlloc(GetProcessHeap(), 0, size + 1); file_buffer = HeapAlloc(GetProcessHeap(), 0, size + 1);
if (!file_buffer) return FALSE; if (!file_buffer) return FALSE;
...@@ -1078,13 +1086,49 @@ static BOOL HLPFILE_FindSubFile(LPCSTR name, BYTE **subbuf, BYTE **subend) ...@@ -1078,13 +1086,49 @@ static BOOL HLPFILE_FindSubFile(LPCSTR name, BYTE **subbuf, BYTE **subend)
{ {
BYTE *root = file_buffer + GET_UINT(file_buffer, 4); BYTE *root = file_buffer + GET_UINT(file_buffer, 4);
BYTE *end = file_buffer + GET_UINT(file_buffer, 12); BYTE *end = file_buffer + GET_UINT(file_buffer, 12);
BYTE *ptr = root + 0x37; BYTE *ptr;
BYTE *bth;
unsigned pgsize;
unsigned pglast;
unsigned nentries;
unsigned i, n;
bth = root + 9;
/* FIXME: this should be using the EnumBTree functions from this file */
pgsize = GET_USHORT(bth, 4);
WINE_TRACE("%s => pgsize=%u #pg=%u rootpg=%u #lvl=%u\n",
name, pgsize, GET_USHORT(bth, 30), GET_USHORT(bth, 26), GET_USHORT(bth, 32));
ptr = bth + 38 + GET_USHORT(bth, 26) * pgsize;
for (n = 1; n < GET_USHORT(bth, 32); n++)
{
nentries = GET_USHORT(ptr, 2);
pglast = GET_USHORT(ptr, 4);
WINE_TRACE("[%u]: #entries=%u next=%u\n", n, nentries, pglast);
while (ptr < end && ptr[0] == 0x7c) ptr += 6;
for (i = 0; i < nentries; i++)
{ {
BYTE *fname = ptr + 1; WINE_TRACE("<= %s\n", ptr);
if (strcmp(name, ptr) < 0) break;
ptr += strlen(ptr) + 1; ptr += strlen(ptr) + 1;
if (!lstrcmpi(fname, name)) pglast = GET_USHORT(ptr, 0);
ptr += 2;
}
ptr = bth + 38 + pglast * pgsize;
}
nentries = GET_USHORT(ptr, 2);
ptr += 8;
for (i = 0; i < nentries; i++)
{
char* fname = ptr;
ptr += strlen(fname) + 1;
WINE_TRACE("\\- %s\n", fname);
if (strcmp(fname, name) == 0)
{ {
*subbuf = file_buffer + GET_UINT(ptr, 0); *subbuf = file_buffer + GET_UINT(ptr, 0);
*subend = *subbuf + GET_UINT(*subbuf, 0); *subend = *subbuf + GET_UINT(*subbuf, 0);
...@@ -1095,8 +1139,9 @@ static BOOL HLPFILE_FindSubFile(LPCSTR name, BYTE **subbuf, BYTE **subend) ...@@ -1095,8 +1139,9 @@ static BOOL HLPFILE_FindSubFile(LPCSTR name, BYTE **subbuf, BYTE **subend)
} }
return TRUE; return TRUE;
} }
else ptr += 4; ptr += 4;
} }
return FALSE; return FALSE;
} }
...@@ -1113,7 +1158,7 @@ static BOOL HLPFILE_SystemCommands(HLPFILE* hlpfile) ...@@ -1113,7 +1158,7 @@ static BOOL HLPFILE_SystemCommands(HLPFILE* hlpfile)
hlpfile->lpszTitle = NULL; hlpfile->lpszTitle = NULL;
if (!HLPFILE_FindSubFile("SYSTEM", &buf, &end)) return FALSE; if (!HLPFILE_FindSubFile("|SYSTEM", &buf, &end)) return FALSE;
magic = GET_USHORT(buf + 9, 0); magic = GET_USHORT(buf + 9, 0);
minor = GET_USHORT(buf + 9, 2); minor = GET_USHORT(buf + 9, 2);
...@@ -1233,7 +1278,7 @@ static BOOL HLPFILE_UncompressLZ77_Phrases(HLPFILE* hlpfile) ...@@ -1233,7 +1278,7 @@ static BOOL HLPFILE_UncompressLZ77_Phrases(HLPFILE* hlpfile)
UINT i, num, dec_size; UINT i, num, dec_size;
BYTE *buf, *end; BYTE *buf, *end;
if (!HLPFILE_FindSubFile("Phrases", &buf, &end)) return FALSE; if (!HLPFILE_FindSubFile("|Phrases", &buf, &end)) return FALSE;
num = phrases.num = GET_USHORT(buf, 9); num = phrases.num = GET_USHORT(buf, 9);
if (buf + 2 * num + 0x13 >= end) {WINE_WARN("1a\n"); return FALSE;}; if (buf + 2 * num + 0x13 >= end) {WINE_WARN("1a\n"); return FALSE;};
...@@ -1266,8 +1311,8 @@ static BOOL HLPFILE_Uncompress_Phrases40(HLPFILE* hlpfile) ...@@ -1266,8 +1311,8 @@ static BOOL HLPFILE_Uncompress_Phrases40(HLPFILE* hlpfile)
long* ptr, mask = 0; long* ptr, mask = 0;
unsigned short bc; unsigned short bc;
if (!HLPFILE_FindSubFile("PhrIndex", &buf_idx, &end_idx) || if (!HLPFILE_FindSubFile("|PhrIndex", &buf_idx, &end_idx) ||
!HLPFILE_FindSubFile("PhrImage", &buf_phs, &end_phs)) return FALSE; !HLPFILE_FindSubFile("|PhrImage", &buf_phs, &end_phs)) return FALSE;
ptr = (long*)(buf_idx + 9 + 28); ptr = (long*)(buf_idx + 9 + 28);
bc = GET_USHORT(buf_idx, 9 + 24) & 0x0F; bc = GET_USHORT(buf_idx, 9 + 24) & 0x0F;
...@@ -1326,7 +1371,7 @@ static BOOL HLPFILE_UncompressLZ77_Topic(HLPFILE* hlpfile) ...@@ -1326,7 +1371,7 @@ static BOOL HLPFILE_UncompressLZ77_Topic(HLPFILE* hlpfile)
BYTE *buf, *ptr, *end, *newptr; BYTE *buf, *ptr, *end, *newptr;
int i, newsize = 0; int i, newsize = 0;
if (!HLPFILE_FindSubFile("TOPIC", &buf, &end)) if (!HLPFILE_FindSubFile("|TOPIC", &buf, &end))
{WINE_WARN("topic0\n"); return FALSE;} {WINE_WARN("topic0\n"); return FALSE;}
if (!(hlpfile->flags & 4)) WINE_FIXME("Unsupported format\n"); if (!(hlpfile->flags & 4)) WINE_FIXME("Unsupported format\n");
...@@ -1572,7 +1617,7 @@ static BOOL HLPFILE_GetContext(HLPFILE *hlpfile) ...@@ -1572,7 +1617,7 @@ static BOOL HLPFILE_GetContext(HLPFILE *hlpfile)
struct myfncb m; struct myfncb m;
unsigned clen; unsigned clen;
if (!HLPFILE_FindSubFile("CONTEXT", &cbuf, &cend)) {WINE_WARN("context0\n"); return FALSE;} if (!HLPFILE_FindSubFile("|CONTEXT", &cbuf, &cend)) {WINE_WARN("context0\n"); return FALSE;}
clen = GET_UINT(cbuf, 0x2b); clen = GET_UINT(cbuf, 0x2b);
hlpfile->Context = HeapAlloc(GetProcessHeap(), 0, clen * sizeof(HLPFILE_CONTEXT)); hlpfile->Context = HeapAlloc(GetProcessHeap(), 0, clen * sizeof(HLPFILE_CONTEXT));
......
...@@ -1088,6 +1088,7 @@ static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize) ...@@ -1088,6 +1088,7 @@ static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize)
if (p->u.image.pos & 0x8000) if (p->u.image.pos & 0x8000)
{ {
space.cx = rect.left; space.cx = rect.left;
if (*line)
space.cy += (*line)->rect.bottom - (*line)->rect.top; space.cy += (*line)->rect.bottom - (*line)->rect.top;
part = 0; part = 0;
} }
...@@ -1096,7 +1097,7 @@ static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize) ...@@ -1096,7 +1097,7 @@ static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize)
bmpSize.cx = dibs.dsBm.bmWidth; bmpSize.cx = dibs.dsBm.bmWidth;
bmpSize.cy = dibs.dsBm.bmHeight; bmpSize.cy = dibs.dsBm.bmHeight;
free_width = rect.right - (part ? (*line)->rect.right : rect.left) - space.cx; free_width = rect.right - ((part && *line) ? (*line)->rect.right : rect.left) - space.cx;
if (free_width <= 0) if (free_width <= 0)
{ {
part = NULL; part = NULL;
...@@ -1153,7 +1154,7 @@ static void WINHELP_DeleteLines(WINHELP_WINDOW *win) ...@@ -1153,7 +1154,7 @@ static void WINHELP_DeleteLines(WINHELP_WINDOW *win)
{ {
WINHELP_LINE *line, *next_line; WINHELP_LINE *line, *next_line;
WINHELP_LINE_PART *part, *next_part; WINHELP_LINE_PART *part, *next_part;
for(line = win->first_line; line; line = next_line) for (line = win->first_line; line; line = next_line)
{ {
next_line = line->next; next_line = line->next;
for (part = &line->first_part; part; part = next_part) for (part = &line->first_part; part; part = next_part)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment