[RICHED20] Sync with Wine Staging 2.9. CORE-13362
[reactos.git] / reactos / dll / win32 / riched20 / writer.c
index 7d2b4b7..607ef6d 100644 (file)
@@ -377,14 +377,6 @@ ME_StreamOutRTFFontAndColorTbl(ME_OutStream *pStream, ME_DisplayItem *pFirstRun,
   if (!ME_StreamOutPrint(pStream, "}\r\n"))
     return FALSE;
 
-  /* It seems like Open Office ignores \deff0 tag at RTF-header.
-     As result it can't correctly parse text before first \fN tag,
-     so we can put \f0 immediately after font table. This forces
-     parser to use the same font, that \deff0 specifies.
-     It makes OOffice happy */
-  if (!ME_StreamOutPrint(pStream, "\\f0"))
-    return FALSE;
-
   /* Output the color table */
   if (!ME_StreamOutPrint(pStream, "{\\colortbl;")) return FALSE; /* first entry is auto-color */
   for (i = 1; i < pStream->nColorTblLen; i++)
@@ -393,7 +385,7 @@ ME_StreamOutRTFFontAndColorTbl(ME_OutStream *pStream, ME_DisplayItem *pFirstRun,
                            (pStream->colortbl[i] >> 8) & 0xFF, (pStream->colortbl[i] >> 16) & 0xFF))
       return FALSE;
   }
-  if (!ME_StreamOutPrint(pStream, "}")) return FALSE;
+  if (!ME_StreamOutPrint(pStream, "}\r\n")) return FALSE;
 
   return TRUE;
 }
@@ -726,8 +718,10 @@ ME_StreamOutRTFParaProps(ME_TextEditor *editor, ME_OutStream *pStream,
       sprintf(props + strlen(props), "\\shading%d", fmt->wShadingWeight);
     if (fmt->wShadingStyle & 0xF)
       strcat(props, style[fmt->wShadingStyle & 0xF]);
-    sprintf(props + strlen(props), "\\cfpat%d\\cbpat%d",
-            (fmt->wShadingStyle >> 4) & 0xF, (fmt->wShadingStyle >> 8) & 0xF);
+    if ((fmt->wShadingStyle >> 4) & 0xf)
+      sprintf(props + strlen(props), "\\cfpat%d", (fmt->wShadingStyle >> 4) & 0xf);
+    if ((fmt->wShadingStyle >> 8) & 0xf)
+      sprintf(props + strlen(props), "\\cbpat%d", (fmt->wShadingStyle >> 8) & 0xf);
   }
   if (*props)
     strcat(props, " ");
@@ -772,14 +766,14 @@ ME_StreamOutRTFCharProps(ME_OutStream *pStream, CHARFORMAT2W *fmt)
   }
 
   if ((old_fmt->dwEffects ^ fmt->dwEffects) & CFE_AUTOBACKCOLOR ||
-      old_fmt->crBackColor != fmt->crBackColor)
+      (!(fmt->dwEffects & CFE_AUTOBACKCOLOR) && old_fmt->crBackColor != fmt->crBackColor))
   {
       if (fmt->dwEffects & CFE_AUTOBACKCOLOR) i = 0;
       else find_color_in_colortbl( pStream, fmt->crBackColor, &i );
       sprintf(props + strlen(props), "\\cb%u", i);
   }
   if ((old_fmt->dwEffects ^ fmt->dwEffects) & CFE_AUTOCOLOR ||
-      old_fmt->crTextColor != fmt->crTextColor)
+      (!(fmt->dwEffects & CFE_AUTOCOLOR) && old_fmt->crTextColor != fmt->crTextColor))
   {
       if (fmt->dwEffects & CFE_AUTOCOLOR) i = 0;
       else find_color_in_colortbl( pStream, fmt->crTextColor, &i );
@@ -1020,7 +1014,7 @@ static BOOL ME_StreamOutRTF(ME_TextEditor *editor, ME_OutStream *pStream,
 
   /* TODO: stylesheet table */
 
-  if (!ME_StreamOutPrint(pStream, "{\\*\\generator Wine Riched20 2.0;}"))
+  if (!ME_StreamOutPrint(pStream, "{\\*\\generator Wine Riched20 2.0;}\r\n"))
     return FALSE;
 
   /* TODO: information group */
@@ -1069,6 +1063,9 @@ static BOOL ME_StreamOutRTF(ME_TextEditor *editor, ME_OutStream *pStream,
       }
       nChars--;
     } else if (cursor.pRun->member.run.nFlags & MERF_ENDPARA) {
+      if (!ME_StreamOutRTFCharProps(pStream, &cursor.pRun->member.run.style->fmt))
+        return FALSE;
+
       if (cursor.pPara->member.para.fmt.dwMask & PFM_TABLE &&
           cursor.pPara->member.para.fmt.wEffects & PFE_TABLE &&
           !(cursor.pPara->member.para.nFlags & (MEPF_ROWSTART|MEPF_ROWEND|MEPF_CELL)))