2005-03-14 22:41:16 +01:00
|
|
|
/*
|
|
|
|
* RichEdit - RTF writer module
|
|
|
|
*
|
|
|
|
* Copyright 2005 by Phil Krylov
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-14 22:41:16 +01:00
|
|
|
*/
|
|
|
|
|
2008-02-01 07:29:44 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2005-03-14 22:41:16 +01:00
|
|
|
#include "editor.h"
|
2005-03-22 17:41:36 +01:00
|
|
|
#include "rtf.h"
|
2005-03-14 22:41:16 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
|
|
|
|
|
|
|
|
|
2005-03-16 21:18:11 +01:00
|
|
|
static BOOL
|
2007-08-16 22:57:12 +02:00
|
|
|
ME_StreamOutRTFText(ME_OutStream *pStream, const WCHAR *text, LONG nChars);
|
2005-03-16 21:18:11 +01:00
|
|
|
|
|
|
|
|
2006-02-05 13:05:45 +01:00
|
|
|
static ME_OutStream*
|
2005-03-14 22:41:16 +01:00
|
|
|
ME_StreamOutInit(ME_TextEditor *editor, EDITSTREAM *stream)
|
|
|
|
{
|
2006-02-05 13:05:45 +01:00
|
|
|
ME_OutStream *pStream = ALLOC_OBJ(ME_OutStream);
|
|
|
|
pStream->stream = stream;
|
|
|
|
pStream->stream->dwError = 0;
|
|
|
|
pStream->pos = 0;
|
|
|
|
pStream->written = 0;
|
|
|
|
pStream->nFontTblLen = 0;
|
|
|
|
pStream->nColorTblLen = 1;
|
2008-08-07 18:31:41 +02:00
|
|
|
pStream->nNestingLevel = 0;
|
2006-02-05 13:05:45 +01:00
|
|
|
return pStream;
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL
|
2006-02-05 13:05:45 +01:00
|
|
|
ME_StreamOutFlush(ME_OutStream *pStream)
|
2005-03-14 22:41:16 +01:00
|
|
|
{
|
|
|
|
LONG nWritten = 0;
|
2006-02-05 13:05:45 +01:00
|
|
|
EDITSTREAM *stream = pStream->stream;
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2015-03-17 10:39:38 +01:00
|
|
|
if (pStream->pos) {
|
|
|
|
TRACE("sending %u bytes\n", pStream->pos);
|
|
|
|
nWritten = pStream->pos;
|
|
|
|
stream->dwError = stream->pfnCallback(stream->dwCookie, (LPBYTE)pStream->buffer,
|
|
|
|
pStream->pos, &nWritten);
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("error=%u written=%u\n", stream->dwError, nWritten);
|
2005-03-14 22:41:16 +01:00
|
|
|
if (nWritten == 0 || stream->dwError)
|
|
|
|
return FALSE;
|
2015-03-17 10:39:38 +01:00
|
|
|
/* Don't resend partial chunks if nWritten < pStream->pos */
|
2011-02-09 18:49:37 +01:00
|
|
|
}
|
2006-02-05 13:05:45 +01:00
|
|
|
pStream->pos = 0;
|
2005-03-14 22:41:16 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static LONG
|
2006-02-05 13:05:45 +01:00
|
|
|
ME_StreamOutFree(ME_OutStream *pStream)
|
2005-03-14 22:41:16 +01:00
|
|
|
{
|
2006-02-05 13:05:45 +01:00
|
|
|
LONG written = pStream->written;
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("total length = %u\n", written);
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2006-02-05 13:05:45 +01:00
|
|
|
FREE_OBJ(pStream);
|
2005-03-14 22:41:16 +01:00
|
|
|
return written;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL
|
2006-02-05 13:05:45 +01:00
|
|
|
ME_StreamOutMove(ME_OutStream *pStream, const char *buffer, int len)
|
2005-03-14 22:41:16 +01:00
|
|
|
{
|
|
|
|
while (len) {
|
|
|
|
int space = STREAMOUT_BUFFER_SIZE - pStream->pos;
|
|
|
|
int fit = min(space, len);
|
|
|
|
|
2007-09-16 04:32:20 +02:00
|
|
|
TRACE("%u:%u:%s\n", pStream->pos, fit, debugstr_an(buffer,fit));
|
2005-03-14 22:41:16 +01:00
|
|
|
memmove(pStream->buffer + pStream->pos, buffer, fit);
|
|
|
|
len -= fit;
|
|
|
|
buffer += fit;
|
|
|
|
pStream->pos += fit;
|
|
|
|
if (pStream->pos == STREAMOUT_BUFFER_SIZE) {
|
2006-02-05 13:05:45 +01:00
|
|
|
if (!ME_StreamOutFlush(pStream))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL
|
2006-02-05 13:05:45 +01:00
|
|
|
ME_StreamOutPrint(ME_OutStream *pStream, const char *format, ...)
|
2005-03-14 22:41:16 +01:00
|
|
|
{
|
|
|
|
char string[STREAMOUT_BUFFER_SIZE]; /* This is going to be enough */
|
|
|
|
int len;
|
|
|
|
va_list valist;
|
|
|
|
|
|
|
|
va_start(valist, format);
|
|
|
|
len = vsnprintf(string, sizeof(string), format, valist);
|
|
|
|
va_end(valist);
|
|
|
|
|
2006-02-05 13:05:45 +01:00
|
|
|
return ME_StreamOutMove(pStream, string, len);
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL
|
2006-02-05 13:05:45 +01:00
|
|
|
ME_StreamOutRTFHeader(ME_OutStream *pStream, int dwFormat)
|
2005-03-14 22:41:16 +01:00
|
|
|
{
|
2005-07-21 13:59:11 +02:00
|
|
|
const char *cCharSet = NULL;
|
2005-03-14 22:41:16 +01:00
|
|
|
UINT nCodePage;
|
|
|
|
LANGID language;
|
|
|
|
BOOL success;
|
|
|
|
|
|
|
|
if (dwFormat & SF_USECODEPAGE) {
|
|
|
|
CPINFOEXW info;
|
|
|
|
|
|
|
|
switch (HIWORD(dwFormat)) {
|
|
|
|
case CP_ACP:
|
|
|
|
cCharSet = "ansi";
|
|
|
|
nCodePage = GetACP();
|
|
|
|
break;
|
|
|
|
case CP_OEMCP:
|
|
|
|
nCodePage = GetOEMCP();
|
|
|
|
if (nCodePage == 437)
|
|
|
|
cCharSet = "pc";
|
|
|
|
else if (nCodePage == 850)
|
|
|
|
cCharSet = "pca";
|
|
|
|
else
|
|
|
|
cCharSet = "ansi";
|
|
|
|
break;
|
|
|
|
case CP_UTF8:
|
|
|
|
nCodePage = CP_UTF8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (HIWORD(dwFormat) == CP_MACCP) {
|
|
|
|
cCharSet = "mac";
|
|
|
|
nCodePage = 10000; /* MacRoman */
|
|
|
|
} else {
|
|
|
|
cCharSet = "ansi";
|
|
|
|
nCodePage = 1252; /* Latin-1 */
|
|
|
|
}
|
|
|
|
if (GetCPInfoExW(HIWORD(dwFormat), 0, &info))
|
|
|
|
nCodePage = info.CodePage;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cCharSet = "ansi";
|
2005-03-22 17:41:36 +01:00
|
|
|
/* 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... */
|
2005-03-14 22:41:16 +01:00
|
|
|
nCodePage = GetACP();
|
|
|
|
}
|
|
|
|
if (nCodePage == CP_UTF8)
|
2006-02-05 13:05:45 +01:00
|
|
|
success = ME_StreamOutPrint(pStream, "{\\urtf");
|
2005-03-14 22:41:16 +01:00
|
|
|
else
|
2006-02-05 13:05:45 +01:00
|
|
|
success = ME_StreamOutPrint(pStream, "{\\rtf1\\%s\\ansicpg%u\\uc1", cCharSet, nCodePage);
|
2005-03-14 22:41:16 +01:00
|
|
|
|
|
|
|
if (!success)
|
|
|
|
return FALSE;
|
|
|
|
|
2006-02-05 13:05:45 +01:00
|
|
|
pStream->nDefaultCodePage = nCodePage;
|
2005-03-14 22:41:16 +01:00
|
|
|
|
|
|
|
/* FIXME: This should be a document property */
|
|
|
|
/* TODO: handle SFF_PLAINRTF */
|
|
|
|
language = GetUserDefaultLangID();
|
2006-02-05 13:05:45 +01:00
|
|
|
if (!ME_StreamOutPrint(pStream, "\\deff0\\deflang%u\\deflangfe%u", language, language))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* FIXME: This should be a document property */
|
2006-02-05 13:05:45 +01:00
|
|
|
pStream->nDefaultFont = 0;
|
2005-03-14 22:41:16 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL
|
2008-09-30 23:11:49 +02:00
|
|
|
ME_StreamOutRTFFontAndColorTbl(ME_OutStream *pStream, ME_DisplayItem *pFirstRun,
|
|
|
|
ME_DisplayItem *pLastRun)
|
2005-03-14 22:41:16 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *item = pFirstRun;
|
2006-02-05 13:05:45 +01:00
|
|
|
ME_FontTableItem *table = pStream->fonttbl;
|
2008-11-05 21:48:37 +01:00
|
|
|
unsigned int i;
|
2008-09-30 23:11:49 +02:00
|
|
|
ME_DisplayItem *pLastPara = ME_GetParagraph(pLastRun);
|
|
|
|
ME_DisplayItem *pCell = NULL;
|
2005-03-14 22:41:16 +01:00
|
|
|
|
|
|
|
do {
|
|
|
|
CHARFORMAT2W *fmt = &item->member.run.style->fmt;
|
|
|
|
COLORREF crColor;
|
|
|
|
|
|
|
|
if (fmt->dwMask & CFM_FACE) {
|
|
|
|
WCHAR *face = fmt->szFaceName;
|
2005-03-22 17:41:36 +01:00
|
|
|
BYTE bCharSet = (fmt->dwMask & CFM_CHARSET) ? fmt->bCharSet : DEFAULT_CHARSET;
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2006-02-05 13:05:45 +01:00
|
|
|
for (i = 0; i < pStream->nFontTblLen; i++)
|
2005-03-14 22:41:16 +01:00
|
|
|
if (table[i].bCharSet == bCharSet
|
|
|
|
&& (table[i].szFaceName == face || !lstrcmpW(table[i].szFaceName, face)))
|
|
|
|
break;
|
2008-09-30 23:11:29 +02:00
|
|
|
if (i == pStream->nFontTblLen && i < STREAMOUT_FONTTBL_SIZE) {
|
2005-03-14 22:41:16 +01:00
|
|
|
table[i].bCharSet = bCharSet;
|
|
|
|
table[i].szFaceName = face;
|
2006-02-05 13:05:45 +01:00
|
|
|
pStream->nFontTblLen++;
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fmt->dwMask & CFM_COLOR && !(fmt->dwEffects & CFE_AUTOCOLOR)) {
|
|
|
|
crColor = fmt->crTextColor;
|
2006-02-05 13:05:45 +01:00
|
|
|
for (i = 1; i < pStream->nColorTblLen; i++)
|
|
|
|
if (pStream->colortbl[i] == crColor)
|
2005-03-14 22:41:16 +01:00
|
|
|
break;
|
2008-09-30 23:11:29 +02:00
|
|
|
if (i == pStream->nColorTblLen && i < STREAMOUT_COLORTBL_SIZE) {
|
2006-02-05 13:05:45 +01:00
|
|
|
pStream->colortbl[i] = crColor;
|
|
|
|
pStream->nColorTblLen++;
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fmt->dwMask & CFM_BACKCOLOR && !(fmt->dwEffects & CFE_AUTOBACKCOLOR)) {
|
|
|
|
crColor = fmt->crBackColor;
|
2006-02-05 13:05:45 +01:00
|
|
|
for (i = 1; i < pStream->nColorTblLen; i++)
|
|
|
|
if (pStream->colortbl[i] == crColor)
|
2005-03-14 22:41:16 +01:00
|
|
|
break;
|
2008-09-30 23:11:29 +02:00
|
|
|
if (i == pStream->nColorTblLen && i < STREAMOUT_COLORTBL_SIZE) {
|
2006-02-05 13:05:45 +01:00
|
|
|
pStream->colortbl[i] = crColor;
|
|
|
|
pStream->nColorTblLen++;
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item == pLastRun)
|
|
|
|
break;
|
|
|
|
item = ME_FindItemFwd(item, diRun);
|
|
|
|
} while (item);
|
2008-09-30 23:11:49 +02:00
|
|
|
item = ME_GetParagraph(pFirstRun);
|
|
|
|
do {
|
2012-11-03 17:25:52 +01:00
|
|
|
if ((pCell = item->member.para.pCell))
|
2008-09-30 23:11:49 +02:00
|
|
|
{
|
|
|
|
ME_Border* borders[4] = { &pCell->member.cell.border.top,
|
|
|
|
&pCell->member.cell.border.left,
|
|
|
|
&pCell->member.cell.border.bottom,
|
|
|
|
&pCell->member.cell.border.right };
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (borders[i]->width > 0)
|
|
|
|
{
|
2008-11-05 21:48:37 +01:00
|
|
|
unsigned int j;
|
2008-09-30 23:11:49 +02:00
|
|
|
COLORREF crColor = borders[i]->colorRef;
|
|
|
|
for (j = 1; j < pStream->nColorTblLen; j++)
|
|
|
|
if (pStream->colortbl[j] == crColor)
|
|
|
|
break;
|
|
|
|
if (j == pStream->nColorTblLen && j < STREAMOUT_COLORTBL_SIZE) {
|
|
|
|
pStream->colortbl[j] = crColor;
|
|
|
|
pStream->nColorTblLen++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (item == pLastPara)
|
|
|
|
break;
|
|
|
|
item = item->member.para.next_para;
|
|
|
|
} while (item);
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2006-02-05 13:05:45 +01:00
|
|
|
if (!ME_StreamOutPrint(pStream, "{\\fonttbl"))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2006-02-05 13:05:45 +01:00
|
|
|
for (i = 0; i < pStream->nFontTblLen; i++) {
|
2005-03-22 17:41:36 +01:00
|
|
|
if (table[i].bCharSet != DEFAULT_CHARSET) {
|
2006-02-05 13:05:45 +01:00
|
|
|
if (!ME_StreamOutPrint(pStream, "{\\f%u\\fcharset%u ", i, table[i].bCharSet))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
} else {
|
2006-02-05 13:05:45 +01:00
|
|
|
if (!ME_StreamOutPrint(pStream, "{\\f%u ", i))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2006-02-05 13:05:45 +01:00
|
|
|
if (!ME_StreamOutRTFText(pStream, table[i].szFaceName, -1))
|
2005-03-16 21:18:11 +01:00
|
|
|
return FALSE;
|
2009-04-25 19:56:11 +02:00
|
|
|
if (!ME_StreamOutPrint(pStream, ";}"))
|
2005-03-16 21:18:11 +01:00
|
|
|
return FALSE;
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
2009-04-25 19:56:11 +02:00
|
|
|
if (!ME_StreamOutPrint(pStream, "}\r\n"))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2013-04-30 08:06:06 +02:00
|
|
|
/* 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;
|
|
|
|
|
2013-03-25 12:05:56 +01:00
|
|
|
/* Output the color table */
|
|
|
|
if (!ME_StreamOutPrint(pStream, "{\\colortbl;")) return FALSE; /* first entry is auto-color */
|
|
|
|
for (i = 1; i < pStream->nColorTblLen; i++)
|
|
|
|
{
|
|
|
|
if (!ME_StreamOutPrint(pStream, "\\red%u\\green%u\\blue%u;", pStream->colortbl[i] & 0xFF,
|
|
|
|
(pStream->colortbl[i] >> 8) & 0xFF, (pStream->colortbl[i] >> 16) & 0xFF))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-03-25 12:05:56 +01:00
|
|
|
if (!ME_StreamOutPrint(pStream, "}")) return FALSE;
|
2005-03-14 22:41:16 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL
|
2008-08-07 18:31:41 +02:00
|
|
|
ME_StreamOutRTFTableProps(ME_TextEditor *editor, ME_OutStream *pStream,
|
2008-09-30 23:11:41 +02:00
|
|
|
ME_DisplayItem *para)
|
2005-03-14 22:41:16 +01:00
|
|
|
{
|
2008-08-07 18:31:41 +02:00
|
|
|
ME_DisplayItem *cell;
|
2005-03-16 21:18:11 +01:00
|
|
|
char props[STREAMOUT_BUFFER_SIZE] = "";
|
2008-09-30 23:11:49 +02:00
|
|
|
int i;
|
|
|
|
const char sideChar[4] = {'t','l','b','r'};
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2008-08-05 01:18:54 +02:00
|
|
|
if (!ME_StreamOutPrint(pStream, "\\trowd"))
|
|
|
|
return FALSE;
|
2008-08-07 18:31:41 +02:00
|
|
|
if (!editor->bEmulateVersion10) { /* v4.1 */
|
2008-09-30 23:11:49 +02:00
|
|
|
PARAFORMAT2 *pFmt = ME_GetTableRowEnd(para)->member.para.pFmt;
|
2008-09-30 23:11:41 +02:00
|
|
|
para = ME_GetTableRowStart(para);
|
2008-08-07 18:31:41 +02:00
|
|
|
cell = para->member.para.next_para->member.para.pCell;
|
|
|
|
assert(cell);
|
2008-09-30 23:11:49 +02:00
|
|
|
if (pFmt->dxOffset)
|
|
|
|
sprintf(props + strlen(props), "\\trgaph%d", pFmt->dxOffset);
|
|
|
|
if (pFmt->dxStartIndent)
|
|
|
|
sprintf(props + strlen(props), "\\trleft%d", pFmt->dxStartIndent);
|
2008-08-07 18:31:41 +02:00
|
|
|
do {
|
2008-09-30 23:11:49 +02:00
|
|
|
ME_Border* borders[4] = { &cell->member.cell.border.top,
|
|
|
|
&cell->member.cell.border.left,
|
|
|
|
&cell->member.cell.border.bottom,
|
|
|
|
&cell->member.cell.border.right };
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (borders[i]->width)
|
|
|
|
{
|
2008-11-05 21:48:37 +01:00
|
|
|
unsigned int j;
|
2008-09-30 23:11:49 +02:00
|
|
|
COLORREF crColor = borders[i]->colorRef;
|
|
|
|
sprintf(props + strlen(props), "\\clbrdr%c", sideChar[i]);
|
|
|
|
sprintf(props + strlen(props), "\\brdrs");
|
|
|
|
sprintf(props + strlen(props), "\\brdrw%d", borders[i]->width);
|
|
|
|
for (j = 1; j < pStream->nColorTblLen; j++) {
|
|
|
|
if (pStream->colortbl[j] == crColor) {
|
|
|
|
sprintf(props + strlen(props), "\\brdrcf%u", j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-08-13 05:15:29 +02:00
|
|
|
sprintf(props + strlen(props), "\\cellx%d", cell->member.cell.nRightBoundary);
|
2008-08-07 18:31:41 +02:00
|
|
|
cell = cell->member.cell.next_cell;
|
|
|
|
} while (cell->member.cell.next_cell);
|
|
|
|
} else { /* v1.0 - 3.0 */
|
2008-09-30 23:11:49 +02:00
|
|
|
const ME_Border* borders[4] = { ¶->member.para.border.top,
|
|
|
|
¶->member.para.border.left,
|
|
|
|
¶->member.para.border.bottom,
|
|
|
|
¶->member.para.border.right };
|
2008-08-07 18:31:41 +02:00
|
|
|
PARAFORMAT2 *pFmt = para->member.para.pFmt;
|
|
|
|
|
|
|
|
assert(!(para->member.para.nFlags & (MEPF_ROWSTART|MEPF_ROWEND|MEPF_CELL)));
|
2008-08-13 05:15:29 +02:00
|
|
|
if (pFmt->dxOffset)
|
|
|
|
sprintf(props + strlen(props), "\\trgaph%d", pFmt->dxOffset);
|
|
|
|
if (pFmt->dxStartIndent)
|
|
|
|
sprintf(props + strlen(props), "\\trleft%d", pFmt->dxStartIndent);
|
2008-09-30 23:11:49 +02:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (borders[i]->width)
|
|
|
|
{
|
2008-11-05 21:48:37 +01:00
|
|
|
unsigned int j;
|
2008-09-30 23:11:49 +02:00
|
|
|
COLORREF crColor = borders[i]->colorRef;
|
|
|
|
sprintf(props + strlen(props), "\\trbrdr%c", sideChar[i]);
|
|
|
|
sprintf(props + strlen(props), "\\brdrs");
|
|
|
|
sprintf(props + strlen(props), "\\brdrw%d", borders[i]->width);
|
|
|
|
for (j = 1; j < pStream->nColorTblLen; j++) {
|
|
|
|
if (pStream->colortbl[j] == crColor) {
|
|
|
|
sprintf(props + strlen(props), "\\brdrcf%u", j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-08-07 18:31:41 +02:00
|
|
|
for (i = 0; i < pFmt->cTabCount; i++)
|
|
|
|
{
|
2008-08-13 05:15:29 +02:00
|
|
|
sprintf(props + strlen(props), "\\cellx%d", pFmt->rgxTabs[i] & 0x00FFFFFF);
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2006-02-04 17:01:01 +01:00
|
|
|
}
|
2008-08-13 05:15:29 +02:00
|
|
|
if (!ME_StreamOutPrint(pStream, props))
|
|
|
|
return FALSE;
|
2008-08-05 01:18:54 +02:00
|
|
|
props[0] = '\0';
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL
|
2008-08-07 18:31:41 +02:00
|
|
|
ME_StreamOutRTFParaProps(ME_TextEditor *editor, ME_OutStream *pStream,
|
2010-07-17 21:29:28 +02:00
|
|
|
ME_DisplayItem *para)
|
2008-08-05 01:18:54 +02:00
|
|
|
{
|
|
|
|
PARAFORMAT2 *fmt = para->member.para.pFmt;
|
|
|
|
char props[STREAMOUT_BUFFER_SIZE] = "";
|
|
|
|
int i;
|
2010-07-17 21:29:28 +02:00
|
|
|
|
|
|
|
if (!editor->bEmulateVersion10) { /* v4.1 */
|
|
|
|
if (para->member.para.nFlags & MEPF_ROWSTART) {
|
|
|
|
pStream->nNestingLevel++;
|
|
|
|
if (pStream->nNestingLevel == 1) {
|
|
|
|
if (!ME_StreamOutRTFTableProps(editor, pStream, para))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else if (para->member.para.nFlags & MEPF_ROWEND) {
|
|
|
|
pStream->nNestingLevel--;
|
|
|
|
if (pStream->nNestingLevel >= 1) {
|
|
|
|
if (!ME_StreamOutPrint(pStream, "{\\*\\nesttableprops"))
|
|
|
|
return FALSE;
|
|
|
|
if (!ME_StreamOutRTFTableProps(editor, pStream, para))
|
|
|
|
return FALSE;
|
|
|
|
if (!ME_StreamOutPrint(pStream, "\\nestrow}{\\nonesttables\\par}\r\n"))
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
if (!ME_StreamOutPrint(pStream, "\\row \r\n"))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
} else { /* v1.0 - 3.0 */
|
|
|
|
if (para->member.para.pFmt->dwMask & PFM_TABLE &&
|
|
|
|
para->member.para.pFmt->wEffects & PFE_TABLE)
|
|
|
|
{
|
|
|
|
if (!ME_StreamOutRTFTableProps(editor, pStream, para))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-14 22:41:16 +01:00
|
|
|
/* TODO: Don't emit anything if the last PARAFORMAT2 is inherited */
|
2006-02-05 13:05:45 +01:00
|
|
|
if (!ME_StreamOutPrint(pStream, "\\pard"))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
2006-02-04 17:01:01 +01:00
|
|
|
|
2008-08-07 18:31:41 +02:00
|
|
|
if (!editor->bEmulateVersion10) { /* v4.1 */
|
|
|
|
if (pStream->nNestingLevel > 0)
|
|
|
|
strcat(props, "\\intbl");
|
2008-08-07 18:31:46 +02:00
|
|
|
if (pStream->nNestingLevel > 1)
|
|
|
|
sprintf(props + strlen(props), "\\itap%d", pStream->nNestingLevel);
|
2008-08-07 18:31:41 +02:00
|
|
|
} else { /* v1.0 - 3.0 */
|
|
|
|
if (fmt->dwMask & PFM_TABLE && fmt->wEffects & PFE_TABLE)
|
|
|
|
strcat(props, "\\intbl");
|
|
|
|
}
|
2005-03-16 21:18:11 +01:00
|
|
|
|
|
|
|
/* TODO: PFM_BORDER. M$ does not emit any keywords for these properties, and
|
|
|
|
* when streaming border keywords in, PFM_BORDER is set, but wBorder field is
|
|
|
|
* set very different from the documentation.
|
|
|
|
* (Tested with RichEdit 5.50.25.0601) */
|
|
|
|
|
|
|
|
if (fmt->dwMask & PFM_ALIGNMENT) {
|
|
|
|
switch (fmt->wAlignment) {
|
|
|
|
case PFA_LEFT:
|
|
|
|
/* Default alignment: not emitted */
|
|
|
|
break;
|
|
|
|
case PFA_RIGHT:
|
|
|
|
strcat(props, "\\qr");
|
|
|
|
break;
|
|
|
|
case PFA_CENTER:
|
|
|
|
strcat(props, "\\qc");
|
|
|
|
break;
|
|
|
|
case PFA_JUSTIFY:
|
|
|
|
strcat(props, "\\qj");
|
|
|
|
break;
|
|
|
|
}
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
2005-03-16 21:18:11 +01:00
|
|
|
|
|
|
|
if (fmt->dwMask & PFM_LINESPACING) {
|
|
|
|
/* FIXME: MSDN says that the bLineSpacingRule field is controlled by the
|
|
|
|
* PFM_SPACEAFTER flag. Is that true? I don't believe so. */
|
|
|
|
switch (fmt->bLineSpacingRule) {
|
|
|
|
case 0: /* Single spacing */
|
|
|
|
strcat(props, "\\sl-240\\slmult1");
|
|
|
|
break;
|
|
|
|
case 1: /* 1.5 spacing */
|
|
|
|
strcat(props, "\\sl-360\\slmult1");
|
|
|
|
break;
|
|
|
|
case 2: /* Double spacing */
|
|
|
|
strcat(props, "\\sl-480\\slmult1");
|
|
|
|
break;
|
|
|
|
case 3:
|
2006-10-13 21:25:54 +02:00
|
|
|
sprintf(props + strlen(props), "\\sl%d\\slmult0", fmt->dyLineSpacing);
|
2005-03-16 21:18:11 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2006-10-13 21:25:54 +02:00
|
|
|
sprintf(props + strlen(props), "\\sl-%d\\slmult0", fmt->dyLineSpacing);
|
2005-03-16 21:18:11 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
2006-10-13 21:25:54 +02:00
|
|
|
sprintf(props + strlen(props), "\\sl-%d\\slmult1", fmt->dyLineSpacing * 240 / 20);
|
2005-03-16 21:18:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fmt->dwMask & PFM_DONOTHYPHEN && fmt->wEffects & PFE_DONOTHYPHEN)
|
|
|
|
strcat(props, "\\hyph0");
|
|
|
|
if (fmt->dwMask & PFM_KEEP && fmt->wEffects & PFE_KEEP)
|
|
|
|
strcat(props, "\\keep");
|
|
|
|
if (fmt->dwMask & PFM_KEEPNEXT && fmt->wEffects & PFE_KEEPNEXT)
|
|
|
|
strcat(props, "\\keepn");
|
|
|
|
if (fmt->dwMask & PFM_NOLINENUMBER && fmt->wEffects & PFE_NOLINENUMBER)
|
|
|
|
strcat(props, "\\noline");
|
|
|
|
if (fmt->dwMask & PFM_NOWIDOWCONTROL && fmt->wEffects & PFE_NOWIDOWCONTROL)
|
|
|
|
strcat(props, "\\nowidctlpar");
|
|
|
|
if (fmt->dwMask & PFM_PAGEBREAKBEFORE && fmt->wEffects & PFE_PAGEBREAKBEFORE)
|
|
|
|
strcat(props, "\\pagebb");
|
|
|
|
if (fmt->dwMask & PFM_RTLPARA && fmt->wEffects & PFE_RTLPARA)
|
|
|
|
strcat(props, "\\rtlpar");
|
|
|
|
if (fmt->dwMask & PFM_SIDEBYSIDE && fmt->wEffects & PFE_SIDEBYSIDE)
|
|
|
|
strcat(props, "\\sbys");
|
|
|
|
|
2008-08-13 05:15:29 +02:00
|
|
|
if (!(editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
|
|
|
fmt->dwMask & PFM_TABLE && fmt->wEffects & PFE_TABLE))
|
|
|
|
{
|
|
|
|
if (fmt->dwMask & PFM_OFFSET)
|
|
|
|
sprintf(props + strlen(props), "\\li%d", fmt->dxOffset);
|
|
|
|
if (fmt->dwMask & PFM_OFFSETINDENT || fmt->dwMask & PFM_STARTINDENT)
|
|
|
|
sprintf(props + strlen(props), "\\fi%d", fmt->dxStartIndent);
|
|
|
|
if (fmt->dwMask & PFM_RIGHTINDENT)
|
|
|
|
sprintf(props + strlen(props), "\\ri%d", fmt->dxRightIndent);
|
|
|
|
if (fmt->dwMask & PFM_TABSTOPS) {
|
|
|
|
static const char * const leader[6] = { "", "\\tldot", "\\tlhyph", "\\tlul", "\\tlth", "\\tleq" };
|
|
|
|
|
|
|
|
for (i = 0; i < fmt->cTabCount; i++) {
|
|
|
|
switch ((fmt->rgxTabs[i] >> 24) & 0xF) {
|
|
|
|
case 1:
|
|
|
|
strcat(props, "\\tqc");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
strcat(props, "\\tqr");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
strcat(props, "\\tqdec");
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
/* Word bar tab (vertical bar). Handled below */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (fmt->rgxTabs[i] >> 28 <= 5)
|
|
|
|
strcat(props, leader[fmt->rgxTabs[i] >> 28]);
|
|
|
|
sprintf(props+strlen(props), "\\tx%d", fmt->rgxTabs[i]&0x00FFFFFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-03-16 21:18:11 +01:00
|
|
|
if (fmt->dwMask & PFM_SPACEAFTER)
|
2006-10-13 21:25:54 +02:00
|
|
|
sprintf(props + strlen(props), "\\sa%d", fmt->dySpaceAfter);
|
2005-03-16 21:18:11 +01:00
|
|
|
if (fmt->dwMask & PFM_SPACEBEFORE)
|
2006-10-13 21:25:54 +02:00
|
|
|
sprintf(props + strlen(props), "\\sb%d", fmt->dySpaceBefore);
|
2005-03-16 21:18:11 +01:00
|
|
|
if (fmt->dwMask & PFM_STYLE)
|
|
|
|
sprintf(props + strlen(props), "\\s%d", fmt->sStyle);
|
|
|
|
|
|
|
|
if (fmt->dwMask & PFM_SHADING) {
|
2006-11-29 11:06:16 +01:00
|
|
|
static const char * const style[16] = { "", "\\bgdkhoriz", "\\bgdkvert", "\\bgdkfdiag",
|
2005-03-16 21:18:11 +01:00
|
|
|
"\\bgdkbdiag", "\\bgdkcross", "\\bgdkdcross",
|
|
|
|
"\\bghoriz", "\\bgvert", "\\bgfdiag",
|
|
|
|
"\\bgbdiag", "\\bgcross", "\\bgdcross",
|
|
|
|
"", "", "" };
|
|
|
|
if (fmt->wShadingWeight)
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-02-05 13:05:45 +01:00
|
|
|
if (*props && !ME_StreamOutPrint(pStream, props))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL
|
2006-02-05 13:05:45 +01:00
|
|
|
ME_StreamOutRTFCharProps(ME_OutStream *pStream, CHARFORMAT2W *fmt)
|
2005-03-14 22:41:16 +01:00
|
|
|
{
|
|
|
|
char props[STREAMOUT_BUFFER_SIZE] = "";
|
2008-11-05 21:48:37 +01:00
|
|
|
unsigned int i;
|
2005-03-14 22:41:16 +01:00
|
|
|
|
|
|
|
if (fmt->dwMask & CFM_ALLCAPS && fmt->dwEffects & CFE_ALLCAPS)
|
|
|
|
strcat(props, "\\caps");
|
|
|
|
if (fmt->dwMask & CFM_ANIMATION)
|
|
|
|
sprintf(props + strlen(props), "\\animtext%u", fmt->bAnimation);
|
|
|
|
if (fmt->dwMask & CFM_BACKCOLOR) {
|
|
|
|
if (!(fmt->dwEffects & CFE_AUTOBACKCOLOR)) {
|
2006-02-05 13:05:45 +01:00
|
|
|
for (i = 1; i < pStream->nColorTblLen; i++)
|
|
|
|
if (pStream->colortbl[i] == fmt->crBackColor) {
|
2005-03-14 22:41:16 +01:00
|
|
|
sprintf(props + strlen(props), "\\cb%u", i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fmt->dwMask & CFM_BOLD && fmt->dwEffects & CFE_BOLD)
|
|
|
|
strcat(props, "\\b");
|
|
|
|
if (fmt->dwMask & CFM_COLOR) {
|
|
|
|
if (!(fmt->dwEffects & CFE_AUTOCOLOR)) {
|
2006-02-05 13:05:45 +01:00
|
|
|
for (i = 1; i < pStream->nColorTblLen; i++)
|
|
|
|
if (pStream->colortbl[i] == fmt->crTextColor) {
|
2005-03-14 22:41:16 +01:00
|
|
|
sprintf(props + strlen(props), "\\cf%u", i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* TODO: CFM_DISABLED */
|
|
|
|
if (fmt->dwMask & CFM_EMBOSS && fmt->dwEffects & CFE_EMBOSS)
|
|
|
|
strcat(props, "\\embo");
|
|
|
|
if (fmt->dwMask & CFM_HIDDEN && fmt->dwEffects & CFE_HIDDEN)
|
|
|
|
strcat(props, "\\v");
|
|
|
|
if (fmt->dwMask & CFM_IMPRINT && fmt->dwEffects & CFE_IMPRINT)
|
|
|
|
strcat(props, "\\impr");
|
|
|
|
if (fmt->dwMask & CFM_ITALIC && fmt->dwEffects & CFE_ITALIC)
|
|
|
|
strcat(props, "\\i");
|
|
|
|
if (fmt->dwMask & CFM_KERNING)
|
|
|
|
sprintf(props + strlen(props), "\\kerning%u", fmt->wKerning);
|
|
|
|
if (fmt->dwMask & CFM_LCID) {
|
|
|
|
/* TODO: handle SFF_PLAINRTF */
|
|
|
|
if (LOWORD(fmt->lcid) == 1024)
|
|
|
|
strcat(props, "\\noproof\\lang1024\\langnp1024\\langfe1024\\langfenp1024");
|
|
|
|
else
|
|
|
|
sprintf(props + strlen(props), "\\lang%u", LOWORD(fmt->lcid));
|
|
|
|
}
|
|
|
|
/* CFM_LINK is not streamed out by M$ */
|
|
|
|
if (fmt->dwMask & CFM_OFFSET) {
|
|
|
|
if (fmt->yOffset >= 0)
|
2006-10-13 21:25:54 +02:00
|
|
|
sprintf(props + strlen(props), "\\up%d", fmt->yOffset);
|
2005-03-14 22:41:16 +01:00
|
|
|
else
|
2006-10-13 21:25:54 +02:00
|
|
|
sprintf(props + strlen(props), "\\dn%d", -fmt->yOffset);
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
|
|
|
if (fmt->dwMask & CFM_OUTLINE && fmt->dwEffects & CFE_OUTLINE)
|
|
|
|
strcat(props, "\\outl");
|
|
|
|
if (fmt->dwMask & CFM_PROTECTED && fmt->dwEffects & CFE_PROTECTED)
|
|
|
|
strcat(props, "\\protect");
|
|
|
|
/* TODO: CFM_REVISED CFM_REVAUTHOR - probably using rsidtbl? */
|
|
|
|
if (fmt->dwMask & CFM_SHADOW && fmt->dwEffects & CFE_SHADOW)
|
|
|
|
strcat(props, "\\shad");
|
2005-03-16 21:18:11 +01:00
|
|
|
if (fmt->dwMask & CFM_SIZE)
|
2006-10-13 21:25:54 +02:00
|
|
|
sprintf(props + strlen(props), "\\fs%d", fmt->yHeight / 10);
|
2005-03-14 22:41:16 +01:00
|
|
|
if (fmt->dwMask & CFM_SMALLCAPS && fmt->dwEffects & CFE_SMALLCAPS)
|
|
|
|
strcat(props, "\\scaps");
|
|
|
|
if (fmt->dwMask & CFM_SPACING)
|
|
|
|
sprintf(props + strlen(props), "\\expnd%u\\expndtw%u", fmt->sSpacing / 5, fmt->sSpacing);
|
|
|
|
if (fmt->dwMask & CFM_STRIKEOUT && fmt->dwEffects & CFE_STRIKEOUT)
|
|
|
|
strcat(props, "\\strike");
|
|
|
|
if (fmt->dwMask & CFM_STYLE) {
|
|
|
|
sprintf(props + strlen(props), "\\cs%u", fmt->sStyle);
|
|
|
|
/* TODO: emit style contents here */
|
|
|
|
}
|
|
|
|
if (fmt->dwMask & (CFM_SUBSCRIPT | CFM_SUPERSCRIPT)) {
|
|
|
|
if (fmt->dwEffects & CFE_SUBSCRIPT)
|
|
|
|
strcat(props, "\\sub");
|
|
|
|
else if (fmt->dwEffects & CFE_SUPERSCRIPT)
|
|
|
|
strcat(props, "\\super");
|
|
|
|
}
|
|
|
|
if (fmt->dwMask & CFM_UNDERLINE || fmt->dwMask & CFM_UNDERLINETYPE) {
|
|
|
|
if (fmt->dwMask & CFM_UNDERLINETYPE)
|
|
|
|
switch (fmt->bUnderlineType) {
|
|
|
|
case CFU_CF1UNDERLINE:
|
|
|
|
case CFU_UNDERLINE:
|
|
|
|
strcat(props, "\\ul");
|
|
|
|
break;
|
|
|
|
case CFU_UNDERLINEDOTTED:
|
|
|
|
strcat(props, "\\uld");
|
|
|
|
break;
|
|
|
|
case CFU_UNDERLINEDOUBLE:
|
|
|
|
strcat(props, "\\uldb");
|
|
|
|
break;
|
|
|
|
case CFU_UNDERLINEWORD:
|
|
|
|
strcat(props, "\\ulw");
|
|
|
|
break;
|
|
|
|
case CFU_UNDERLINENONE:
|
|
|
|
default:
|
2013-08-20 00:31:38 +02:00
|
|
|
strcat(props, "\\ulnone");
|
2005-03-14 22:41:16 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (fmt->dwEffects & CFE_UNDERLINE)
|
|
|
|
strcat(props, "\\ul");
|
|
|
|
}
|
|
|
|
/* FIXME: How to emit CFM_WEIGHT? */
|
|
|
|
|
|
|
|
if (fmt->dwMask & CFM_FACE || fmt->dwMask & CFM_CHARSET) {
|
|
|
|
WCHAR *szFaceName;
|
|
|
|
|
|
|
|
if (fmt->dwMask & CFM_FACE)
|
|
|
|
szFaceName = fmt->szFaceName;
|
|
|
|
else
|
2006-02-05 13:05:45 +01:00
|
|
|
szFaceName = pStream->fonttbl[0].szFaceName;
|
|
|
|
for (i = 0; i < pStream->nFontTblLen; i++) {
|
|
|
|
if (szFaceName == pStream->fonttbl[i].szFaceName
|
|
|
|
|| !lstrcmpW(szFaceName, pStream->fonttbl[i].szFaceName))
|
2005-03-14 22:41:16 +01:00
|
|
|
if (!(fmt->dwMask & CFM_CHARSET)
|
2006-02-05 13:05:45 +01:00
|
|
|
|| fmt->bCharSet == pStream->fonttbl[i].bCharSet)
|
2005-03-14 22:41:16 +01:00
|
|
|
break;
|
|
|
|
}
|
2006-02-05 13:05:45 +01:00
|
|
|
if (i < pStream->nFontTblLen)
|
2005-03-22 17:41:36 +01:00
|
|
|
{
|
2006-02-05 13:05:45 +01:00
|
|
|
if (i != pStream->nDefaultFont)
|
2005-03-24 16:09:05 +01:00
|
|
|
sprintf(props + strlen(props), "\\f%u", i);
|
2005-03-22 17:41:36 +01:00
|
|
|
|
|
|
|
/* In UTF-8 mode, charsets/codepages are not used */
|
2006-02-05 13:05:45 +01:00
|
|
|
if (pStream->nDefaultCodePage != CP_UTF8)
|
2005-03-22 17:41:36 +01:00
|
|
|
{
|
2006-02-05 13:05:45 +01:00
|
|
|
if (pStream->fonttbl[i].bCharSet == DEFAULT_CHARSET)
|
|
|
|
pStream->nCodePage = pStream->nDefaultCodePage;
|
2005-03-22 17:41:36 +01:00
|
|
|
else
|
2006-02-05 13:05:45 +01:00
|
|
|
pStream->nCodePage = RTFCharSetToCodePage(NULL, pStream->fonttbl[i].bCharSet);
|
2005-03-22 17:41:36 +01:00
|
|
|
}
|
|
|
|
}
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
|
|
|
if (*props)
|
|
|
|
strcat(props, " ");
|
2006-02-05 13:05:45 +01:00
|
|
|
if (!ME_StreamOutPrint(pStream, props))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL
|
2007-08-16 22:57:12 +02:00
|
|
|
ME_StreamOutRTFText(ME_OutStream *pStream, const WCHAR *text, LONG nChars)
|
2005-03-14 22:41:16 +01:00
|
|
|
{
|
|
|
|
char buffer[STREAMOUT_BUFFER_SIZE];
|
|
|
|
int pos = 0;
|
2005-07-05 18:18:33 +02:00
|
|
|
int fit, nBytes, i;
|
2005-03-16 21:18:11 +01:00
|
|
|
|
|
|
|
if (nChars == -1)
|
|
|
|
nChars = lstrlenW(text);
|
|
|
|
|
2005-03-14 22:41:16 +01:00
|
|
|
while (nChars) {
|
2005-03-22 17:41:36 +01:00
|
|
|
/* In UTF-8 mode, font charsets are not used. */
|
2006-02-05 13:05:45 +01:00
|
|
|
if (pStream->nDefaultCodePage == CP_UTF8) {
|
2005-03-14 22:41:16 +01:00
|
|
|
/* 6 is the maximum character length in UTF-8 */
|
|
|
|
fit = min(nChars, STREAMOUT_BUFFER_SIZE / 6);
|
2005-07-05 18:18:33 +02:00
|
|
|
nBytes = WideCharToMultiByte(CP_UTF8, 0, text, fit, buffer,
|
|
|
|
STREAMOUT_BUFFER_SIZE, NULL, NULL);
|
2005-03-14 22:41:16 +01:00
|
|
|
nChars -= fit;
|
|
|
|
text += fit;
|
2005-07-05 18:18:33 +02:00
|
|
|
for (i = 0; i < nBytes; i++)
|
2005-03-14 22:41:16 +01:00
|
|
|
if (buffer[i] == '{' || buffer[i] == '}' || buffer[i] == '\\') {
|
2006-02-05 13:05:45 +01:00
|
|
|
if (!ME_StreamOutPrint(pStream, "%.*s\\", i - pos, buffer + pos))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
pos = i;
|
|
|
|
}
|
2005-08-11 12:30:41 +02:00
|
|
|
if (pos < nBytes)
|
2006-02-05 13:05:45 +01:00
|
|
|
if (!ME_StreamOutMove(pStream, buffer + pos, nBytes - pos))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
pos = 0;
|
|
|
|
} else if (*text < 128) {
|
|
|
|
if (*text == '{' || *text == '}' || *text == '\\')
|
|
|
|
buffer[pos++] = '\\';
|
|
|
|
buffer[pos++] = (char)(*text++);
|
|
|
|
nChars--;
|
|
|
|
} else {
|
2005-03-24 16:09:05 +01:00
|
|
|
BOOL unknown = FALSE;
|
2005-09-12 22:30:37 +02:00
|
|
|
char letter[3];
|
|
|
|
|
2005-03-24 16:09:05 +01:00
|
|
|
/* FIXME: In the MS docs for WideCharToMultiByte there is a big list of
|
|
|
|
* codepages including CP_SYMBOL for which the last parameter must be set
|
|
|
|
* to NULL for the function to succeed. But in Wine we need to care only
|
|
|
|
* about CP_SYMBOL */
|
2006-02-05 13:05:45 +01:00
|
|
|
nBytes = WideCharToMultiByte(pStream->nCodePage, 0, text, 1,
|
2005-03-24 16:09:05 +01:00
|
|
|
letter, 3, NULL,
|
2006-02-05 13:05:45 +01:00
|
|
|
(pStream->nCodePage == CP_SYMBOL) ? NULL : &unknown);
|
2005-03-14 22:41:16 +01:00
|
|
|
if (unknown)
|
2005-03-24 16:09:05 +01:00
|
|
|
pos += sprintf(buffer + pos, "\\u%d?", (short)*text);
|
2005-09-12 22:30:37 +02:00
|
|
|
else if ((BYTE)*letter < 128) {
|
2005-03-14 22:41:16 +01:00
|
|
|
if (*letter == '{' || *letter == '}' || *letter == '\\')
|
|
|
|
buffer[pos++] = '\\';
|
|
|
|
buffer[pos++] = *letter;
|
2005-03-22 17:41:36 +01:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < nBytes; i++)
|
2005-10-11 21:56:03 +02:00
|
|
|
pos += sprintf(buffer + pos, "\\'%02x", (BYTE)letter[i]);
|
2005-03-22 17:41:36 +01:00
|
|
|
}
|
2005-03-14 22:41:16 +01:00
|
|
|
text++;
|
|
|
|
nChars--;
|
|
|
|
}
|
2005-03-22 17:41:36 +01:00
|
|
|
if (pos >= STREAMOUT_BUFFER_SIZE - 11) {
|
2006-02-05 13:05:45 +01:00
|
|
|
if (!ME_StreamOutMove(pStream, buffer, pos))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
}
|
2006-02-05 13:05:45 +01:00
|
|
|
return ME_StreamOutMove(pStream, buffer, pos);
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-13 14:44:22 +02:00
|
|
|
static BOOL ME_StreamOutRTF(ME_TextEditor *editor, ME_OutStream *pStream,
|
|
|
|
const ME_Cursor *start, int nChars, int dwFormat)
|
2005-03-14 22:41:16 +01:00
|
|
|
{
|
2009-08-13 14:44:22 +02:00
|
|
|
ME_Cursor cursor = *start;
|
|
|
|
ME_DisplayItem *prev_para = cursor.pPara;
|
|
|
|
ME_Cursor endCur = cursor;
|
2009-02-06 07:09:47 +01:00
|
|
|
|
2009-08-13 14:44:22 +02:00
|
|
|
ME_MoveCursorChars(editor, &endCur, nChars);
|
2009-02-06 07:09:47 +01:00
|
|
|
|
2006-02-05 13:05:45 +01:00
|
|
|
if (!ME_StreamOutRTFHeader(pStream, dwFormat))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2009-08-13 14:44:22 +02:00
|
|
|
if (!ME_StreamOutRTFFontAndColorTbl(pStream, cursor.pRun, endCur.pRun))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
2009-08-13 14:44:22 +02:00
|
|
|
|
2005-03-14 22:41:16 +01:00
|
|
|
/* TODO: stylesheet table */
|
2009-08-13 14:44:22 +02:00
|
|
|
|
2005-03-14 22:41:16 +01:00
|
|
|
/* FIXME: maybe emit something smarter for the generator? */
|
2006-02-05 13:05:45 +01:00
|
|
|
if (!ME_StreamOutPrint(pStream, "{\\*\\generator Wine Riched20 2.0.????;}"))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* TODO: information group */
|
|
|
|
|
|
|
|
/* TODO: document formatting properties */
|
|
|
|
|
|
|
|
/* FIXME: We have only one document section */
|
|
|
|
|
|
|
|
/* TODO: section formatting properties */
|
|
|
|
|
2009-08-13 14:44:22 +02:00
|
|
|
if (!ME_StreamOutRTFParaProps(editor, pStream, cursor.pPara))
|
2005-03-15 16:40:52 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2009-08-13 14:44:22 +02:00
|
|
|
do {
|
|
|
|
if (cursor.pPara != prev_para)
|
2005-03-15 16:40:52 +01:00
|
|
|
{
|
2009-08-13 14:44:22 +02:00
|
|
|
prev_para = cursor.pPara;
|
2010-07-17 21:29:28 +02:00
|
|
|
if (!ME_StreamOutRTFParaProps(editor, pStream, cursor.pPara))
|
|
|
|
return FALSE;
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
2009-08-13 14:44:22 +02:00
|
|
|
|
|
|
|
if (cursor.pRun == endCur.pRun && !endCur.nOffset)
|
2005-03-14 22:41:16 +01:00
|
|
|
break;
|
2009-08-13 14:44:22 +02:00
|
|
|
TRACE("flags %xh\n", cursor.pRun->member.run.nFlags);
|
|
|
|
/* TODO: emit embedded objects */
|
|
|
|
if (cursor.pPara->member.para.nFlags & (MEPF_ROWSTART|MEPF_ROWEND))
|
2010-07-17 21:29:08 +02:00
|
|
|
continue;
|
2009-08-13 14:44:22 +02:00
|
|
|
if (cursor.pRun->member.run.nFlags & MERF_GRAPHICS) {
|
|
|
|
FIXME("embedded objects are not handled\n");
|
|
|
|
} else if (cursor.pRun->member.run.nFlags & MERF_TAB) {
|
|
|
|
if (editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
|
|
|
cursor.pPara->member.para.pFmt->dwMask & PFM_TABLE &&
|
|
|
|
cursor.pPara->member.para.pFmt->wEffects & PFE_TABLE)
|
|
|
|
{
|
|
|
|
if (!ME_StreamOutPrint(pStream, "\\cell "))
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
if (!ME_StreamOutPrint(pStream, "\\tab "))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else if (cursor.pRun->member.run.nFlags & MERF_ENDCELL) {
|
|
|
|
if (pStream->nNestingLevel > 1) {
|
|
|
|
if (!ME_StreamOutPrint(pStream, "\\nestcell "))
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
if (!ME_StreamOutPrint(pStream, "\\cell "))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
nChars--;
|
|
|
|
} else if (cursor.pRun->member.run.nFlags & MERF_ENDPARA) {
|
|
|
|
if (cursor.pPara->member.para.pFmt->dwMask & PFM_TABLE &&
|
|
|
|
cursor.pPara->member.para.pFmt->wEffects & PFE_TABLE &&
|
|
|
|
!(cursor.pPara->member.para.nFlags & (MEPF_ROWSTART|MEPF_ROWEND|MEPF_CELL)))
|
|
|
|
{
|
|
|
|
if (!ME_StreamOutPrint(pStream, "\\row \r\n"))
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
if (!ME_StreamOutPrint(pStream, "\r\n\\par"))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* Skip as many characters as required by current line break */
|
2013-01-31 14:48:00 +01:00
|
|
|
nChars = max(0, nChars - cursor.pRun->member.run.len);
|
2009-08-13 14:44:22 +02:00
|
|
|
} else if (cursor.pRun->member.run.nFlags & MERF_ENDROW) {
|
|
|
|
if (!ME_StreamOutPrint(pStream, "\\line \r\n"))
|
|
|
|
return FALSE;
|
|
|
|
nChars--;
|
|
|
|
} else {
|
|
|
|
int nEnd;
|
|
|
|
|
|
|
|
if (!ME_StreamOutPrint(pStream, "{"))
|
|
|
|
return FALSE;
|
|
|
|
TRACE("style %p\n", cursor.pRun->member.run.style);
|
|
|
|
if (!ME_StreamOutRTFCharProps(pStream, &cursor.pRun->member.run.style->fmt))
|
|
|
|
return FALSE;
|
|
|
|
|
2013-01-31 14:48:00 +01:00
|
|
|
nEnd = (cursor.pRun == endCur.pRun) ? endCur.nOffset : cursor.pRun->member.run.len;
|
2013-01-30 16:10:20 +01:00
|
|
|
if (!ME_StreamOutRTFText(pStream, get_text( &cursor.pRun->member.run, cursor.nOffset ),
|
2009-08-13 14:44:22 +02:00
|
|
|
nEnd - cursor.nOffset))
|
|
|
|
return FALSE;
|
|
|
|
cursor.nOffset = 0;
|
|
|
|
if (!ME_StreamOutPrint(pStream, "}"))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} while (cursor.pRun != endCur.pRun && ME_NextRun(&cursor.pPara, &cursor.pRun));
|
|
|
|
|
2009-04-24 09:25:46 +02:00
|
|
|
if (!ME_StreamOutMove(pStream, "}\0", 2))
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-13 14:44:22 +02:00
|
|
|
static BOOL ME_StreamOutText(ME_TextEditor *editor, ME_OutStream *pStream,
|
|
|
|
const ME_Cursor *start, int nChars, DWORD dwFormat)
|
2005-03-14 22:41:16 +01:00
|
|
|
{
|
2009-08-13 14:44:22 +02:00
|
|
|
ME_Cursor cursor = *start;
|
2005-03-14 22:41:16 +01:00
|
|
|
int nLen;
|
|
|
|
UINT nCodePage = CP_ACP;
|
2005-09-12 22:30:37 +02:00
|
|
|
char *buffer = NULL;
|
2005-03-14 22:41:16 +01:00
|
|
|
int nBufLen = 0;
|
|
|
|
BOOL success = TRUE;
|
|
|
|
|
2009-08-13 14:44:22 +02:00
|
|
|
if (!cursor.pRun)
|
2005-03-14 22:41:16 +01:00
|
|
|
return FALSE;
|
2009-01-28 07:34:56 +01:00
|
|
|
|
2005-03-14 22:41:16 +01:00
|
|
|
if (dwFormat & SF_USECODEPAGE)
|
|
|
|
nCodePage = HIWORD(dwFormat);
|
|
|
|
|
|
|
|
/* TODO: Handle SF_TEXTIZED */
|
2009-01-28 07:34:56 +01:00
|
|
|
|
2009-08-13 14:44:22 +02:00
|
|
|
while (success && nChars && cursor.pRun) {
|
2013-01-31 14:48:00 +01:00
|
|
|
nLen = min(nChars, cursor.pRun->member.run.len - cursor.nOffset);
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2009-08-13 14:44:22 +02:00
|
|
|
if (!editor->bEmulateVersion10 && cursor.pRun->member.run.nFlags & MERF_ENDPARA)
|
2009-01-28 07:34:56 +01:00
|
|
|
{
|
2011-12-16 13:06:45 +01:00
|
|
|
static const WCHAR szEOL[] = { '\r', '\n' };
|
2009-01-28 07:34:56 +01:00
|
|
|
|
|
|
|
/* richedit 2.0 - all line breaks are \r\n */
|
|
|
|
if (dwFormat & SF_UNICODE)
|
|
|
|
success = ME_StreamOutMove(pStream, (const char *)szEOL, sizeof(szEOL));
|
|
|
|
else
|
|
|
|
success = ME_StreamOutMove(pStream, "\r\n", 2);
|
2005-03-14 22:41:16 +01:00
|
|
|
} else {
|
|
|
|
if (dwFormat & SF_UNICODE)
|
2013-01-30 16:10:20 +01:00
|
|
|
success = ME_StreamOutMove(pStream, (const char *)(get_text( &cursor.pRun->member.run, cursor.nOffset )),
|
2005-03-14 22:41:16 +01:00
|
|
|
sizeof(WCHAR) * nLen);
|
|
|
|
else {
|
|
|
|
int nSize;
|
|
|
|
|
2013-01-30 16:10:20 +01:00
|
|
|
nSize = WideCharToMultiByte(nCodePage, 0, get_text( &cursor.pRun->member.run, cursor.nOffset ),
|
2005-03-14 22:41:16 +01:00
|
|
|
nLen, NULL, 0, NULL, NULL);
|
|
|
|
if (nSize > nBufLen) {
|
2006-05-10 00:33:53 +02:00
|
|
|
FREE_OBJ(buffer);
|
2005-09-12 22:30:37 +02:00
|
|
|
buffer = ALLOC_N_OBJ(char, nSize);
|
2005-03-14 22:41:16 +01:00
|
|
|
nBufLen = nSize;
|
|
|
|
}
|
2013-01-30 16:10:20 +01:00
|
|
|
WideCharToMultiByte(nCodePage, 0, get_text( &cursor.pRun->member.run, cursor.nOffset ),
|
2005-03-14 22:41:16 +01:00
|
|
|
nLen, buffer, nSize, NULL, NULL);
|
2006-02-05 13:05:45 +01:00
|
|
|
success = ME_StreamOutMove(pStream, buffer, nSize);
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
|
|
|
}
|
2009-01-28 07:34:56 +01:00
|
|
|
|
2005-03-14 22:41:16 +01:00
|
|
|
nChars -= nLen;
|
2009-08-13 14:44:22 +02:00
|
|
|
cursor.nOffset = 0;
|
|
|
|
cursor.pRun = ME_FindItemFwd(cursor.pRun, diRun);
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
2009-01-28 07:34:56 +01:00
|
|
|
|
2006-05-10 00:33:53 +02:00
|
|
|
FREE_OBJ(buffer);
|
2005-03-14 22:41:16 +01:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-13 14:44:22 +02:00
|
|
|
LRESULT ME_StreamOutRange(ME_TextEditor *editor, DWORD dwFormat,
|
|
|
|
const ME_Cursor *start,
|
|
|
|
int nChars, EDITSTREAM *stream)
|
2005-03-14 22:41:16 +01:00
|
|
|
{
|
2006-02-05 13:05:45 +01:00
|
|
|
ME_OutStream *pStream = ME_StreamOutInit(editor, stream);
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2005-07-05 22:56:07 +02:00
|
|
|
if (dwFormat & SF_RTF)
|
2009-08-13 14:44:22 +02:00
|
|
|
ME_StreamOutRTF(editor, pStream, start, nChars, dwFormat);
|
2005-03-14 22:41:16 +01:00
|
|
|
else if (dwFormat & SF_TEXT || dwFormat & SF_TEXTIZED)
|
2009-08-13 14:44:22 +02:00
|
|
|
ME_StreamOutText(editor, pStream, start, nChars, dwFormat);
|
2006-02-05 13:05:45 +01:00
|
|
|
if (!pStream->stream->dwError)
|
|
|
|
ME_StreamOutFlush(pStream);
|
|
|
|
return ME_StreamOutFree(pStream);
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
2006-02-05 13:05:06 +01:00
|
|
|
|
|
|
|
LRESULT
|
|
|
|
ME_StreamOut(ME_TextEditor *editor, DWORD dwFormat, EDITSTREAM *stream)
|
|
|
|
{
|
2009-08-13 14:44:22 +02:00
|
|
|
ME_Cursor start;
|
|
|
|
int nChars;
|
2006-02-05 13:05:06 +01:00
|
|
|
|
2009-08-13 14:44:22 +02:00
|
|
|
if (dwFormat & SFF_SELECTION) {
|
|
|
|
int nStart, nTo;
|
|
|
|
start = editor->pCursors[ME_GetSelectionOfs(editor, &nStart, &nTo)];
|
|
|
|
nChars = nTo - nStart;
|
|
|
|
} else {
|
|
|
|
ME_SetCursorToStart(editor, &start);
|
|
|
|
nChars = ME_GetTextLength(editor);
|
|
|
|
/* Generate an end-of-paragraph at the end of SCF_ALL RTF output */
|
|
|
|
if (dwFormat & SF_RTF)
|
|
|
|
nChars++;
|
2006-02-05 13:05:06 +01:00
|
|
|
}
|
2009-08-13 14:44:22 +02:00
|
|
|
return ME_StreamOutRange(editor, dwFormat, &start, nChars, stream);
|
2006-02-05 13:05:06 +01:00
|
|
|
}
|