[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Exchanging RTF with MacOSX
From: |
Andreas Höschler |
Subject: |
Exchanging RTF with MacOSX |
Date: |
Wed, 30 Aug 2006 19:18:59 +0200 |
Hi Wolfgang,
If I open it on GNustep with TextEdit.app the german letters are
gone. If I
create a file under GNUstep and open it on a Mac (TextEdit.app), the
german
characters are replaced with garbage!?
After looking at the attached rtf and doing some research, it looks
like the encoding is "Mac OS Roman" (cpg1000):
http://en.wikipedia.org/wiki/Code_page_10000
and not unicode.
Right. And since Windows copepage 1252 is close to ISO 8859-1 (and
thus the
first 256 characters of Unicode, the following simple patch will make
GNUstep
write RTF files that -- at least as far as ISO 8859-1 characters are
concerned -- are read correctly by OS X's TextEdit.app.
--- TextConverters/RTF/RTFProducer.m.orig 2006-08-30
17:59:51.000000000 +0200
+++ TextConverters/RTF/RTFProducer.m 2006-08-30 18:00:29.000000000
+0200
@@ -395,7 +395,7 @@
// grok paragraph spacing \saN. Should be no problem with other RTF
parsers
// as this command will be ignored. So this is for compatibility
with OS X.
result = (NSMutableString *)[NSMutableString stringWithString:
- @"{\\rtf1\\ansi\\ansicpg10000\\cocoartf102"];
+ @"{\\rtf1\\ansi\\ansicpg1252\\cocoartf102"];
[result appendString: [self fontTable]];
[result appendString: [self colorTable]];
Works fabulous. Thanks a lot!
The patch on the input side is more complicated, as it requires
reading the
code page from the RTF file (which according to my cursory look is
currently
ignored in the RTF parser) and setting up an appropriate iconv
translation in
RTFConsumer.m (which is currently both beyond my time and iconv
expertise).
Fred Kiefer provided a hack for the other direction that is most likely
improvable but works for now.
pico ./TextConverters/RTF/rtfScanner.c
#include <iconv.h>
// read in a character as two hex digit
static int gethex(RTFscannerCtxt *lctxt)
{
int c = 0;
int i;
for (i = 0; i < 2; i++)
{
int c1 = lexGetchar(lctxt);
if (!isxdigit(c1))
{
lexUngetchar(lctxt, c1);
break;
}
else
{
c = c * 16;
if (isdigit(c1))
{
c += c1 - '0';
}
else if (isupper(c1))
{
c += c1 - 'A' + 10;
}
else
{
c += c1 - 'a' + 10;
}
}
}
{
iconv_t cd;
unsigned char c1 = c;
unsigned char *i;
unsigned int u;
unsigned int *o;
unsigned int inlen = 1;
unsigned int outlen = 4;
size_t rval;
cd = iconv_open("UTF-16LE", "MACINTOSH");
if (cd != (iconv_t)-1)
{
i = &c1;
o = &u;
rval = iconv(cd, (void*)&i, &inlen, (void*)&o, &outlen);
if (rval != (size_t)-1)
{
c = u;
}
iconv_close(cd);
}
}
return c;
}
Thanks guys! One more stone removed.
Regards,
Andreas
- ANN: GUI-0.11.0, Gregory John Casamento, 2006/08/29
- Re: ANN: GUI-0.11.0, Gregory John Casamento, 2006/08/29
- Re: ANN: GUI-0.11.0, Andreas Höschler, 2006/08/29
- Re: Re: ANN: GUI-0.11.0, Nicolas Roard, 2006/08/30
- Re: ANN: GUI-0.11.0, Andreas Höschler, 2006/08/30
- Re: ANN: GUI-0.11.0, Charles Philip Chan, 2006/08/30
- Re: ANN: GUI-0.11.0, Andreas Höschler, 2006/08/30
- Re: ANN: GUI-0.11.0, Charles Philip Chan, 2006/08/30
- Re: ANN: GUI-0.11.0, Wolfgang Lux, 2006/08/30
- Exchanging RTF with MacOSX,
Andreas Höschler <=
- Re: ANN: GUI-0.11.0, Gerold Rupprecht, 2006/08/30