j***@yahoo.com
2006-03-16 16:23:05 UTC
Hi,
I'm using an MLTEPane derived class (CMLTEView) to display formatted
text with bold, italic... and colours.
I'm trying to export it to RTF but with some trouble: (running OS X.3.5
with CW 9.5)
the colours are not exported: i.e. the whole text is black on white in
the resulting RTF.
I get:
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;}
instead of:
{\colortbl;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;
\red127\green0\blue0;
\red0\green127\blue127;} for instance...
If I copy and paste the same text in another MLTEPane or in TextEdit
the colours are OK in that new window but not in the data gotten from
the RTF export (in the pRTF pointer below).
What is more the exported RTF is in MacRoman (ansicp10000). I would
like to export it for my Windows colleagues using CP1252 but how can I
ask TXNFlattenObjectToCFDataRef to do so?
Here is the code:
bool CMLTEView::StreamOutRTF()
{
CFDataRef rDataRef;
OSStatus status = ::TXNFlattenObjectToCFDataRef(mTXNObject,
kTXNRichTextFormatData, &rDataRef);
if(noErr!=status)
return false;
CFStringRef rString =
::CFStringCreateFromExternalRepresentation(kCFAllocatorDefault,
rDataRef, kCFStringEncodingMacRoman); // Here data in rDataRef are
already in MacRoman...
::CFRelease(rDataRef);
if(!rString)
return false;
CFIndex nFCIndex = ::CFStringGetLength(rString);
if(!nFCIndex)
return false;
++nFCIndex;
char* pRTF = new char[nFCIndex];
if(!::CFStringGetCString(rString, pRTF, nFCIndex,
kCFStringEncodingMacRoman))
{
::CFRelease(rString);
return false;
}
// Do my things with pRTF...
delete [] pRTF;
::CFRelease(rString);
return true;
}
Thanks in advance for your help.
Regards, MacPorter.
I'm using an MLTEPane derived class (CMLTEView) to display formatted
text with bold, italic... and colours.
I'm trying to export it to RTF but with some trouble: (running OS X.3.5
with CW 9.5)
the colours are not exported: i.e. the whole text is black on white in
the resulting RTF.
I get:
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;}
instead of:
{\colortbl;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;
\red127\green0\blue0;
\red0\green127\blue127;} for instance...
If I copy and paste the same text in another MLTEPane or in TextEdit
the colours are OK in that new window but not in the data gotten from
the RTF export (in the pRTF pointer below).
What is more the exported RTF is in MacRoman (ansicp10000). I would
like to export it for my Windows colleagues using CP1252 but how can I
ask TXNFlattenObjectToCFDataRef to do so?
Here is the code:
bool CMLTEView::StreamOutRTF()
{
CFDataRef rDataRef;
OSStatus status = ::TXNFlattenObjectToCFDataRef(mTXNObject,
kTXNRichTextFormatData, &rDataRef);
if(noErr!=status)
return false;
CFStringRef rString =
::CFStringCreateFromExternalRepresentation(kCFAllocatorDefault,
rDataRef, kCFStringEncodingMacRoman); // Here data in rDataRef are
already in MacRoman...
::CFRelease(rDataRef);
if(!rString)
return false;
CFIndex nFCIndex = ::CFStringGetLength(rString);
if(!nFCIndex)
return false;
++nFCIndex;
char* pRTF = new char[nFCIndex];
if(!::CFStringGetCString(rString, pRTF, nFCIndex,
kCFStringEncodingMacRoman))
{
::CFRelease(rString);
return false;
}
// Do my things with pRTF...
delete [] pRTF;
::CFRelease(rString);
return true;
}
Thanks in advance for your help.
Regards, MacPorter.