RICHEDIT: RTF import improvements
Krzysztof Foltman
kfoltman at portal.onet.pl
Tue Mar 15 15:34:01 CST 2005
ChangeLog:
* Unknown destinations are now correctly skipped (so loading an RTF
file generated by, for example, OpenOffice doesn't produce lots of
garbage anymore)
* format stack for RTF groups (so that RTF reader can correctly read
what RTF writer wrote :) )
Krzysztof
-------------- next part --------------
Index: reader.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/reader.c,v
retrieving revision 1.5
diff -u -r1.5 reader.c
--- reader.c 15 Mar 2005 19:31:44 -0000 1.5
+++ reader.c 15 Mar 2005 21:28:31 -0000
@@ -3685,7 +3685,7 @@
/*
- * This function notices destinations that should be ignored
+ * This function notices destinations that aren't explicitly handled
* and skips to their ends. This keeps, for instance, picture
* data from being considered as plain text.
*/
@@ -3694,26 +3694,8 @@
Destination (RTF_Info *info)
{
TRACE("\n");
-
- switch (info->rtfMinor)
- {
- case rtfGenerator:
- case rtfPict:
- case rtfFNContSep:
- case rtfFNContNotice:
- case rtfInfo:
- case rtfIndexRange:
- case rtfITitle:
- case rtfISubject:
- case rtfIAuthor:
- case rtfIOperator:
- case rtfIKeywords:
- case rtfIComment:
- case rtfIVersion:
- case rtfIDoccomm:
- RTFSkipGroup (info);
- break;
- }
+ if (!RTFGetDestinationCallback(info, info->rtfMinor))
+ RTFSkipGroup (info);
}
@@ -3730,6 +3712,15 @@
switch (info->rtfMinor)
{
+ case rtfOptDest:
+ /* the next token determines destination, if it's unknown, skip the group */
+ /* this way we filter out the garbage coming from unknown destinations */
+ RTFGetToken(info);
+ if (info->rtfClass != rtfDestination)
+ RTFSkipGroup(info);
+ else
+ RTFRouteToken(info); /* "\*" is ignored with known destinations */
+ break;
case rtfPage:
case rtfSect:
case rtfRow:
Index: rtf.h
===================================================================
RCS file: /home/wine/wine/dlls/riched20/rtf.h,v
retrieving revision 1.3
diff -u -r1.3 rtf.h
--- rtf.h 15 Mar 2005 19:31:44 -0000 1.3
+++ rtf.h 15 Mar 2005 21:28:32 -0000
@@ -1390,6 +1390,9 @@
# define maxCSStack 10
+/* character format stack size */
+
+# define maxCharFormatStack 32
struct _RTF_Info;
typedef struct _RTF_Info RTF_Info;
@@ -1499,6 +1502,9 @@
DWORD dwOutputCount;
char OutputBuffer[0x1000];
+
+ CHARFORMAT2W formatStack[maxCharFormatStack];
+ int formatStackTop;
};
Index: editor.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/editor.c,v
retrieving revision 1.12
diff -u -r1.12 editor.c
--- editor.c 15 Mar 2005 15:40:52 -0000 1.12
+++ editor.c 15 Mar 2005 21:28:32 -0000
@@ -284,9 +284,11 @@
switch(info->rtfMinor)
{
case rtfPlain:
- FIXME("rtfPlain: how plain should it be ?\n");
- fmt.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_COLOR | CFM_BACKCOLOR;
+ /* FIXME add more flags once they're implemented */
+ fmt.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_COLOR | CFM_BACKCOLOR | CFM_SIZE | CFM_WEIGHT;
fmt.dwEffects = CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR;
+ fmt.yHeight = 12*20; /* 12pt */
+ fmt.wWeight = 400;
break;
case rtfBold:
fmt.dwMask = CFM_BOLD;
@@ -385,6 +387,25 @@
void ME_RTFReadHook(RTF_Info *info) {
switch(info->rtfClass)
{
+ case rtfGroup:
+ switch(info->rtfMajor)
+ {
+ case rtfBeginGroup:
+ if (info->formatStackTop < maxCharFormatStack) {
+ info->formatStack[info->formatStackTop].cbSize = sizeof(info->formatStack[0]);
+ SendMessageW(info->hwndEdit, EM_GETCHARFORMAT, 1, (LPARAM)&info->formatStack[info->formatStackTop]);
+ }
+ info->formatStackTop++;
+ break;
+ case rtfEndGroup:
+ RTFFlushOutputBuffer(info);
+ info->formatStackTop--;
+ if (info->formatStackTop < maxCharFormatStack) {
+ SendMessageW(info->hwndEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&info->formatStack[info->formatStackTop]);
+ }
+ break;
+ }
+ break;
case rtfControl:
switch(info->rtfMajor)
{
More information about the wine-patches
mailing list