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
|
|
|
*/
|
|
|
|
|
2016-06-07 12:18:23 +02:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
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);
|
|
|
|
|
2016-10-14 11:05:04 +02:00
|
|
|
#define STREAMOUT_BUFFER_SIZE 4096
|
|
|
|
#define STREAMOUT_FONTTBL_SIZE 8192
|
|
|
|
#define STREAMOUT_COLORTBL_SIZE 1024
|
|
|
|
|
|
|
|
typedef struct tagME_OutStream
|
|
|
|
{
|
|
|
|
EDITSTREAM *stream;
|
|
|
|
char buffer[STREAMOUT_BUFFER_SIZE];
|
|
|
|
UINT pos, written;
|
|
|
|
UINT nCodePage;
|
|
|
|
UINT nFontTblLen;
|
|
|
|
ME_FontTableItem fonttbl[STREAMOUT_FONTTBL_SIZE];
|
|
|
|
UINT nColorTblLen;
|
|
|
|
COLORREF colortbl[STREAMOUT_COLORTBL_SIZE];
|
|
|
|
UINT nDefaultFont;
|
|
|
|
UINT nDefaultCodePage;
|
|
|
|
/* nNestingLevel = 0 means we aren't in a cell, 1 means we are in a cell,
|
|
|
|
* an greater numbers mean we are in a cell nested within a cell. */
|
|
|
|
UINT nNestingLevel;
|
|
|
|
CHARFORMAT2W cur_fmt; /* current character format */
|
|
|
|
} ME_OutStream;
|
2005-03-14 22:41:16 +01:00
|
|
|
|
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)
|
|
|
|
{
|
2018-02-03 23:59:47 +01:00
|
|
|
ME_OutStream *pStream = heap_alloc_zero(sizeof(*pStream));
|
|
|
|
|
2006-02-05 13:05:45 +01:00
|
|
|
pStream->stream = stream;
|
|
|
|
pStream->stream->dwError = 0;
|
|
|
|
pStream->nColorTblLen = 1;
|
2016-10-14 11:05:04 +02:00
|
|
|
pStream->cur_fmt.dwEffects = CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR;
|
|
|
|
pStream->cur_fmt.bUnderlineType = CFU_UNDERLINE;
|
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
|
|
|
}
|
2015-11-06 07:18:10 +01:00
|
|
|
if (nWritten == pStream->pos)
|
|
|
|
pStream->written += nWritten;
|
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
|
|
|
|
2018-02-03 23:59:46 +01:00
|
|
|
heap_free(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-19 10:30:25 +02:00
|
|
|
static BOOL WINAPIV
|
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;
|
2019-06-19 10:30:25 +02:00
|
|
|
__ms_va_list valist;
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2019-06-19 10:30:25 +02:00
|
|
|
__ms_va_start(valist, format);
|
2005-03-14 22:41:16 +01:00
|
|
|
len = vsnprintf(string, sizeof(string), format, valist);
|
2019-06-19 10:30:25 +02:00
|
|
|
__ms_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
|
|
|
}
|
|
|
|
|
2016-06-07 12:18:23 +02:00
|
|
|
#define HEX_BYTES_PER_LINE 40
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
ME_StreamOutHexData(ME_OutStream *stream, const BYTE *data, UINT len)
|
|
|
|
{
|
|
|
|
|
|
|
|
char line[HEX_BYTES_PER_LINE * 2 + 1];
|
|
|
|
UINT size, i;
|
|
|
|
static const char hex[] = "0123456789abcdef";
|
|
|
|
|
|
|
|
while (len)
|
|
|
|
{
|
|
|
|
size = min( len, HEX_BYTES_PER_LINE );
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
{
|
|
|
|
line[i * 2] = hex[(*data >> 4) & 0xf];
|
|
|
|
line[i * 2 + 1] = hex[*data & 0xf];
|
|
|
|
data++;
|
|
|
|
}
|
|
|
|
line[size * 2] = '\n';
|
|
|
|
if (!ME_StreamOutMove( stream, line, size * 2 + 1 ))
|
|
|
|
return FALSE;
|
|
|
|
len -= size;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2016-10-11 14:04:02 +02:00
|
|
|
static void add_font_to_fonttbl( ME_OutStream *stream, ME_Style *style )
|
|
|
|
{
|
|
|
|
ME_FontTableItem *table = stream->fonttbl;
|
|
|
|
CHARFORMAT2W *fmt = &style->fmt;
|
|
|
|
WCHAR *face = fmt->szFaceName;
|
|
|
|
BYTE charset = (fmt->dwMask & CFM_CHARSET) ? fmt->bCharSet : DEFAULT_CHARSET;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (fmt->dwMask & CFM_FACE)
|
|
|
|
{
|
|
|
|
for (i = 0; i < stream->nFontTblLen; i++)
|
|
|
|
if (table[i].bCharSet == charset
|
2019-06-19 10:30:25 +02:00
|
|
|
&& (table[i].szFaceName == face || !wcscmp(table[i].szFaceName, face)))
|
2016-10-11 14:04:02 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == stream->nFontTblLen && i < STREAMOUT_FONTTBL_SIZE)
|
|
|
|
{
|
|
|
|
table[i].bCharSet = charset;
|
|
|
|
table[i].szFaceName = face;
|
|
|
|
stream->nFontTblLen++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2016-10-12 13:58:50 +02:00
|
|
|
static BOOL find_font_in_fonttbl( ME_OutStream *stream, CHARFORMAT2W *fmt, unsigned int *idx )
|
|
|
|
{
|
|
|
|
WCHAR *facename;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
*idx = 0;
|
|
|
|
if (fmt->dwMask & CFM_FACE)
|
|
|
|
facename = fmt->szFaceName;
|
|
|
|
else
|
|
|
|
facename = stream->fonttbl[0].szFaceName;
|
|
|
|
for (i = 0; i < stream->nFontTblLen; i++)
|
|
|
|
{
|
|
|
|
if (facename == stream->fonttbl[i].szFaceName
|
2019-06-19 10:30:25 +02:00
|
|
|
|| !wcscmp(facename, stream->fonttbl[i].szFaceName))
|
2016-10-12 13:58:50 +02:00
|
|
|
if (!(fmt->dwMask & CFM_CHARSET)
|
|
|
|
|| fmt->bCharSet == stream->fonttbl[i].bCharSet)
|
|
|
|
{
|
|
|
|
*idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return i < stream->nFontTblLen;
|
|
|
|
}
|
|
|
|
|
2016-10-11 14:04:03 +02:00
|
|
|
static void add_color_to_colortbl( ME_OutStream *stream, COLORREF color )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1; i < stream->nColorTblLen; i++)
|
|
|
|
if (stream->colortbl[i] == color)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == stream->nColorTblLen && i < STREAMOUT_COLORTBL_SIZE)
|
|
|
|
{
|
|
|
|
stream->colortbl[i] = color;
|
|
|
|
stream->nColorTblLen++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-12 13:58:51 +02:00
|
|
|
static BOOL find_color_in_colortbl( ME_OutStream *stream, COLORREF color, unsigned int *idx )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
*idx = 0;
|
|
|
|
for (i = 1; i < stream->nColorTblLen; i++)
|
|
|
|
{
|
|
|
|
if (stream->colortbl[i] == color)
|
|
|
|
{
|
|
|
|
*idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return i < stream->nFontTblLen;
|
|
|
|
}
|
|
|
|
|
2020-10-20 13:50:34 +02:00
|
|
|
static BOOL stream_out_font_and_colour_tbls( ME_OutStream *pStream, ME_Run *first, ME_Run *last )
|
2005-03-14 22:41:16 +01:00
|
|
|
{
|
2020-10-20 13:50:34 +02:00
|
|
|
ME_Run *run = first;
|
2006-02-05 13:05:45 +01:00
|
|
|
ME_FontTableItem *table = pStream->fonttbl;
|
2008-11-05 21:48:37 +01:00
|
|
|
unsigned int i;
|
2020-10-22 13:46:49 +02:00
|
|
|
ME_Cell *cell = NULL;
|
2016-10-11 14:04:04 +02:00
|
|
|
ME_Paragraph *prev_para = NULL;
|
2016-10-11 14:04:02 +02:00
|
|
|
|
2020-10-20 13:50:34 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
CHARFORMAT2W *fmt = &run->style->fmt;
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2020-10-20 13:50:34 +02:00
|
|
|
add_font_to_fonttbl( pStream, run->style );
|
2016-10-11 14:04:02 +02:00
|
|
|
|
2016-10-11 14:04:03 +02:00
|
|
|
if (fmt->dwMask & CFM_COLOR && !(fmt->dwEffects & CFE_AUTOCOLOR))
|
|
|
|
add_color_to_colortbl( pStream, fmt->crTextColor );
|
|
|
|
if (fmt->dwMask & CFM_BACKCOLOR && !(fmt->dwEffects & CFE_AUTOBACKCOLOR))
|
|
|
|
add_color_to_colortbl( pStream, fmt->crBackColor );
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2020-10-20 13:50:34 +02:00
|
|
|
if (run->para != prev_para)
|
2008-09-30 23:11:49 +02:00
|
|
|
{
|
2016-10-12 13:58:49 +02:00
|
|
|
/* check for any para numbering text */
|
2020-10-20 13:50:34 +02:00
|
|
|
if (run->para->fmt.wNumbering)
|
|
|
|
add_font_to_fonttbl( pStream, run->para->para_num.style );
|
2016-10-12 13:58:49 +02:00
|
|
|
|
2020-10-22 13:46:49 +02:00
|
|
|
if ((cell = para_cell( run->para )))
|
2016-10-11 14:04:04 +02:00
|
|
|
{
|
2020-10-22 13:46:49 +02:00
|
|
|
ME_Border* borders[4] = { &cell->border.top, &cell->border.left,
|
|
|
|
&cell->border.bottom, &cell->border.right };
|
2008-09-30 23:11:49 +02:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
if (borders[i]->width > 0)
|
2016-10-11 14:04:03 +02:00
|
|
|
add_color_to_colortbl( pStream, borders[i]->colorRef );
|
2016-10-11 14:04:04 +02:00
|
|
|
}
|
|
|
|
|
2020-10-20 13:50:34 +02:00
|
|
|
prev_para = run->para;
|
2008-09-30 23:11:49 +02:00
|
|
|
}
|
2016-10-11 14:04:04 +02:00
|
|
|
|
2020-10-20 13:50:34 +02:00
|
|
|
if (run == last) break;
|
|
|
|
run = run_next_all_paras( run );
|
|
|
|
} while (run);
|
2016-10-11 14:04:04 +02: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-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;
|
|
|
|
}
|
2017-03-03 11:10:43 +01:00
|
|
|
if (!ME_StreamOutPrint(pStream, "}\r\n")) return FALSE;
|
2005-03-14 22:41:16 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-10-20 13:50:35 +02:00
|
|
|
static BOOL stream_out_table_props( ME_TextEditor *editor, ME_OutStream *pStream,
|
|
|
|
ME_Paragraph *para )
|
2005-03-14 22:41:16 +01:00
|
|
|
{
|
2020-10-22 13:46:49 +02:00
|
|
|
ME_Cell *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;
|
2020-10-20 13:50:35 +02:00
|
|
|
if (!editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
{
|
|
|
|
PARAFORMAT2 *pFmt = &table_row_end( para )->fmt;
|
2020-10-22 13:46:49 +02:00
|
|
|
cell = table_row_first_cell( para );
|
|
|
|
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);
|
2020-10-20 13:50:35 +02:00
|
|
|
do
|
|
|
|
{
|
2020-10-22 13:46:49 +02:00
|
|
|
ME_Border* borders[4] = { &cell->border.top, &cell->border.left,
|
|
|
|
&cell->border.bottom, &cell->border.right };
|
2008-09-30 23:11:49 +02:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (borders[i]->width)
|
|
|
|
{
|
2016-10-12 13:58:51 +02:00
|
|
|
unsigned int idx;
|
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);
|
2016-10-12 13:58:51 +02:00
|
|
|
if (find_color_in_colortbl( pStream, crColor, &idx ))
|
|
|
|
sprintf(props + strlen(props), "\\brdrcf%u", idx);
|
2008-09-30 23:11:49 +02:00
|
|
|
}
|
|
|
|
}
|
2020-10-22 13:46:49 +02:00
|
|
|
sprintf( props + strlen(props), "\\cellx%d", cell->nRightBoundary );
|
|
|
|
cell = cell_next( cell );
|
|
|
|
} while (cell_next( cell ));
|
2020-10-20 13:50:35 +02:00
|
|
|
}
|
|
|
|
else /* v1.0 - 3.0 */
|
|
|
|
{
|
|
|
|
const ME_Border* borders[4] = { ¶->border.top,
|
|
|
|
¶->border.left,
|
|
|
|
¶->border.bottom,
|
|
|
|
¶->border.right };
|
|
|
|
PARAFORMAT2 *pFmt = ¶->fmt;
|
|
|
|
|
|
|
|
assert( !(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)
|
|
|
|
{
|
2016-10-12 13:58:51 +02:00
|
|
|
unsigned int idx;
|
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);
|
2016-10-12 13:58:51 +02:00
|
|
|
if (find_color_in_colortbl( pStream, crColor, &idx ))
|
|
|
|
sprintf(props + strlen(props), "\\brdrcf%u", idx);
|
2008-09-30 23:11:49 +02:00
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2016-10-12 13:58:52 +02:00
|
|
|
static BOOL stream_out_para_num( ME_OutStream *stream, ME_Paragraph *para, BOOL pn_dest )
|
|
|
|
{
|
|
|
|
static const char fmt_label[] = "{\\*\\pn\\pnlvlbody\\pnf%u\\pnindent%d\\pnstart%d%s%s}";
|
|
|
|
static const char fmt_bullet[] = "{\\*\\pn\\pnlvlblt\\pnf%u\\pnindent%d{\\pntxtb\\'b7}}";
|
|
|
|
static const char dec[] = "\\pndec";
|
|
|
|
static const char lcltr[] = "\\pnlcltr";
|
|
|
|
static const char ucltr[] = "\\pnucltr";
|
|
|
|
static const char lcrm[] = "\\pnlcrm";
|
|
|
|
static const char ucrm[] = "\\pnucrm";
|
|
|
|
static const char period[] = "{\\pntxta.}";
|
|
|
|
static const char paren[] = "{\\pntxta)}";
|
|
|
|
static const char parens[] = "{\\pntxtb(}{\\pntxta)}";
|
|
|
|
const char *type, *style = "";
|
|
|
|
unsigned int idx;
|
|
|
|
|
|
|
|
find_font_in_fonttbl( stream, ¶->para_num.style->fmt, &idx );
|
|
|
|
|
|
|
|
if (!ME_StreamOutPrint( stream, "{\\pntext\\f%u ", idx )) return FALSE;
|
|
|
|
if (!ME_StreamOutRTFText( stream, para->para_num.text->szData, para->para_num.text->nLen ))
|
|
|
|
return FALSE;
|
|
|
|
if (!ME_StreamOutPrint( stream, "\\tab}" )) return FALSE;
|
|
|
|
|
|
|
|
if (!pn_dest) return TRUE;
|
|
|
|
|
|
|
|
if (para->fmt.wNumbering == PFN_BULLET)
|
|
|
|
{
|
|
|
|
if (!ME_StreamOutPrint( stream, fmt_bullet, idx, para->fmt.wNumberingTab ))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (para->fmt.wNumbering)
|
|
|
|
{
|
|
|
|
case PFN_ARABIC:
|
|
|
|
default:
|
|
|
|
type = dec;
|
|
|
|
break;
|
|
|
|
case PFN_LCLETTER:
|
|
|
|
type = lcltr;
|
|
|
|
break;
|
|
|
|
case PFN_UCLETTER:
|
|
|
|
type = ucltr;
|
|
|
|
break;
|
|
|
|
case PFN_LCROMAN:
|
|
|
|
type = lcrm;
|
|
|
|
break;
|
|
|
|
case PFN_UCROMAN:
|
|
|
|
type = ucrm;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (para->fmt.wNumberingStyle & 0xf00)
|
|
|
|
{
|
|
|
|
case PFNS_PERIOD:
|
|
|
|
style = period;
|
|
|
|
break;
|
|
|
|
case PFNS_PAREN:
|
|
|
|
style = paren;
|
|
|
|
break;
|
|
|
|
case PFNS_PARENS:
|
|
|
|
style = parens;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ME_StreamOutPrint( stream, fmt_label, idx, para->fmt.wNumberingTab,
|
|
|
|
para->fmt.wNumberingStart, type, style ))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-10-20 13:50:35 +02:00
|
|
|
static BOOL stream_out_para_props( ME_TextEditor *editor, ME_OutStream *pStream,
|
|
|
|
ME_Paragraph *para )
|
2008-08-05 01:18:54 +02:00
|
|
|
{
|
2020-10-20 13:50:35 +02:00
|
|
|
PARAFORMAT2 *fmt = ¶->fmt;
|
2008-08-05 01:18:54 +02:00
|
|
|
char props[STREAMOUT_BUFFER_SIZE] = "";
|
|
|
|
int i;
|
2020-10-20 13:50:35 +02:00
|
|
|
ME_Paragraph *prev_para = para_prev( para );
|
2016-10-11 14:04:00 +02:00
|
|
|
|
2020-10-20 13:50:35 +02:00
|
|
|
if (!editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
{
|
|
|
|
if (para->nFlags & MEPF_ROWSTART)
|
|
|
|
{
|
2010-07-17 21:29:28 +02:00
|
|
|
pStream->nNestingLevel++;
|
2020-10-20 13:50:35 +02:00
|
|
|
if (pStream->nNestingLevel == 1)
|
|
|
|
if (!stream_out_table_props( editor, pStream, para )) return FALSE;
|
2010-07-17 21:29:28 +02:00
|
|
|
return TRUE;
|
2020-10-20 13:50:35 +02:00
|
|
|
}
|
|
|
|
else if (para->nFlags & MEPF_ROWEND)
|
|
|
|
{
|
2010-07-17 21:29:28 +02:00
|
|
|
pStream->nNestingLevel--;
|
2020-10-20 13:50:35 +02:00
|
|
|
if (pStream->nNestingLevel >= 1)
|
|
|
|
{
|
|
|
|
if (!ME_StreamOutPrint(pStream, "{\\*\\nesttableprops")) return FALSE;
|
|
|
|
if (!stream_out_table_props( editor, pStream, para )) return FALSE;
|
|
|
|
if (!ME_StreamOutPrint(pStream, "\\nestrow}{\\nonesttables\\par}\r\n")) return FALSE;
|
2010-07-17 21:29:28 +02:00
|
|
|
}
|
2020-10-20 13:50:35 +02:00
|
|
|
else if (!ME_StreamOutPrint(pStream, "\\row\r\n")) return FALSE;
|
2010-07-17 21:29:28 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2020-10-20 13:50:35 +02:00
|
|
|
}
|
|
|
|
else /* v1.0 - 3.0 */
|
|
|
|
{
|
|
|
|
if (para->fmt.dwMask & PFM_TABLE && para->fmt.wEffects & PFE_TABLE)
|
|
|
|
if (!stream_out_table_props( editor, pStream, para )) return FALSE;
|
2010-07-17 21:29:28 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 14:04:00 +02:00
|
|
|
if (prev_para && !memcmp( fmt, &prev_para->fmt, sizeof(*fmt) ))
|
2016-10-12 13:58:52 +02:00
|
|
|
{
|
|
|
|
if (fmt->wNumbering)
|
2020-10-20 13:50:35 +02:00
|
|
|
return stream_out_para_num( pStream, para, FALSE );
|
2016-10-11 14:04:00 +02:00
|
|
|
return TRUE;
|
2016-10-12 13:58:52 +02:00
|
|
|
}
|
2016-10-11 14:04:00 +02:00
|
|
|
|
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
|
|
|
|
2016-10-12 13:58:52 +02:00
|
|
|
if (fmt->wNumbering)
|
2020-10-20 13:50:35 +02:00
|
|
|
if (!stream_out_para_num( pStream, para, TRUE )) return FALSE;
|
2016-10-12 13:58:52 +02:00
|
|
|
|
2020-10-20 13:50:35 +02:00
|
|
|
if (!editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
{
|
|
|
|
if (pStream->nNestingLevel > 0) strcat(props, "\\intbl");
|
|
|
|
if (pStream->nNestingLevel > 1) sprintf(props + strlen(props), "\\itap%d", pStream->nNestingLevel);
|
|
|
|
}
|
|
|
|
else /* v1.0 - 3.0 */
|
|
|
|
{
|
2008-08-07 18:31:41 +02:00
|
|
|
if (fmt->dwMask & PFM_TABLE && fmt->wEffects & PFE_TABLE)
|
|
|
|
strcat(props, "\\intbl");
|
|
|
|
}
|
2016-10-12 13:58:52 +02:00
|
|
|
|
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) */
|
|
|
|
|
2020-10-20 13:50:35 +02:00
|
|
|
if (fmt->dwMask & PFM_ALIGNMENT)
|
|
|
|
{
|
|
|
|
switch (fmt->wAlignment)
|
|
|
|
{
|
2005-03-16 21:18:11 +01:00
|
|
|
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
|
|
|
|
2020-10-20 13:50:35 +02:00
|
|
|
if (fmt->dwMask & PFM_LINESPACING)
|
|
|
|
{
|
2005-03-16 21:18:11 +01:00
|
|
|
/* FIXME: MSDN says that the bLineSpacingRule field is controlled by the
|
|
|
|
* PFM_SPACEAFTER flag. Is that true? I don't believe so. */
|
2020-10-20 13:50:35 +02:00
|
|
|
switch (fmt->bLineSpacingRule)
|
|
|
|
{
|
2005-03-16 21:18:11 +01:00
|
|
|
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))
|
|
|
|
{
|
2016-10-11 14:04:01 +02:00
|
|
|
if (fmt->dxOffset)
|
2008-08-13 05:15:29 +02:00
|
|
|
sprintf(props + strlen(props), "\\li%d", fmt->dxOffset);
|
2016-10-11 14:04:01 +02:00
|
|
|
if (fmt->dxStartIndent)
|
2008-08-13 05:15:29 +02:00
|
|
|
sprintf(props + strlen(props), "\\fi%d", fmt->dxStartIndent);
|
2016-10-11 14:04:01 +02:00
|
|
|
if (fmt->dxRightIndent)
|
2008-08-13 05:15:29 +02:00
|
|
|
sprintf(props + strlen(props), "\\ri%d", fmt->dxRightIndent);
|
|
|
|
if (fmt->dwMask & PFM_TABSTOPS) {
|
|
|
|
static const char * const leader[6] = { "", "\\tldot", "\\tlhyph", "\\tlul", "\\tlth", "\\tleq" };
|
|
|
|
|
2020-10-20 13:50:35 +02:00
|
|
|
for (i = 0; i < fmt->cTabCount; i++)
|
|
|
|
{
|
|
|
|
switch ((fmt->rgxTabs[i] >> 24) & 0xf)
|
|
|
|
{
|
2008-08-13 05:15:29 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 14:04:01 +02:00
|
|
|
if (fmt->dySpaceAfter)
|
2006-10-13 21:25:54 +02:00
|
|
|
sprintf(props + strlen(props), "\\sa%d", fmt->dySpaceAfter);
|
2016-10-11 14:04:01 +02:00
|
|
|
if (fmt->dySpaceBefore)
|
2006-10-13 21:25:54 +02:00
|
|
|
sprintf(props + strlen(props), "\\sb%d", fmt->dySpaceBefore);
|
2016-10-11 14:04:01 +02:00
|
|
|
if (fmt->sStyle != -1)
|
2005-03-16 21:18:11 +01:00
|
|
|
sprintf(props + strlen(props), "\\s%d", fmt->sStyle);
|
|
|
|
|
2020-10-20 13:50:35 +02:00
|
|
|
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]);
|
2017-04-21 12:33:26 +02:00
|
|
|
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);
|
2005-03-16 21:18:11 +01:00
|
|
|
}
|
2016-10-14 11:05:04 +02:00
|
|
|
if (*props)
|
|
|
|
strcat(props, " ");
|
2005-03-16 21:18:11 +01:00
|
|
|
|
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;
|
2016-10-14 11:05:04 +02:00
|
|
|
CHARFORMAT2W *old_fmt = &pStream->cur_fmt;
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
DWORD effect;
|
|
|
|
const char *on, *off;
|
|
|
|
} effects[] =
|
|
|
|
{
|
|
|
|
{ CFE_ALLCAPS, "\\caps", "\\caps0" },
|
|
|
|
{ CFE_BOLD, "\\b", "\\b0" },
|
|
|
|
{ CFE_DISABLED, "\\disabled", "\\disabled0" },
|
|
|
|
{ CFE_EMBOSS, "\\embo", "\\embo0" },
|
|
|
|
{ CFE_HIDDEN, "\\v", "\\v0" },
|
|
|
|
{ CFE_IMPRINT, "\\impr", "\\impr0" },
|
|
|
|
{ CFE_ITALIC, "\\i", "\\i0" },
|
|
|
|
{ CFE_OUTLINE, "\\outl", "\\outl0" },
|
|
|
|
{ CFE_PROTECTED, "\\protect", "\\protect0" },
|
|
|
|
{ CFE_SHADOW, "\\shad", "\\shad0" },
|
|
|
|
{ CFE_SMALLCAPS, "\\scaps", "\\scaps0" },
|
|
|
|
{ CFE_STRIKEOUT, "\\strike", "\\strike0" },
|
|
|
|
};
|
|
|
|
|
2018-09-10 22:49:39 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE( effects ); i++)
|
2016-10-14 11:05:04 +02:00
|
|
|
{
|
|
|
|
if ((old_fmt->dwEffects ^ fmt->dwEffects) & effects[i].effect)
|
|
|
|
strcat( props, fmt->dwEffects & effects[i].effect ? effects[i].on : effects[i].off );
|
|
|
|
}
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2016-10-14 11:05:04 +02:00
|
|
|
if ((old_fmt->dwEffects ^ fmt->dwEffects) & CFE_AUTOBACKCOLOR ||
|
2017-04-05 15:02:08 +02:00
|
|
|
(!(fmt->dwEffects & CFE_AUTOBACKCOLOR) && old_fmt->crBackColor != fmt->crBackColor))
|
2016-10-14 11:05:04 +02:00
|
|
|
{
|
|
|
|
if (fmt->dwEffects & CFE_AUTOBACKCOLOR) i = 0;
|
|
|
|
else find_color_in_colortbl( pStream, fmt->crBackColor, &i );
|
2017-06-05 15:18:40 +02:00
|
|
|
sprintf(props + strlen(props), "\\highlight%u", i);
|
2016-10-14 11:05:04 +02:00
|
|
|
}
|
|
|
|
if ((old_fmt->dwEffects ^ fmt->dwEffects) & CFE_AUTOCOLOR ||
|
2017-04-05 15:02:08 +02:00
|
|
|
(!(fmt->dwEffects & CFE_AUTOCOLOR) && old_fmt->crTextColor != fmt->crTextColor))
|
2016-10-14 11:05:04 +02:00
|
|
|
{
|
|
|
|
if (fmt->dwEffects & CFE_AUTOCOLOR) i = 0;
|
|
|
|
else find_color_in_colortbl( pStream, fmt->crTextColor, &i );
|
2016-10-12 13:58:51 +02:00
|
|
|
sprintf(props + strlen(props), "\\cf%u", i);
|
2016-10-14 11:05:04 +02:00
|
|
|
}
|
2016-10-12 13:58:51 +02:00
|
|
|
|
2016-10-14 11:05:04 +02:00
|
|
|
if (old_fmt->bAnimation != fmt->bAnimation)
|
|
|
|
sprintf(props + strlen(props), "\\animtext%u", fmt->bAnimation);
|
|
|
|
if (old_fmt->wKerning != fmt->wKerning)
|
2005-03-14 22:41:16 +01:00
|
|
|
sprintf(props + strlen(props), "\\kerning%u", fmt->wKerning);
|
2016-10-14 11:05:04 +02:00
|
|
|
|
|
|
|
if (old_fmt->lcid != fmt->lcid)
|
|
|
|
{
|
2005-03-14 22:41:16 +01:00
|
|
|
/* 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));
|
|
|
|
}
|
2016-10-14 11:05:04 +02:00
|
|
|
|
|
|
|
if (old_fmt->yOffset != fmt->yOffset)
|
|
|
|
{
|
2005-03-14 22:41:16 +01:00
|
|
|
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
|
|
|
}
|
2016-10-14 11:05:04 +02:00
|
|
|
if (old_fmt->yHeight != fmt->yHeight)
|
2006-10-13 21:25:54 +02:00
|
|
|
sprintf(props + strlen(props), "\\fs%d", fmt->yHeight / 10);
|
2016-10-14 11:05:04 +02:00
|
|
|
if (old_fmt->sSpacing != fmt->sSpacing)
|
2005-03-14 22:41:16 +01:00
|
|
|
sprintf(props + strlen(props), "\\expnd%u\\expndtw%u", fmt->sSpacing / 5, fmt->sSpacing);
|
2016-10-14 11:05:04 +02:00
|
|
|
if ((old_fmt->dwEffects ^ fmt->dwEffects) & (CFM_SUBSCRIPT | CFM_SUPERSCRIPT))
|
|
|
|
{
|
2005-03-14 22:41:16 +01:00
|
|
|
if (fmt->dwEffects & CFE_SUBSCRIPT)
|
|
|
|
strcat(props, "\\sub");
|
|
|
|
else if (fmt->dwEffects & CFE_SUPERSCRIPT)
|
|
|
|
strcat(props, "\\super");
|
2016-10-14 11:05:04 +02:00
|
|
|
else
|
|
|
|
strcat(props, "\\nosupersub");
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
2016-10-14 11:05:04 +02:00
|
|
|
if ((old_fmt->dwEffects ^ fmt->dwEffects) & CFE_UNDERLINE ||
|
|
|
|
old_fmt->bUnderlineType != fmt->bUnderlineType)
|
2016-10-14 11:05:03 +02:00
|
|
|
{
|
2016-10-14 11:05:04 +02:00
|
|
|
BYTE type = (fmt->dwEffects & CFE_UNDERLINE) ? fmt->bUnderlineType : CFU_UNDERLINENONE;
|
|
|
|
switch (type)
|
2016-10-14 11:05:03 +02:00
|
|
|
{
|
|
|
|
case CFU_UNDERLINE:
|
2005-03-14 22:41:16 +01:00
|
|
|
strcat(props, "\\ul");
|
|
|
|
break;
|
2016-10-14 11:05:03 +02:00
|
|
|
case CFU_UNDERLINEDOTTED:
|
2005-03-14 22:41:16 +01:00
|
|
|
strcat(props, "\\uld");
|
|
|
|
break;
|
2016-10-14 11:05:03 +02:00
|
|
|
case CFU_UNDERLINEDOUBLE:
|
2005-03-14 22:41:16 +01:00
|
|
|
strcat(props, "\\uldb");
|
|
|
|
break;
|
2016-10-14 11:05:03 +02:00
|
|
|
case CFU_UNDERLINEWORD:
|
2005-03-14 22:41:16 +01:00
|
|
|
strcat(props, "\\ulw");
|
|
|
|
break;
|
2016-10-14 11:05:03 +02:00
|
|
|
case CFU_CF1UNDERLINE:
|
|
|
|
case CFU_UNDERLINENONE:
|
|
|
|
default:
|
2013-08-20 00:31:38 +02:00
|
|
|
strcat(props, "\\ulnone");
|
2005-03-14 22:41:16 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-19 10:30:25 +02:00
|
|
|
if (wcscmp(old_fmt->szFaceName, fmt->szFaceName) ||
|
2016-10-14 11:05:04 +02:00
|
|
|
old_fmt->bCharSet != fmt->bCharSet)
|
2016-10-12 13:58:50 +02:00
|
|
|
{
|
|
|
|
if (find_font_in_fonttbl( pStream, fmt, &i ))
|
2005-03-22 17:41:36 +01:00
|
|
|
{
|
2016-10-14 11:05:04 +02: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;
|
2016-10-14 11:05:04 +02:00
|
|
|
*old_fmt = *fmt;
|
2005-03-14 22:41:16 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-06-07 12:18:23 +02:00
|
|
|
static BOOL stream_out_graphics( ME_TextEditor *editor, ME_OutStream *stream,
|
|
|
|
ME_Run *run )
|
|
|
|
{
|
|
|
|
IDataObject *data;
|
|
|
|
HRESULT hr;
|
|
|
|
FORMATETC fmt = { CF_ENHMETAFILE, NULL, DVASPECT_CONTENT, -1, TYMED_ENHMF };
|
|
|
|
STGMEDIUM med = { TYMED_NULL };
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
ENHMETAHEADER *emf_bits = NULL;
|
|
|
|
UINT size;
|
|
|
|
SIZE goal, pic;
|
|
|
|
ME_Context c;
|
|
|
|
|
2018-04-13 09:56:54 +02:00
|
|
|
hr = IOleObject_QueryInterface( run->reobj->obj.poleobj, &IID_IDataObject, (void **)&data );
|
2016-06-07 12:18:23 +02:00
|
|
|
if (FAILED(hr)) return FALSE;
|
|
|
|
|
|
|
|
ME_InitContext( &c, editor, ITextHost_TxGetDC( editor->texthost ) );
|
|
|
|
hr = IDataObject_QueryGetData( data, &fmt );
|
|
|
|
if (hr != S_OK) goto done;
|
|
|
|
|
|
|
|
hr = IDataObject_GetData( data, &fmt, &med );
|
|
|
|
if (FAILED(hr)) goto done;
|
|
|
|
if (med.tymed != TYMED_ENHMF) goto done;
|
|
|
|
|
|
|
|
size = GetEnhMetaFileBits( med.u.hEnhMetaFile, 0, NULL );
|
|
|
|
if (size < FIELD_OFFSET(ENHMETAHEADER, cbPixelFormat)) goto done;
|
|
|
|
|
|
|
|
emf_bits = HeapAlloc( GetProcessHeap(), 0, size );
|
|
|
|
if (!emf_bits) goto done;
|
|
|
|
|
|
|
|
size = GetEnhMetaFileBits( med.u.hEnhMetaFile, size, (BYTE *)emf_bits );
|
|
|
|
if (size < FIELD_OFFSET(ENHMETAHEADER, cbPixelFormat)) goto done;
|
|
|
|
|
|
|
|
/* size_in_pixels = (frame_size / 100) * szlDevice / szlMillimeters
|
|
|
|
pic = size_in_pixels * 2540 / dpi */
|
|
|
|
pic.cx = MulDiv( emf_bits->rclFrame.right - emf_bits->rclFrame.left, emf_bits->szlDevice.cx * 254,
|
|
|
|
emf_bits->szlMillimeters.cx * c.dpi.cx * 10 );
|
|
|
|
pic.cy = MulDiv( emf_bits->rclFrame.bottom - emf_bits->rclFrame.top, emf_bits->szlDevice.cy * 254,
|
|
|
|
emf_bits->szlMillimeters.cy * c.dpi.cy * 10 );
|
|
|
|
|
|
|
|
/* convert goal size to twips */
|
2018-04-13 09:56:54 +02:00
|
|
|
goal.cx = MulDiv( run->reobj->obj.sizel.cx, 144, 254 );
|
|
|
|
goal.cy = MulDiv( run->reobj->obj.sizel.cy, 144, 254 );
|
2016-06-07 12:18:23 +02:00
|
|
|
|
|
|
|
if (!ME_StreamOutPrint( stream, "{\\*\\shppict{\\pict\\emfblip\\picw%d\\pich%d\\picwgoal%d\\pichgoal%d\n",
|
|
|
|
pic.cx, pic.cy, goal.cx, goal.cy ))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (!ME_StreamOutHexData( stream, (BYTE *)emf_bits, size ))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (!ME_StreamOutPrint( stream, "}}\n" ))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
ME_DestroyContext( &c );
|
|
|
|
HeapFree( GetProcessHeap(), 0, emf_bits );
|
|
|
|
ReleaseStgMedium( &med );
|
|
|
|
IDataObject_Release( data );
|
|
|
|
return ret;
|
|
|
|
}
|
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;
|
2020-11-04 07:56:22 +01:00
|
|
|
ME_Paragraph *prev_para = NULL;
|
2009-08-13 14:44:22 +02:00
|
|
|
ME_Cursor endCur = cursor;
|
2009-02-06 07:09:47 +01:00
|
|
|
|
2016-10-04 14:07:33 +02:00
|
|
|
ME_MoveCursorChars(editor, &endCur, nChars, TRUE);
|
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;
|
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
if (!stream_out_font_and_colour_tbls( pStream, cursor.run, endCur.run ))
|
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
|
|
|
|
2017-03-03 11:10:43 +01:00
|
|
|
if (!ME_StreamOutPrint(pStream, "{\\*\\generator Wine Riched20 2.0;}\r\n"))
|
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 */
|
|
|
|
|
2020-11-04 07:56:22 +01:00
|
|
|
do
|
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
if (cursor.para != prev_para)
|
2005-03-15 16:40:52 +01:00
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
prev_para = cursor.para;
|
|
|
|
if (!stream_out_para_props( editor, pStream, cursor.para ))
|
2010-07-17 21:29:28 +02:00
|
|
|
return FALSE;
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
2009-08-13 14:44:22 +02:00
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
if (cursor.run == endCur.run && !endCur.nOffset)
|
2005-03-14 22:41:16 +01:00
|
|
|
break;
|
2020-11-04 07:56:22 +01:00
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
TRACE("flags %xh\n", cursor.run->nFlags);
|
2009-08-13 14:44:22 +02:00
|
|
|
/* TODO: emit embedded objects */
|
2020-11-06 09:32:24 +01:00
|
|
|
if (cursor.para->nFlags & (MEPF_ROWSTART | MEPF_ROWEND))
|
2010-07-17 21:29:08 +02:00
|
|
|
continue;
|
2020-11-06 09:32:24 +01:00
|
|
|
if (cursor.run->nFlags & MERF_GRAPHICS)
|
2020-11-04 07:56:22 +01:00
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
if (!stream_out_graphics( editor, pStream, cursor.run ))
|
2016-06-07 12:18:23 +02:00
|
|
|
return FALSE;
|
2020-11-04 07:56:22 +01:00
|
|
|
}
|
2020-11-06 09:32:24 +01:00
|
|
|
else if (cursor.run->nFlags & MERF_TAB)
|
2020-11-04 07:56:22 +01:00
|
|
|
{
|
2009-08-13 14:44:22 +02:00
|
|
|
if (editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
2020-11-06 09:32:24 +01:00
|
|
|
para_in_table( cursor.para ))
|
2009-08-13 14:44:22 +02:00
|
|
|
{
|
|
|
|
if (!ME_StreamOutPrint(pStream, "\\cell "))
|
|
|
|
return FALSE;
|
2020-11-04 07:56:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-13 14:44:22 +02:00
|
|
|
if (!ME_StreamOutPrint(pStream, "\\tab "))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-11-04 07:56:22 +01:00
|
|
|
}
|
2020-11-06 09:32:24 +01:00
|
|
|
else if (cursor.run->nFlags & MERF_ENDCELL)
|
2020-11-04 07:56:22 +01:00
|
|
|
{
|
|
|
|
if (pStream->nNestingLevel > 1)
|
|
|
|
{
|
2009-08-13 14:44:22 +02:00
|
|
|
if (!ME_StreamOutPrint(pStream, "\\nestcell "))
|
|
|
|
return FALSE;
|
2020-11-04 07:56:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-13 14:44:22 +02:00
|
|
|
if (!ME_StreamOutPrint(pStream, "\\cell "))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
nChars--;
|
2020-11-04 07:56:22 +01:00
|
|
|
}
|
2020-11-06 09:32:24 +01:00
|
|
|
else if (cursor.run->nFlags & MERF_ENDPARA)
|
2020-11-04 07:56:22 +01:00
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
if (!ME_StreamOutRTFCharProps( pStream, &cursor.run->style->fmt ))
|
2017-03-03 11:10:41 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
if (para_in_table( cursor.para ) &&
|
|
|
|
!(cursor.para->nFlags & (MEPF_ROWSTART | MEPF_ROWEND | MEPF_CELL)))
|
2009-08-13 14:44:22 +02:00
|
|
|
{
|
2016-10-14 11:05:07 +02:00
|
|
|
if (!ME_StreamOutPrint(pStream, "\\row\r\n"))
|
2009-08-13 14:44:22 +02:00
|
|
|
return FALSE;
|
2020-11-04 07:56:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-14 11:05:04 +02:00
|
|
|
if (!ME_StreamOutPrint(pStream, "\\par\r\n"))
|
2009-08-13 14:44:22 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* Skip as many characters as required by current line break */
|
2020-11-06 09:32:24 +01:00
|
|
|
nChars = max(0, nChars - cursor.run->len);
|
2020-11-04 07:56:22 +01:00
|
|
|
}
|
2020-11-06 09:32:24 +01:00
|
|
|
else if (cursor.run->nFlags & MERF_ENDROW)
|
2020-11-04 07:56:22 +01:00
|
|
|
{
|
2016-10-14 11:05:07 +02:00
|
|
|
if (!ME_StreamOutPrint(pStream, "\\line\r\n"))
|
2009-08-13 14:44:22 +02:00
|
|
|
return FALSE;
|
|
|
|
nChars--;
|
2020-11-04 07:56:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-13 14:44:22 +02:00
|
|
|
int nEnd;
|
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
TRACE("style %p\n", cursor.run->style);
|
|
|
|
if (!ME_StreamOutRTFCharProps( pStream, &cursor.run->style->fmt ))
|
2009-08-13 14:44:22 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
nEnd = (cursor.run == endCur.run) ? endCur.nOffset : cursor.run->len;
|
|
|
|
if (!ME_StreamOutRTFText(pStream, get_text( cursor.run, cursor.nOffset ),
|
2009-08-13 14:44:22 +02:00
|
|
|
nEnd - cursor.nOffset))
|
|
|
|
return FALSE;
|
|
|
|
cursor.nOffset = 0;
|
|
|
|
}
|
2020-11-06 09:32:24 +01:00
|
|
|
} while (cursor.run != endCur.run && cursor_next_run( &cursor, TRUE ));
|
2009-08-13 14:44:22 +02:00
|
|
|
|
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;
|
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
if (!cursor.run)
|
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
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
while (success && nChars && cursor.run)
|
|
|
|
{
|
|
|
|
nLen = min(nChars, cursor.run->len - cursor.nOffset);
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
if (!editor->bEmulateVersion10 && cursor.run->nFlags & MERF_ENDPARA)
|
2009-01-28 07:34:56 +01:00
|
|
|
{
|
|
|
|
/* richedit 2.0 - all line breaks are \r\n */
|
|
|
|
if (dwFormat & SF_UNICODE)
|
2020-11-15 23:11:16 +01:00
|
|
|
success = ME_StreamOutMove(pStream, (const char *)L"\r\n", 2 * sizeof(WCHAR));
|
2009-01-28 07:34:56 +01:00
|
|
|
else
|
|
|
|
success = ME_StreamOutMove(pStream, "\r\n", 2);
|
2005-03-14 22:41:16 +01:00
|
|
|
} else {
|
|
|
|
if (dwFormat & SF_UNICODE)
|
2020-11-06 09:32:24 +01:00
|
|
|
success = ME_StreamOutMove(pStream, (const char *)(get_text( cursor.run, cursor.nOffset )),
|
2005-03-14 22:41:16 +01:00
|
|
|
sizeof(WCHAR) * nLen);
|
|
|
|
else {
|
|
|
|
int nSize;
|
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
nSize = WideCharToMultiByte(nCodePage, 0, get_text( cursor.run, cursor.nOffset ),
|
2005-03-14 22:41:16 +01:00
|
|
|
nLen, NULL, 0, NULL, NULL);
|
|
|
|
if (nSize > nBufLen) {
|
2018-02-03 23:59:46 +01:00
|
|
|
buffer = heap_realloc(buffer, nSize);
|
2005-03-14 22:41:16 +01:00
|
|
|
nBufLen = nSize;
|
|
|
|
}
|
2020-11-06 09:32:24 +01:00
|
|
|
WideCharToMultiByte(nCodePage, 0, get_text( cursor.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;
|
2020-11-06 09:32:24 +01:00
|
|
|
cursor.run = run_next_all_paras( cursor.run );
|
2005-03-14 22:41:16 +01:00
|
|
|
}
|
2009-01-28 07:34:56 +01:00
|
|
|
|
2018-02-03 23:59:46 +01:00
|
|
|
heap_free(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
|
|
|
}
|