[PATCH 33/45] [WinHelp]: now generating RTF information for bitmaps
Eric Pouech
eric.pouech at orange.fr
Sun Mar 23 04:20:38 CDT 2008
A+
---
programs/winhelp/hlpfile.c | 138 ++++++++++++++++++++++++--------------------
1 files changed, 75 insertions(+), 63 deletions(-)
diff --git a/programs/winhelp/hlpfile.c b/programs/winhelp/hlpfile.c
index 0add7fe..28f8b8a 100644
--- a/programs/winhelp/hlpfile.c
+++ b/programs/winhelp/hlpfile.c
@@ -631,20 +631,45 @@ static BOOL HLPFILE_RtfAddText(struct RtfData* rd, const char* str)
return HLPFILE_RtfAddRawString(rd, last, p - last);
}
-#if 0
+static BOOL HLPFILE_RtfAddHexBytes(struct RtfData* rd, const void* _ptr, unsigned sz)
+{
+ char tmp[512];
+ unsigned i, step;
+ const BYTE* ptr = _ptr;
+ const char* _2hex = "0123456789abcdef";
+
+ if (!rd->in_text)
+ {
+ if (!HLPFILE_RtfAddRawString(rd, " ", 1)) return FALSE;
+ rd->in_text = TRUE;
+ }
+ for (; sz; sz -= step)
+ {
+ step = min(256, sz);
+ for (i = 0; i < step; i++)
+ {
+ tmp[2 * i + 0] = _2hex[*ptr >> 4];
+ tmp[2 * i + 1] = _2hex[*ptr++ & 0xF];
+ }
+ if (!HLPFILE_RtfAddRawString(rd, tmp, 2 * step)) return FALSE;
+ }
+ return TRUE;
+}
+
/******************************************************************
- * HLPFILE_LoadBitmap
+ * HLPFILE_RtfAddBitmap
*
*
*/
-static BOOL HLPFILE_LoadBitmap(BYTE* beg, BYTE type, BYTE pack,
- HLPFILE_PARAGRAPH* paragraph)
+static BOOL HLPFILE_RtfAddBitmap(struct RtfData* rd, BYTE* beg, BYTE type, BYTE pack)
{
BYTE* ptr;
BYTE* pict_beg;
BITMAPINFO* bi;
unsigned long off, csz;
- HDC hdc;
+ unsigned nc = 0;
+ BOOL ret = FALSE;
+ char tmp[256];
bi = HeapAlloc(GetProcessHeap(), 0, sizeof(*bi));
if (!bi) return FALSE;
@@ -677,9 +702,9 @@ static BOOL HLPFILE_LoadBitmap(BYTE* beg, BYTE type, BYTE pack,
/* now read palette info */
if (type == 0x06)
{
- unsigned nc = bi->bmiHeader.biClrUsed;
unsigned i;
-
+
+ nc = bi->bmiHeader.biClrUsed;
/* not quite right, especially for bitfields type of compression */
if (!nc && bi->bmiHeader.biBitCount <= 8)
nc = 1 << bi->bmiHeader.biBitCount;
@@ -696,27 +721,41 @@ static BOOL HLPFILE_LoadBitmap(BYTE* beg, BYTE type, BYTE pack,
}
}
pict_beg = HLPFILE_DecompressGfx(beg + off, csz, bi->bmiHeader.biSizeImage, pack);
-
- paragraph->u.gfx.u.bmp.hBitmap = CreateDIBitmap(hdc = GetDC(0), &bi->bmiHeader,
- CBM_INIT, pict_beg,
- bi, DIB_RGB_COLORS);
- ReleaseDC(0, hdc);
- if (!paragraph->u.gfx.u.bmp.hBitmap)
- WINE_ERR("Couldn't create bitmap\n");
-
+
+ if (!HLPFILE_RtfAddControl(rd, "{\\pict")) goto done;
+ if (type == 0x06)
+ {
+ sprintf(tmp, "\\dibitmap0\\picw%d\\pich%d",
+ bi->bmiHeader.biWidth, bi->bmiHeader.biHeight);
+ if (!HLPFILE_RtfAddControl(rd, tmp)) goto done;
+ if (!HLPFILE_RtfAddHexBytes(rd, bi, sizeof(*bi) + nc * sizeof(RGBQUAD))) goto done;
+ }
+ else
+ {
+ sprintf(tmp, "\\wbitmap0\\wbmbitspixel%d\\wbmplanes%d\\picw%d\\pich%d",
+ bi->bmiHeader.biBitCount, bi->bmiHeader.biPlanes,
+ bi->bmiHeader.biWidth, bi->bmiHeader.biHeight);
+ if (!HLPFILE_RtfAddControl(rd, tmp)) goto done;
+ }
+ if (!HLPFILE_RtfAddHexBytes(rd, pict_beg, bi->bmiHeader.biSizeImage)) goto done;
+ if (!HLPFILE_RtfAddControl(rd, "}")) goto done;
+
+ ret = TRUE;
+done:
HeapFree(GetProcessHeap(), 0, bi);
if (pict_beg != beg + off) HeapFree(GetProcessHeap(), 0, pict_beg);
- return TRUE;
+ return ret;
}
/******************************************************************
- * HLPFILE_LoadMetaFile
+ * HLPFILE_RtfAddMetaFile
*
*
*/
-static BOOL HLPFILE_LoadMetaFile(BYTE* beg, BYTE pack, HLPFILE_PARAGRAPH* paragraph)
+static BOOL HLPFILE_RtfAddMetaFile(BYTE* beg, BYTE pack)
{
+#if 0
BYTE* ptr;
unsigned long size, csize;
unsigned long off, hsoff;
@@ -755,24 +794,23 @@ static BOOL HLPFILE_LoadMetaFile(BYTE* beg, BYTE pack, HLPFILE_PARAGRAPH* pa
WINE_FIXME("Couldn't load metafile\n");
if (bits != beg + off) HeapFree(GetProcessHeap(), 0, bits);
+#endif
return TRUE;
}
/******************************************************************
- * HLPFILE_LoadGfxByAddr
+ * HLPFILE_RtfAddGfxByAddr
*
*
*/
-static BOOL HLPFILE_LoadGfxByAddr(HLPFILE *hlpfile, BYTE* ref,
- unsigned long size,
- HLPFILE_PARAGRAPH* paragraph)
+static BOOL HLPFILE_RtfAddGfxByAddr(struct RtfData* rd, HLPFILE *hlpfile,
+ BYTE* ref, unsigned long size)
{
unsigned i, numpict;
numpict = GET_USHORT(ref, 2);
- WINE_TRACE("Got picture magic=%04x #=%d\n",
- GET_USHORT(ref, 0), numpict);
+ WINE_TRACE("Got picture magic=%04x #=%d\n", GET_USHORT(ref, 0), numpict);
for (i = 0; i < numpict; i++)
{
@@ -790,10 +828,10 @@ static BOOL HLPFILE_LoadGfxByAddr(HLPFILE *hlpfile, BYTE* ref,
{
case 5: /* device dependent bmp */
case 6: /* device independent bmp */
- HLPFILE_LoadBitmap(beg, type, pack, paragraph);
+ HLPFILE_RtfAddBitmap(rd, beg, type, pack);
break;
- case 8:
- HLPFILE_LoadMetaFile(beg, pack, paragraph);
+ case 8:
+ HLPFILE_RtfAddMetaFile(beg, pack);
break;
default: WINE_FIXME("Unknown type %u\n", type); return FALSE;
}
@@ -808,12 +846,11 @@ static BOOL HLPFILE_LoadGfxByAddr(HLPFILE *hlpfile, BYTE* ref,
}
/******************************************************************
- * HLPFILE_LoadGfxByIndex
+ * HLPFILE_RtfAddGfxByIndex
*
*
*/
-static BOOL HLPFILE_LoadGfxByIndex(HLPFILE *hlpfile, unsigned index,
- HLPFILE_PARAGRAPH* paragraph)
+static BOOL HLPFILE_RtfAddGfxByIndex(struct RtfData* rd, HLPFILE *hlpfile, unsigned index)
{
char tmp[16];
BYTE *ref, *end;
@@ -821,39 +858,16 @@ static BOOL HLPFILE_LoadGfxByIndex(HLPFILE *hlpfile, unsigned index,
WINE_TRACE("Loading picture #%d\n", index);
- if (index < hlpfile->numBmps && hlpfile->bmps[index] != NULL)
- {
- paragraph->u.gfx.u.bmp.hBitmap = hlpfile->bmps[index];
- return TRUE;
- }
-
sprintf(tmp, "|bm%u", index);
if (!HLPFILE_FindSubFile(hlpfile, tmp, &ref, &end)) {WINE_WARN("no sub file\n"); return FALSE;}
ref += 9;
- ret = HLPFILE_LoadGfxByAddr(hlpfile, ref, end - ref, paragraph);
-
- /* cache bitmap */
- if (ret && paragraph->cookie == para_bitmap)
- {
- if (index >= hlpfile->numBmps)
- {
- hlpfile->numBmps = index + 1;
- if (hlpfile->bmps)
- hlpfile->bmps = HeapReAlloc(GetProcessHeap(), 0, hlpfile->bmps,
- hlpfile->numBmps * sizeof(hlpfile->bmps[0]));
- else
- hlpfile->bmps = HeapAlloc(GetProcessHeap(), 0,
- hlpfile->numBmps * sizeof(hlpfile->bmps[0]));
+ ret = HLPFILE_RtfAddGfxByAddr(rd, hlpfile, ref, end - ref);
- }
- hlpfile->bmps[index] = paragraph->u.gfx.u.bmp.hBitmap;
- }
return ret;
}
-#endif
/***********************************************************************
*
@@ -1164,10 +1178,10 @@ BOOL HLPFILE_BrowseParagraph(HLPFILE *hlpfile, struct RtfData* rd, BYTE *buf, BY
case 0x87:
case 0x88:
{
- BYTE pos = (*format - 0x86);
BYTE type = format[1];
long size;
+ /* FIXME: we don't position this element (86=center, 87=left, 88=right) */
format += 2;
size = fetch_long(&format);
@@ -1177,25 +1191,23 @@ BOOL HLPFILE_BrowseParagraph(HLPFILE *hlpfile, struct RtfData* rd, BYTE *buf, BY
fetch_ushort(&format); /* hot spot */
/* fall thru */
case 0x03:
-#if 0
switch (GET_SHORT(format, 0))
{
case 0:
- HLPFILE_LoadGfxByIndex(hlpfile, GET_SHORT(format, 2),
- paragraph);
+ HLPFILE_RtfAddGfxByIndex(rd, hlpfile, GET_SHORT(format, 2));
+ rd->char_pos++;
break;
case 1:
- WINE_FIXME("does it work ??? %x<%lu>#%u\n",
- GET_SHORT(format, 0),
+ WINE_FIXME("does it work ??? %x<%lu>#%u\n",
+ GET_SHORT(format, 0),
size, GET_SHORT(format, 2));
- HLPFILE_LoadGfxByAddr(hlpfile, format + 2, size - 4,
- paragraph);
+ HLPFILE_RtfAddGfxByAddr(rd, hlpfile, format + 2, size - 4);
+ rd->char_pos++;
break;
default:
WINE_FIXME("??? %u\n", GET_SHORT(format, 0));
break;
}
-#endif
break;
case 0x05:
WINE_FIXME("Got an embedded element %s\n", format + 6);
More information about the wine-patches
mailing list