From 4c9f013f8b50f866172cd6769c8e6bfe214a7bb5 Mon Sep 17 00:00:00 2001 From: Phil Krylov Date: Mon, 22 Aug 2005 10:06:08 +0000 Subject: [PATCH] Added handling of deff RTF control word. --- dlls/riched20/editor.c | 17 +++++++++++------ dlls/riched20/reader.c | 24 ++++++++++++++++++++++++ dlls/riched20/rtf.h | 2 ++ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index c00f77d89e4..7c500f51e7f 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -393,6 +393,7 @@ static void ME_RTFCharAttrHook(RTF_Info *info) style2 = ME_ApplyStyle(info->style, &fmt); ME_ReleaseStyle(info->style); info->style = style2; + info->styleChanged = TRUE; } } @@ -476,18 +477,22 @@ static void ME_RTFReadHook(RTF_Info *info) { info->stack[info->stackTop].unicodeLength = info->unicodeLength; } info->stackTop++; + info->styleChanged = FALSE; break; case rtfEndGroup: { ME_Style *s; RTFFlushOutputBuffer(info); info->stackTop--; - /* FIXME too slow ? how come ? */ - s = ME_ApplyStyle(info->style, &info->stack[info->stackTop].fmt); - ME_ReleaseStyle(info->style); - info->style = s; - info->codePage = info->stack[info->stackTop].codePage; - info->unicodeLength = info->stack[info->stackTop].unicodeLength; + if (info->styleChanged) + { + /* FIXME too slow ? how come ? */ + s = ME_ApplyStyle(info->style, &info->stack[info->stackTop].fmt); + ME_ReleaseStyle(info->style); + info->style = s; + info->codePage = info->stack[info->stackTop].codePage; + info->unicodeLength = info->stack[info->stackTop].unicodeLength; + } break; } } diff --git a/dlls/riched20/reader.c b/dlls/riched20/reader.c index 758e5abc807..d79dac26e14 100644 --- a/dlls/riched20/reader.c +++ b/dlls/riched20/reader.c @@ -257,6 +257,7 @@ void RTFInit(RTF_Info *info) info->ansiCodePage = 1252; /* Latin-1; actually unused */ info->unicodeLength = 1; /* \uc1 is the default */ info->codePage = info->ansiCodePage; + info->defFont = 0; info->rtfClass = -1; info->pushedClass = -1; @@ -1005,6 +1006,14 @@ static void ReadFontTbl(RTF_Info *info) if (!RTFCheckCM (info, rtfGroup, rtfEndGroup)) RTFPanic (info, "%s: missing \"}\"", fn); } + + /* Apply the real properties of the default font */ + if (fp->rtfFNum == info->defFont) + { + if (info->ansiCodePage != CP_UTF8) + info->codePage = fp->rtfFCodePage; + TRACE("default font codepage %d\n", info->codePage); + } } if (fp->rtfFNum == -1) RTFPanic (info,"%s: missing font number", fn); @@ -2467,6 +2476,7 @@ void RTFPanic(RTF_Info *info, const char *fmt, ...) static void TextClass (RTF_Info *info); static void ControlClass (RTF_Info *info); +static void DefFont(RTF_Info *info); static void Destination (RTF_Info *info); static void SpecialChar (RTF_Info *info); static void RTFPutUnicodeChar (RTF_Info *info, int c); @@ -2516,6 +2526,9 @@ ControlClass (RTF_Info *info) case rtfCharSet: CharSet(info); break; + case rtfDefFont: + DefFont(info); + break; case rtfDestination: Destination (info); break; @@ -2542,6 +2555,7 @@ CharAttr(RTF_Info *info) { if (info->ansiCodePage != CP_UTF8) info->codePage = font->rtfFCodePage; + TRACE("font %d codepage %d\n", info->rtfParam, info->codePage); } else RTFMsg(info, "unknown font %d\n", info->rtfParam); @@ -2591,9 +2605,19 @@ Destination (RTF_Info *info) } +static void +DefFont(RTF_Info *info) +{ + TRACE("%d\n", info->rtfParam); + info->defFont = info->rtfParam; +} + + static void DocAttr(RTF_Info *info) { + TRACE("minor %d, param %d\n", info->rtfMinor, info->rtfParam); + switch (info->rtfMinor) { case rtfAnsiCodePage: diff --git a/dlls/riched20/rtf.h b/dlls/riched20/rtf.h index 53ec6eeac21..d3720be01d5 100644 --- a/dlls/riched20/rtf.h +++ b/dlls/riched20/rtf.h @@ -1070,6 +1070,7 @@ struct _RTF_Info { RTFColor *colorList; /* initialized to NULL */ RTFStyle *styleList; int ansiCodePage; /* ANSI codepage used in conversion to Unicode */ + int defFont; /* Character attributes */ int unicodeLength; /* The length of ANSI representation of Unicode characters */ @@ -1103,6 +1104,7 @@ struct _RTF_Info { RTFState stack[maxStack]; int stackTop; + BOOL styleChanged; };