[PATCH 36/45] [WinHelp]: added support for multi-columns RTF output

Eric Pouech eric.pouech at orange.fr
Sun Mar 23 04:21:04 CDT 2008




A+
---

 programs/winhelp/hlpfile.c |   62 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 59 insertions(+), 3 deletions(-)


diff --git a/programs/winhelp/hlpfile.c b/programs/winhelp/hlpfile.c
index af10b6a..01bbc94 100644
--- a/programs/winhelp/hlpfile.c
+++ b/programs/winhelp/hlpfile.c
@@ -944,6 +944,7 @@ BOOL HLPFILE_BrowseParagraph(HLPFILE *hlpfile, struct RtfData* rd, BYTE *buf, BY
     unsigned           nc, ncol = 1;
     char               tmp[256];
     BOOL               ret = FALSE;
+    short              table_width;
     BOOL               in_table = FALSE;
 
     if (buf + 0x19 > end) {WINE_WARN("header too small\n"); return FALSE;};
@@ -985,21 +986,59 @@ BOOL HLPFILE_BrowseParagraph(HLPFILE *hlpfile, struct RtfData* rd, BYTE *buf, BY
         in_table = TRUE;
         ncol = *format++;
 
-        WINE_TRACE("#cols %u\n", ncol);
+        if (!HLPFILE_RtfAddControl(rd, "\\trowd")) goto done;
         type = *format++;
         if (type == 0 || type == 2)
+        {
+            table_width = GET_SHORT(format, 0);
             format += 2;
-        format += ncol * 4;
+        }
+        else
+            table_width = 32767;
+        WINE_TRACE("New table: cols=%d type=%x width=%d\n",
+                   ncol, type, table_width);
+        if (ncol > 1)
+        {
+            int     pos;
+            sprintf(tmp, "\\trgaph%d\\trleft%d",
+                    HLPFILE_HalfPointsToTwips(MulDiv(GET_SHORT(format, 6), table_width, 32767)),
+                    HLPFILE_HalfPointsToTwips(MulDiv(GET_SHORT(format, 0), table_width, 32767)));
+            if (!HLPFILE_RtfAddControl(rd, tmp)) goto done;
+            pos = HLPFILE_HalfPointsToTwips(MulDiv(GET_SHORT(format, 6) / 2, table_width, 32767));
+            for (nc = 0; nc < ncol; nc++)
+            {
+                WINE_TRACE("column(%d/%d) gap=%d width=%d\n",
+                           nc, ncol, GET_SHORT(format, nc*4),
+                           GET_SHORT(format, nc*4+2));
+                pos += GET_SHORT(format, nc * 4) + GET_SHORT(format, nc * 4 + 2);
+                sprintf(tmp, "\\cellx%d",
+                        HLPFILE_HalfPointsToTwips(MulDiv(pos, table_width, 32767)));
+                if (!HLPFILE_RtfAddControl(rd, tmp)) goto done;
+            }
+        }
+        else
+        {
+            WINE_TRACE("column(0/%d) gap=%d width=%d\n",
+                       ncol, GET_SHORT(format, 0), GET_SHORT(format, 2));
+            sprintf(tmp, "\\trleft%d\\cellx%d ",
+                    HLPFILE_HalfPointsToTwips(MulDiv(GET_SHORT(format, 0), table_width, 32767)),
+                    HLPFILE_HalfPointsToTwips(MulDiv(GET_SHORT(format, 0) + GET_SHORT(format, 2),
+                                      table_width, 32767)));
+            if (!HLPFILE_RtfAddControl(rd, tmp)) goto done;
+        }
+        format += 4 * ncol;
     }
 
     for (nc = 0; nc < ncol; /**/)
     {
         WINE_TRACE("looking for format at offset %u in column %d\n", format - (buf + 0x15), nc);
+        HLPFILE_RtfAddControl(rd, "\\pard");
         if (in_table)
         {
             nc = GET_SHORT(format, 0);
             if (nc == -1) break;
             format += 5;
+            HLPFILE_RtfAddControl(rd, "\\intbl");
         }
         else nc++;
         format += 4;
@@ -1156,7 +1195,18 @@ BOOL HLPFILE_BrowseParagraph(HLPFILE *hlpfile, struct RtfData* rd, BYTE *buf, BY
                 break;
 
 	    case 0x82:
-                if (!HLPFILE_RtfAddControl(rd, "\\par\\pard")) goto done;
+                if (in_table)
+                {
+                    if (format[1] != 0xFF)
+                    {
+                        if (!HLPFILE_RtfAddControl(rd, "\\par\\intbl")) goto done;
+                    }
+                    else
+                    {
+                        if (!HLPFILE_RtfAddControl(rd, "\\cell\\pard\\intbl")) goto done;
+                    }
+                }
+                else if (!HLPFILE_RtfAddControl(rd, "\\par")) goto done;
                 format += 1;
                 rd->char_pos++;
                 break;
@@ -1309,8 +1359,14 @@ BOOL HLPFILE_BrowseParagraph(HLPFILE *hlpfile, struct RtfData* rd, BYTE *buf, BY
 	    }
 	}
     }
+    if (in_table)
+    {
+        if (!HLPFILE_RtfAddControl(rd, "\\row\\par\\pard\\plain")) goto done;
+        rd->char_pos += 2;
+    }
     ret = TRUE;
 done:
+
     HeapFree(GetProcessHeap(), 0, text_base);
     return ret;
 }





More information about the wine-patches mailing list