summaryrefslogtreecommitdiffstats
path: root/svtools/source/svrtf/rtfout.cxx
diff options
context:
space:
mode:
authorJens-Heiner Rechtien <hr@openoffice.org>2003-11-05 13:23:57 +0000
committerJens-Heiner Rechtien <hr@openoffice.org>2003-11-05 13:23:57 +0000
commit01abc4e16ec5d11f1810e63c864b55ae8057459c (patch)
tree7a1b90c8812bce90578533dce16a37e9c9b8b2ed /svtools/source/svrtf/rtfout.cxx
parentstart up problems of svdem.exe fixed (diff)
downloadcore-01abc4e16ec5d11f1810e63c864b55ae8057459c.tar.gz
core-01abc4e16ec5d11f1810e63c864b55ae8057459c.zip
INTEGRATION: CWS kilkennyfilterteam14 (1.2.364); FILE MERGED
2003/09/19 15:28:16 cmc 1.2.364.1: #i10538# add support for exporting ansi fallback characters when exporting unicode characters (note multibyte characters are possible) and because word and wordpad don't allow this in fontnames then add a new method to not use these fallbacks
Diffstat (limited to 'svtools/source/svrtf/rtfout.cxx')
-rw-r--r--svtools/source/svrtf/rtfout.cxx195
1 files changed, 120 insertions, 75 deletions
diff --git a/svtools/source/svrtf/rtfout.cxx b/svtools/source/svrtf/rtfout.cxx
index 9ec588f2b3c2..50ecb1b739a9 100644
--- a/svtools/source/svrtf/rtfout.cxx
+++ b/svtools/source/svrtf/rtfout.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: rtfout.cxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: obo $ $Date: 2003-10-20 16:00:34 $
+ * last change: $Author: hr $ $Date: 2003-11-05 14:23:57 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -68,6 +68,12 @@
#ifndef _STRING_HXX
#include <tools/string.hxx>
#endif
+#ifndef _RTL_STRING_HXX_
+#include <rtl/string.hxx>
+#endif
+#ifndef _RTL_USTRBUF_HXX_
+#include <rtl/ustrbuf.hxx>
+#endif
#ifndef _RTFKEYWD_HXX
#include <rtfkeywd.hxx>
@@ -76,6 +82,7 @@
#include <rtfout.hxx>
#endif
+using namespace rtl;
#if defined(MAC)
const sal_Char RTFOutFuncs::sNewLine = '\015';
@@ -86,108 +93,146 @@ const sal_Char __FAR_DATA RTFOutFuncs::sNewLine[] = "\015\012";
#endif
-// ER 01.04.99 diese Methode wurde aus sw/source/filter/rtf/rtfatr.cxx
-// Writer& OutRTF_SwChar( Writer& rWrt, BYTE c ) kopiert und angepasst
-SvStream& RTFOutFuncs::Out_Char( SvStream& rStream, sal_Unicode c,
- rtl_TextEncoding eDestEnc, BOOL bWriteHelpFile )
+SvStream& RTFOutFuncs::Out_Char(SvStream& rStream, sal_Unicode c,
+ int *pUCMode, rtl_TextEncoding eDestEnc, BOOL bWriteHelpFile)
{
const sal_Char* pStr = 0;
- switch( c )
+ switch (c)
{
- case 0x1: // this are control character of our textattributes and
- case 0x2: // will never be written
- break;
-
- case 0xA0: rStream << "\\~"; break;
- case 0xAD: rStream << "\\-"; break;
- case 0x2011: rStream << "\\_"; break;
- case '\n': pStr = sRTF_LINE; break;
- case '\t': pStr = sRTF_TAB; break;
-
+ case 0x1:
+ case 0x2:
+ // this are control character of our textattributes and will never be
+ // written
+ break;
+ case 0xA0:
+ rStream << "\\~";
+ break;
+ case 0xAD:
+ rStream << "\\-";
+ break;
+ case 0x2011:
+ rStream << "\\_";
+ break;
+ case '\n':
+ pStr = sRTF_LINE;
+ break;
+ case '\t':
+ pStr = sRTF_TAB;
+ break;
default:
+ if(!bWriteHelpFile)
{
- sal_Unicode cCh = c;
- c = (BYTE)ByteString::ConvertFromUnicode( c, eDestEnc, FALSE );
- if( !c )
+ switch(c)
{
- // then write as unicode - character
- if( 0xFF < cCh )
- {
- ByteString sNo( ByteString::CreateFromInt32( cCh ));
- rStream << "\\u" << sNo.GetBuffer() << " ?";
- }
- else
- {
- rStream << "\\'";
- Out_Hex( rStream, cCh, 2 );
- }
- break;
+ case 149:
+ pStr = sRTF_BULLET;
+ break;
+ case 150:
+ pStr = sRTF_ENDASH;
+ break;
+ case 151:
+ pStr = sRTF_EMDASH;
+ break;
+ case 145:
+ pStr = sRTF_LQUOTE;
+ break;
+ case 146:
+ pStr = sRTF_RQUOTE;
+ break;
+ case 147:
+ pStr = sRTF_LDBLQUOTE;
+ break;
+ case 148:
+ pStr = sRTF_RDBLQUOTE;
+ break;
}
- if( !bWriteHelpFile )
- switch( c )
- {
-#ifdef MAC
- case 0xa5: pStr = sRTF_BULLET; break;
- case 0xd0: pStr = sRTF_ENDASH; break;
- case 0xd1: pStr = sRTF_EMDASH; break;
- case 0xd4: pStr = sRTF_LQUOTE; break;
- case 0xd5: pStr = sRTF_RQUOTE; break;
- case 0xd2: pStr = sRTF_LDBLQUOTE; break;
- case 0xd3: pStr = sRTF_RDBLQUOTE; break;
-#else
- case 149: pStr = sRTF_BULLET; break;
- case 150: pStr = sRTF_ENDASH; break;
- case 151: pStr = sRTF_EMDASH; break;
- case 145: pStr = sRTF_LQUOTE; break;
- case 146: pStr = sRTF_RQUOTE; break;
- case 147: pStr = sRTF_LDBLQUOTE; break;
- case 148: pStr = sRTF_RDBLQUOTE; break;
-#endif
- // MAC
- }
- if( !pStr )
- switch ( c )
+ if (pStr)
+ break;
+ }
+
+ switch (c)
+ {
+ case '\\':
+ case '}':
+ case '{':
+ rStream << '\\' << (sal_Char)c;
+ break;
+ default:
+ if (c >= ' ' && c <= '~')
+ rStream << (sal_Char)c;
+ else
{
- case '\\':
- case '}':
- case '{': rStream << '\\' << (sal_Char)c; break;
-
- default:
- if( c >= ' ' && c <= '~' )
- rStream << (sal_Char)c;
- else if( 0xFF < c )
+ //If we can't convert to the dest encoding, or if
+ //its an uncommon multibyte sequence which most
+ //readers won't be able to handle correctly, then
+ //export as unicode
+ OUString sBuf(&c, 1);
+ OString sConverted;
+ sal_uInt32 nFlags =
+ RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
+ RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR;
+ bool bWriteAsUnicode = !(sBuf.convertToString(&sConverted,
+ eDestEnc, nFlags));
+ if (bWriteAsUnicode)
+ {
+ sBuf.convertToString(&sConverted,
+ eDestEnc, OUSTRING_TO_OSTRING_CVTFLAGS);
+ }
+ const sal_Int32 nLen = sConverted.getLength();
+ if (sConverted.getLength() > 1)
+ bWriteAsUnicode = true;
+
+ if (bWriteAsUnicode && pUCMode)
{
- // write as unicode-char
- ByteString aNumStr( ByteString::CreateFromInt32( c ));
- rStream << "\\u" << aNumStr.GetBuffer() << " ?";
+ // then write as unicode - character
+ if (*pUCMode != nLen)
+ {
+ rStream << "\\uc" << ByteString::CreateFromInt32(nLen).GetBuffer();
+ *pUCMode = nLen;
+ }
+ ByteString sNo(ByteString::CreateFromInt32(c));
+ rStream << "\\u" << sNo.GetBuffer();
}
- else
+
+ for (sal_Int32 nI = 0; nI < nLen; ++nI)
{
rStream << "\\'";
- Out_Hex( rStream, c, 2 );
+ Out_Hex(rStream, sConverted.getStr()[nI], 2);
}
- break;
}
+ break;
}
break;
}
- if( pStr )
+ if (pStr)
rStream << pStr << ' ';
return rStream;
}
-
SvStream& RTFOutFuncs::Out_String( SvStream& rStream, const String& rStr,
- rtl_TextEncoding eDestEnc, BOOL bWriteHelpFile )
+ rtl_TextEncoding eDestEnc, BOOL bWriteHelpFile)
{
- for( xub_StrLen n = 0; n < rStr.Len(); n++ )
- Out_Char( rStream, rStr.GetChar( n ), eDestEnc, bWriteHelpFile );
+ int nUCMode = 1;
+ for (xub_StrLen n = 0; n < rStr.Len(); ++n)
+ Out_Char(rStream, rStr.GetChar(n), &nUCMode, eDestEnc, bWriteHelpFile);
+ if (nUCMode != 1)
+ rStream << "\\uc1";
return rStream;
}
+SvStream& RTFOutFuncs::Out_Fontname(SvStream& rStream, const String& rStr,
+ rtl_TextEncoding eDestEnc, BOOL bWriteHelpFile)
+{
+ //Fontnames in word have a quirk in that \uc and usage of ansi replacement
+ //chars after a \u don't work and in wordpad \u doesn't work, so we are
+ //left with forcing ansi characters only for fontnames
+ for (xub_StrLen n = 0; n < rStr.Len(); ++n)
+ Out_Char(rStream, rStr.GetChar(n), 0, eDestEnc, bWriteHelpFile);
+ return rStream;
+}
SvStream& RTFOutFuncs::Out_Hex( SvStream& rStream, ULONG nHex, BYTE nLen )
{