RTFDestroyAttrs(info);
- info->ansiCodePage = 1252; /* Latin-1 */
-
+ info->ansiCodePage = 1252; /* Latin-1; actually unused */
info->unicodeLength = 1; /* \uc1 is the default */
info->codePage = info->ansiCodePage;
}
-static int
+int
RTFCharSetToCodePage(RTF_Info *info, int charset)
{
switch (charset)
{
case ANSI_CHARSET:
+ return 1252;
case DEFAULT_CHARSET:
- return info->ansiCodePage;
+ return CP_ACP;
case SYMBOL_CHARSET:
return CP_SYMBOL;
case MAC_CHARSET:
/* FIXME: TranslateCharsetInfo does not work as good as it
* should, so let's use it only when all else fails */
if (!TranslateCharsetInfo(&n, &csi, TCI_SRCCHARSET))
- RTFMsg(info,"%s: unknown charset %u\n", __FUNCTION__, charset);
+ RTFMsg(info, "%s: unknown charset %u\n", __FUNCTION__, charset);
else
return csi.ciACP;
}
fp->rtfFAltName = NULL;
fp->rtfFNum = -1;
fp->rtfFFamily = 0;
- fp->rtfFCharSet = 0;
+ fp->rtfFCharSet = DEFAULT_CHARSET; /* 1 */
fp->rtfFPitch = 0;
fp->rtfFType = 0;
- fp->rtfFCodePage = 0;
+ fp->rtfFCodePage = CP_ACP;
while (info->rtfClass != rtfEOF
&& !RTFCheckCM (info, rtfText, ';')
/* ---------------------------------------------------------------------- */
/*
- * Print message. Default is to send message to stderr
- * but this may be overridden with RTFSetMsgProc().
+ * Print message.
*
- * Message should include linefeeds as necessary. If the default
- * function is overridden, the overriding function may want to
- * map linefeeds to another line ending character or sequence if
- * the host system doesn't use linefeeds.
+ * Message should include linefeeds as necessary.
*/
case rtfFontNum:
font = RTFGetFont(info, info->rtfParam);
if (font)
- info->codePage = font->rtfFCodePage;
+ {
+ if (info->ansiCodePage != CP_UTF8)
+ info->codePage = font->rtfFCodePage;
+ }
else
RTFMsg(info, "unknown font %d\n", info->rtfParam);
break;
*/
#include "editor.h"
+#include "rtf.h"
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
}
} else {
cCharSet = "ansi";
+ /* TODO: If the original document contained an \ansicpg value, retain it.
+ * Otherwise, M$ richedit emits a codepage number determined from the
+ * charset of the default font here. Anyway, this value is not used by
+ * the reader... */
nCodePage = GetACP();
}
if (nCodePage == CP_UTF8)
if (!success)
return FALSE;
- editor->pStream->nCodePage = nCodePage;
+ editor->pStream->nDefaultCodePage = nCodePage;
/* FIXME: This should be a document property */
/* TODO: handle SFF_PLAINRTF */
if (fmt->dwMask & CFM_FACE) {
WCHAR *face = fmt->szFaceName;
- BYTE bCharSet = fmt->bCharSet;
+ BYTE bCharSet = (fmt->dwMask & CFM_CHARSET) ? fmt->bCharSet : DEFAULT_CHARSET;
for (i = 0; i < editor->pStream->nFontTblLen; i++)
if (table[i].bCharSet == bCharSet
return FALSE;
for (i = 0; i < editor->pStream->nFontTblLen; i++) {
- if (table[i].bCharSet) {
+ if (table[i].bCharSet != DEFAULT_CHARSET) {
if (!ME_StreamOutPrint(editor, "{\\f%u\\fcharset%u ", i, table[i].bCharSet))
return FALSE;
} else {
break;
}
if (i < editor->pStream->nFontTblLen && i != editor->pStream->nDefaultFont)
+ {
sprintf(props + strlen(props), "\\f%u", i);
+
+ /* In UTF-8 mode, charsets/codepages are not used */
+ if (editor->pStream->nDefaultCodePage != CP_UTF8)
+ {
+ if (editor->pStream->fonttbl[i].bCharSet == DEFAULT_CHARSET)
+ editor->pStream->nCodePage = editor->pStream->nDefaultCodePage;
+ else
+ editor->pStream->nCodePage = RTFCharSetToCodePage(NULL,
+ editor->pStream->fonttbl[i].bCharSet);
+ }
+ }
}
if (*props)
strcat(props, " ");
nChars = lstrlenW(text);
while (nChars) {
- if (editor->pStream->nCodePage == CP_UTF8) {
+ /* In UTF-8 mode, font charsets are not used. */
+ if (editor->pStream->nDefaultCodePage == CP_UTF8) {
/* 6 is the maximum character length in UTF-8 */
fit = min(nChars, STREAMOUT_BUFFER_SIZE / 6);
WideCharToMultiByte(CP_UTF8, 0, text, fit, buffer, STREAMOUT_BUFFER_SIZE,
nChars--;
} else {
BOOL unknown;
- BYTE letter[2];
+ BYTE letter[3];
+ int nBytes, i;
- WideCharToMultiByte(editor->pStream->nCodePage, 0, text, 1, letter, 2,
- NULL, &unknown);
+ nBytes = WideCharToMultiByte(editor->pStream->nCodePage, 0, text, 1,
+ letter, 3, NULL, &unknown);
if (unknown)
pos += sprintf(buffer + pos, "\\u%d?", (int)*text);
else if (*letter < 128) {
if (*letter == '{' || *letter == '}' || *letter == '\\')
buffer[pos++] = '\\';
buffer[pos++] = *letter;
- } else
- pos += sprintf(buffer + pos, "\\'%02x", *letter);
+ } else {
+ for (i = 0; i < nBytes; i++)
+ pos += sprintf(buffer + pos, "\\'%02x", letter[i]);
+ }
text++;
nChars--;
}
- if (pos >= STREAMOUT_BUFFER_SIZE - 10) {
+ if (pos >= STREAMOUT_BUFFER_SIZE - 11) {
if (!ME_StreamOutMove(editor, buffer, pos))
return FALSE;
pos = 0;