2 * RichEdit - RTF writer module
4 * Copyright 2005 by Phil Krylov
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
27 ME_StreamOutRTFText(ME_TextEditor *editor, WCHAR *text, LONG nChars);
31 ME_StreamOutInit(ME_TextEditor *editor, EDITSTREAM *stream)
33 editor->pStream = ALLOC_OBJ(ME_OutStream);
34 editor->pStream->stream = stream;
35 editor->pStream->pos = 0;
36 editor->pStream->written = 0;
37 editor->pStream->nFontTblLen = 0;
38 editor->pStream->nColorTblLen = 1;
43 ME_StreamOutFlush(ME_TextEditor *editor)
47 EDITSTREAM *stream = editor->pStream->stream;
50 stream->dwError = stream->pfnCallback(stream->dwCookie, editor->pStream->buffer + nStart,
51 editor->pStream->pos - nStart, &nWritten);
52 if (nWritten == 0 || stream->dwError)
54 editor->pStream->written += nWritten;
56 } while (nStart < editor->pStream->pos);
57 editor->pStream->pos = 0;
63 ME_StreamOutFree(ME_TextEditor *editor)
65 LONG written = editor->pStream->written;
67 FREE_OBJ(editor->pStream);
68 editor->pStream = NULL;
74 ME_StreamOutMove(ME_TextEditor *editor, BYTE *buffer, int len)
76 ME_OutStream *pStream = editor->pStream;
79 int space = STREAMOUT_BUFFER_SIZE - pStream->pos;
80 int fit = min(space, len);
82 TRACE("%u:%u:%.*s\n", pStream->pos, fit, fit, buffer);
83 memmove(pStream->buffer + pStream->pos, buffer, fit);
87 if (pStream->pos == STREAMOUT_BUFFER_SIZE) {
88 if (!ME_StreamOutFlush(editor))
97 ME_StreamOutPrint(ME_TextEditor *editor, char *format, ...)
99 char string[STREAMOUT_BUFFER_SIZE]; /* This is going to be enough */
103 va_start(valist, format);
104 len = vsnprintf(string, sizeof(string), format, valist);
107 return ME_StreamOutMove(editor, string, len);
112 ME_StreamOutRTFHeader(ME_TextEditor *editor, int dwFormat)
114 char *cCharSet = NULL;
119 if (dwFormat & SF_USECODEPAGE) {
122 switch (HIWORD(dwFormat)) {
125 nCodePage = GetACP();
128 nCodePage = GetOEMCP();
129 if (nCodePage == 437)
131 else if (nCodePage == 850)
140 if (HIWORD(dwFormat) == CP_MACCP) {
142 nCodePage = 10000; /* MacRoman */
145 nCodePage = 1252; /* Latin-1 */
147 if (GetCPInfoExW(HIWORD(dwFormat), 0, &info))
148 nCodePage = info.CodePage;
152 nCodePage = GetACP();
154 if (nCodePage == CP_UTF8)
155 success = ME_StreamOutPrint(editor, "{\\urtf");
157 success = ME_StreamOutPrint(editor, "{\\rtf1\\%s\\ansicpg%u\\uc1", cCharSet, nCodePage);
162 editor->pStream->nCodePage = nCodePage;
164 /* FIXME: This should be a document property */
165 /* TODO: handle SFF_PLAINRTF */
166 language = GetUserDefaultLangID();
167 if (!ME_StreamOutPrint(editor, "\\deff0\\deflang%u\\deflangfe%u", language, language))
170 /* FIXME: This should be a document property */
171 editor->pStream->nDefaultFont = 0;
178 ME_StreamOutRTFFontAndColorTbl(ME_TextEditor *editor, ME_DisplayItem *pFirstRun, ME_DisplayItem *pLastRun)
180 ME_DisplayItem *item = pFirstRun;
181 ME_FontTableItem *table = editor->pStream->fonttbl;
185 CHARFORMAT2W *fmt = &item->member.run.style->fmt;
188 if (fmt->dwMask & CFM_FACE) {
189 WCHAR *face = fmt->szFaceName;
190 BYTE bCharSet = fmt->bCharSet;
192 for (i = 0; i < editor->pStream->nFontTblLen; i++)
193 if (table[i].bCharSet == bCharSet
194 && (table[i].szFaceName == face || !lstrcmpW(table[i].szFaceName, face)))
196 if (i == editor->pStream->nFontTblLen) {
197 table[i].bCharSet = bCharSet;
198 table[i].szFaceName = face;
199 editor->pStream->nFontTblLen++;
203 if (fmt->dwMask & CFM_COLOR && !(fmt->dwEffects & CFE_AUTOCOLOR)) {
204 crColor = fmt->crTextColor;
205 for (i = 1; i < editor->pStream->nColorTblLen; i++)
206 if (editor->pStream->colortbl[i] == crColor)
208 if (i == editor->pStream->nColorTblLen) {
209 editor->pStream->colortbl[i] = crColor;
210 editor->pStream->nColorTblLen++;
213 if (fmt->dwMask & CFM_BACKCOLOR && !(fmt->dwEffects & CFE_AUTOBACKCOLOR)) {
214 crColor = fmt->crBackColor;
215 for (i = 1; i < editor->pStream->nColorTblLen; i++)
216 if (editor->pStream->colortbl[i] == crColor)
218 if (i == editor->pStream->nColorTblLen) {
219 editor->pStream->colortbl[i] = crColor;
220 editor->pStream->nColorTblLen++;
224 if (item == pLastRun)
226 item = ME_FindItemFwd(item, diRun);
229 if (!ME_StreamOutPrint(editor, "{\\fonttbl"))
232 for (i = 0; i < editor->pStream->nFontTblLen; i++) {
233 if (table[i].bCharSet) {
234 if (!ME_StreamOutPrint(editor, "{\\f%u\\fcharset%u ", i, table[i].bCharSet))
237 if (!ME_StreamOutPrint(editor, "{\\f%u ", i))
240 if (!ME_StreamOutRTFText(editor, table[i].szFaceName, -1))
242 if (!ME_StreamOutPrint(editor, ";}\r\n"))
245 if (!ME_StreamOutPrint(editor, "}"))
248 /* Output colors table if not empty */
249 if (editor->pStream->nColorTblLen > 1) {
250 if (!ME_StreamOutPrint(editor, "{\\colortbl;"))
252 for (i = 1; i < editor->pStream->nColorTblLen; i++) {
253 if (!ME_StreamOutPrint(editor, "\\red%u\\green%u\\blue%u;",
254 editor->pStream->colortbl[i] & 0xFF,
255 (editor->pStream->colortbl[i] >> 8) & 0xFF,
256 (editor->pStream->colortbl[i] >> 16) & 0xFF))
259 if (!ME_StreamOutPrint(editor, "}"))
268 ME_StreamOutRTFParaProps(ME_TextEditor *editor, ME_DisplayItem *para)
270 PARAFORMAT2 *fmt = para->member.para.pFmt;
271 char props[STREAMOUT_BUFFER_SIZE] = "";
274 /* TODO: Don't emit anything if the last PARAFORMAT2 is inherited */
275 if (!ME_StreamOutPrint(editor, "\\pard"))
278 /* TODO: PFM_BORDER. M$ does not emit any keywords for these properties, and
279 * when streaming border keywords in, PFM_BORDER is set, but wBorder field is
280 * set very different from the documentation.
281 * (Tested with RichEdit 5.50.25.0601) */
283 if (fmt->dwMask & PFM_ALIGNMENT) {
284 switch (fmt->wAlignment) {
286 /* Default alignment: not emitted */
289 strcat(props, "\\qr");
292 strcat(props, "\\qc");
295 strcat(props, "\\qj");
300 if (fmt->dwMask & PFM_LINESPACING) {
301 /* FIXME: MSDN says that the bLineSpacingRule field is controlled by the
302 * PFM_SPACEAFTER flag. Is that true? I don't believe so. */
303 switch (fmt->bLineSpacingRule) {
304 case 0: /* Single spacing */
305 strcat(props, "\\sl-240\\slmult1");
307 case 1: /* 1.5 spacing */
308 strcat(props, "\\sl-360\\slmult1");
310 case 2: /* Double spacing */
311 strcat(props, "\\sl-480\\slmult1");
314 sprintf(props + strlen(props), "\\sl%ld\\slmult0", fmt->dyLineSpacing);
317 sprintf(props + strlen(props), "\\sl-%ld\\slmult0", fmt->dyLineSpacing);
320 sprintf(props + strlen(props), "\\sl-%ld\\slmult1", fmt->dyLineSpacing * 240 / 20);
325 if (fmt->dwMask & PFM_DONOTHYPHEN && fmt->wEffects & PFE_DONOTHYPHEN)
326 strcat(props, "\\hyph0");
327 if (fmt->dwMask & PFM_KEEP && fmt->wEffects & PFE_KEEP)
328 strcat(props, "\\keep");
329 if (fmt->dwMask & PFM_KEEPNEXT && fmt->wEffects & PFE_KEEPNEXT)
330 strcat(props, "\\keepn");
331 if (fmt->dwMask & PFM_NOLINENUMBER && fmt->wEffects & PFE_NOLINENUMBER)
332 strcat(props, "\\noline");
333 if (fmt->dwMask & PFM_NOWIDOWCONTROL && fmt->wEffects & PFE_NOWIDOWCONTROL)
334 strcat(props, "\\nowidctlpar");
335 if (fmt->dwMask & PFM_PAGEBREAKBEFORE && fmt->wEffects & PFE_PAGEBREAKBEFORE)
336 strcat(props, "\\pagebb");
337 if (fmt->dwMask & PFM_RTLPARA && fmt->wEffects & PFE_RTLPARA)
338 strcat(props, "\\rtlpar");
339 if (fmt->dwMask & PFM_SIDEBYSIDE && fmt->wEffects & PFE_SIDEBYSIDE)
340 strcat(props, "\\sbys");
341 if (fmt->dwMask & PFM_TABLE && fmt->dwMask & PFE_TABLE)
342 strcat(props, "\\intbl");
344 if (fmt->dwMask & PFM_OFFSET)
345 sprintf(props + strlen(props), "\\li%ld", fmt->dxOffset);
346 if (fmt->dwMask & PFM_OFFSETINDENT || fmt->dwMask & PFM_STARTINDENT)
347 sprintf(props + strlen(props), "\\fi%ld", fmt->dxStartIndent);
348 if (fmt->dwMask & PFM_RIGHTINDENT)
349 sprintf(props + strlen(props), "\\ri%ld", fmt->dxRightIndent);
350 if (fmt->dwMask & PFM_SPACEAFTER)
351 sprintf(props + strlen(props), "\\sa%ld", fmt->dySpaceAfter);
352 if (fmt->dwMask & PFM_SPACEBEFORE)
353 sprintf(props + strlen(props), "\\sb%ld", fmt->dySpaceBefore);
354 if (fmt->dwMask & PFM_STYLE)
355 sprintf(props + strlen(props), "\\s%d", fmt->sStyle);
357 if (fmt->dwMask & PFM_TABSTOPS) {
358 static const char *leader[6] = { "", "\\tldot", "\\tlhyph", "\\tlul", "\\tlth", "\\tleq" };
360 for (i = 0; i < fmt->cTabCount; i++) {
361 switch ((fmt->rgxTabs[i] >> 24) & 0xF) {
363 strcat(props, "\\tqc");
366 strcat(props, "\\tqr");
369 strcat(props, "\\tqdec");
372 /* Word bar tab (vertical bar). Handled below */
375 if (fmt->rgxTabs[i] >> 28 <= 5)
376 strcat(props, leader[fmt->rgxTabs[i] >> 28]);
381 if (fmt->dwMask & PFM_SHADING) {
382 static const char *style[16] = { "", "\\bgdkhoriz", "\\bgdkvert", "\\bgdkfdiag",
383 "\\bgdkbdiag", "\\bgdkcross", "\\bgdkdcross",
384 "\\bghoriz", "\\bgvert", "\\bgfdiag",
385 "\\bgbdiag", "\\bgcross", "\\bgdcross",
387 if (fmt->wShadingWeight)
388 sprintf(props + strlen(props), "\\shading%d", fmt->wShadingWeight);
389 if (fmt->wShadingStyle & 0xF)
390 strcat(props, style[fmt->wShadingStyle & 0xF]);
391 sprintf(props + strlen(props), "\\cfpat%d\\cbpat%d",
392 (fmt->wShadingStyle >> 4) & 0xF, (fmt->wShadingStyle >> 8) & 0xF);
395 if (*props && !ME_StreamOutPrint(editor, props))
403 ME_StreamOutRTFCharProps(ME_TextEditor *editor, CHARFORMAT2W *fmt)
405 char props[STREAMOUT_BUFFER_SIZE] = "";
408 if (fmt->dwMask & CFM_ALLCAPS && fmt->dwEffects & CFE_ALLCAPS)
409 strcat(props, "\\caps");
410 if (fmt->dwMask & CFM_ANIMATION)
411 sprintf(props + strlen(props), "\\animtext%u", fmt->bAnimation);
412 if (fmt->dwMask & CFM_BACKCOLOR) {
413 if (!(fmt->dwEffects & CFE_AUTOBACKCOLOR)) {
414 for (i = 1; i < editor->pStream->nColorTblLen; i++)
415 if (editor->pStream->colortbl[i] == fmt->crBackColor) {
416 sprintf(props + strlen(props), "\\cb%u", i);
421 if (fmt->dwMask & CFM_BOLD && fmt->dwEffects & CFE_BOLD)
422 strcat(props, "\\b");
423 if (fmt->dwMask & CFM_COLOR) {
424 if (!(fmt->dwEffects & CFE_AUTOCOLOR)) {
425 for (i = 1; i < editor->pStream->nColorTblLen; i++)
426 if (editor->pStream->colortbl[i] == fmt->crTextColor) {
427 sprintf(props + strlen(props), "\\cf%u", i);
432 /* TODO: CFM_DISABLED */
433 if (fmt->dwMask & CFM_EMBOSS && fmt->dwEffects & CFE_EMBOSS)
434 strcat(props, "\\embo");
435 if (fmt->dwMask & CFM_HIDDEN && fmt->dwEffects & CFE_HIDDEN)
436 strcat(props, "\\v");
437 if (fmt->dwMask & CFM_IMPRINT && fmt->dwEffects & CFE_IMPRINT)
438 strcat(props, "\\impr");
439 if (fmt->dwMask & CFM_ITALIC && fmt->dwEffects & CFE_ITALIC)
440 strcat(props, "\\i");
441 if (fmt->dwMask & CFM_KERNING)
442 sprintf(props + strlen(props), "\\kerning%u", fmt->wKerning);
443 if (fmt->dwMask & CFM_LCID) {
444 /* TODO: handle SFF_PLAINRTF */
445 if (LOWORD(fmt->lcid) == 1024)
446 strcat(props, "\\noproof\\lang1024\\langnp1024\\langfe1024\\langfenp1024");
448 sprintf(props + strlen(props), "\\lang%u", LOWORD(fmt->lcid));
450 /* CFM_LINK is not streamed out by M$ */
451 if (fmt->dwMask & CFM_OFFSET) {
452 if (fmt->yOffset >= 0)
453 sprintf(props + strlen(props), "\\up%ld", fmt->yOffset);
455 sprintf(props + strlen(props), "\\dn%ld", -fmt->yOffset);
457 if (fmt->dwMask & CFM_OUTLINE && fmt->dwEffects & CFE_OUTLINE)
458 strcat(props, "\\outl");
459 if (fmt->dwMask & CFM_PROTECTED && fmt->dwEffects & CFE_PROTECTED)
460 strcat(props, "\\protect");
461 /* TODO: CFM_REVISED CFM_REVAUTHOR - probably using rsidtbl? */
462 if (fmt->dwMask & CFM_SHADOW && fmt->dwEffects & CFE_SHADOW)
463 strcat(props, "\\shad");
464 if (fmt->dwMask & CFM_SIZE)
465 sprintf(props + strlen(props), "\\fs%ld", fmt->yHeight / 10);
466 if (fmt->dwMask & CFM_SMALLCAPS && fmt->dwEffects & CFE_SMALLCAPS)
467 strcat(props, "\\scaps");
468 if (fmt->dwMask & CFM_SPACING)
469 sprintf(props + strlen(props), "\\expnd%u\\expndtw%u", fmt->sSpacing / 5, fmt->sSpacing);
470 if (fmt->dwMask & CFM_STRIKEOUT && fmt->dwEffects & CFE_STRIKEOUT)
471 strcat(props, "\\strike");
472 if (fmt->dwMask & CFM_STYLE) {
473 sprintf(props + strlen(props), "\\cs%u", fmt->sStyle);
474 /* TODO: emit style contents here */
476 if (fmt->dwMask & (CFM_SUBSCRIPT | CFM_SUPERSCRIPT)) {
477 if (fmt->dwEffects & CFE_SUBSCRIPT)
478 strcat(props, "\\sub");
479 else if (fmt->dwEffects & CFE_SUPERSCRIPT)
480 strcat(props, "\\super");
482 if (fmt->dwMask & CFM_UNDERLINE || fmt->dwMask & CFM_UNDERLINETYPE) {
483 if (fmt->dwMask & CFM_UNDERLINETYPE)
484 switch (fmt->bUnderlineType) {
485 case CFU_CF1UNDERLINE:
487 strcat(props, "\\ul");
489 case CFU_UNDERLINEDOTTED:
490 strcat(props, "\\uld");
492 case CFU_UNDERLINEDOUBLE:
493 strcat(props, "\\uldb");
495 case CFU_UNDERLINEWORD:
496 strcat(props, "\\ulw");
498 case CFU_UNDERLINENONE:
500 strcat(props, "\\ul0");
503 else if (fmt->dwEffects & CFE_UNDERLINE)
504 strcat(props, "\\ul");
506 /* FIXME: How to emit CFM_WEIGHT? */
508 if (fmt->dwMask & CFM_FACE || fmt->dwMask & CFM_CHARSET) {
511 if (fmt->dwMask & CFM_FACE)
512 szFaceName = fmt->szFaceName;
514 szFaceName = editor->pStream->fonttbl[0].szFaceName;
515 for (i = 0; i < editor->pStream->nFontTblLen; i++) {
516 if (szFaceName == editor->pStream->fonttbl[i].szFaceName
517 || !lstrcmpW(szFaceName, editor->pStream->fonttbl[i].szFaceName))
518 if (!(fmt->dwMask & CFM_CHARSET)
519 || fmt->bCharSet == editor->pStream->fonttbl[i].bCharSet)
522 if (i < editor->pStream->nFontTblLen && i != editor->pStream->nDefaultFont)
523 sprintf(props + strlen(props), "\\f%u", i);
527 if (!ME_StreamOutPrint(editor, props))
534 ME_StreamOutRTFText(ME_TextEditor *editor, WCHAR *text, LONG nChars)
536 char buffer[STREAMOUT_BUFFER_SIZE];
541 nChars = lstrlenW(text);
544 if (editor->pStream->nCodePage == CP_UTF8) {
545 /* 6 is the maximum character length in UTF-8 */
546 fit = min(nChars, STREAMOUT_BUFFER_SIZE / 6);
547 WideCharToMultiByte(CP_UTF8, 0, text, fit, buffer, STREAMOUT_BUFFER_SIZE,
551 for (i = 0; buffer[i]; i++)
552 if (buffer[i] == '{' || buffer[i] == '}' || buffer[i] == '\\') {
553 if (!ME_StreamOutPrint(editor, "%.*s\\", i - pos, buffer + pos))
558 if (!ME_StreamOutPrint(editor, "%s", buffer + pos))
561 } else if (*text < 128) {
562 if (*text == '{' || *text == '}' || *text == '\\')
563 buffer[pos++] = '\\';
564 buffer[pos++] = (char)(*text++);
570 WideCharToMultiByte(editor->pStream->nCodePage, 0, text, 1, letter, 2,
573 pos += sprintf(buffer + pos, "\\u%d?", (int)*text);
574 else if (*letter < 128) {
575 if (*letter == '{' || *letter == '}' || *letter == '\\')
576 buffer[pos++] = '\\';
577 buffer[pos++] = *letter;
579 pos += sprintf(buffer + pos, "\\'%02x", *letter);
583 if (pos >= STREAMOUT_BUFFER_SIZE - 10) {
584 if (!ME_StreamOutMove(editor, buffer, pos))
589 return ME_StreamOutMove(editor, buffer, pos);
594 ME_StreamOutRTF(ME_TextEditor *editor, int nStart, int nChars, int dwFormat)
596 ME_DisplayItem *p, *pEnd;
597 int nOffset, nEndLen;
598 ME_RunOfsFromCharOfs(editor, nStart, &p, &nOffset);
599 ME_RunOfsFromCharOfs(editor, nStart+nChars, &pEnd, &nEndLen);
601 if (!ME_StreamOutRTFHeader(editor, dwFormat))
604 if (!ME_StreamOutRTFFontAndColorTbl(editor, p, pEnd))
607 /* TODO: stylesheet table */
609 /* FIXME: maybe emit something smarter for the generator? */
610 if (!ME_StreamOutPrint(editor, "{\\*\\generator Wine Riched20 2.0.????;}"))
613 /* TODO: information group */
615 /* TODO: document formatting properties */
617 /* FIXME: We have only one document section */
619 /* TODO: section formatting properties */
621 if (!ME_StreamOutRTFParaProps(editor, ME_GetParagraph(p)))
629 if (!ME_StreamOutRTFParaProps(editor, p))
633 if (p == pEnd && !nEndLen)
635 TRACE("flags %xh\n", p->member.run.nFlags);
636 /* TODO: emit embedded objects */
637 if (p->member.run.nFlags & MERF_GRAPHICS)
638 FIXME("embedded objects are not handled\n");
639 if (p->member.run.nFlags & MERF_ENDPARA) {
640 if (!ME_StreamOutPrint(editor, "\r\n\\par"))
646 if (!ME_StreamOutPrint(editor, "{"))
648 TRACE("style %p\n", p->member.run.style);
649 if (!ME_StreamOutRTFCharProps(editor, &p->member.run.style->fmt))
652 nEnd = (p == pEnd) ? nEndLen : ME_StrLen(p->member.run.strText);
653 if (!ME_StreamOutRTFText(editor, p->member.run.strText->szData + nOffset, nEnd - nOffset))
656 if (!ME_StreamOutPrint(editor, "}"))
660 default: /* we missed the last item */
665 p = ME_FindItemFwd(p, diRunOrParagraphOrEnd);
667 if (!ME_StreamOutPrint(editor, "}"))
674 ME_StreamOutText(ME_TextEditor *editor, int nStart, int nChars, DWORD dwFormat)
676 /* FIXME: use ME_RunOfsFromCharOfs */
677 ME_DisplayItem *item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
679 UINT nCodePage = CP_ACP;
687 if (dwFormat & SF_USECODEPAGE)
688 nCodePage = HIWORD(dwFormat);
690 /* TODO: Handle SF_TEXTIZED */
692 while (success && nChars && item) {
693 nLen = ME_StrLen(item->member.run.strText) - nStart;
697 if (item->member.run.nFlags & MERF_ENDPARA) {
698 WCHAR szEOL[] = { '\r', '\n' };
700 if (dwFormat & SF_UNICODE)
701 success = ME_StreamOutMove(editor, (BYTE *)szEOL, 4);
703 success = ME_StreamOutMove(editor, "\r\n", 2);
705 if (dwFormat & SF_UNICODE)
706 success = ME_StreamOutMove(editor, (BYTE *)(item->member.run.strText->szData + nStart),
707 sizeof(WCHAR) * nLen);
711 nSize = WideCharToMultiByte(nCodePage, 0, item->member.run.strText->szData + nStart,
712 nLen, NULL, 0, NULL, NULL);
713 if (nSize > nBufLen) {
716 buffer = ALLOC_N_OBJ(BYTE, nSize);
719 WideCharToMultiByte(nCodePage, 0, item->member.run.strText->szData + nStart,
720 nLen, buffer, nSize, NULL, NULL);
721 success = ME_StreamOutMove(editor, buffer, nSize - 1);
727 item = ME_FindItemFwd(item, diRun);
737 ME_StreamOut(ME_TextEditor *editor, DWORD dwFormat, EDITSTREAM *stream)
741 ME_StreamOutInit(editor, stream);
743 if (dwFormat & SFF_SELECTION)
744 ME_GetSelection(editor, &nStart, &nTo);
750 nTo = ME_GetTextLength(editor);
751 TRACE("from %d to %d\n", nStart, nTo);
753 if (dwFormat & SF_RTF || dwFormat & SF_RTFNOOBJS)
754 ME_StreamOutRTF(editor, nStart, nTo - nStart, dwFormat);
755 else if (dwFormat & SF_TEXT || dwFormat & SF_TEXTIZED)
756 ME_StreamOutText(editor, nStart, nTo - nStart, dwFormat);
758 ME_StreamOutFlush(editor);
759 return ME_StreamOutFree(editor);