Well, in reply to Johan. I'll admit that I kinda knew those were there, but
the documentation on them is either horrible or non-existent (depending on
which RTF modules you look at.) As for the HTML2RTF, I know of no already
existing interpreter, but I plan on using HTML::Parser to make it simpler.
Anyway, I managed to get it to properly translate '<', '>' and '&' into
their HTML counterparts. Please point out any bugs or suggestions you have.
sub rtf2html{
my $re = $main->reDesc; #Just set this to the RichEdit object
my $oldtext = $re->Text();
my @escapes;
{
my $temp = -1;
while(($temp = index($oldtext,'<',$temp+1)) != -1){
push(@escapes,[$temp,'<']);
}
$temp = -1;
while(($temp = index($oldtext,'>',$temp+1)) != -1){
push(@escapes,[$temp,'>']);
}
$temp = -1;
while(($temp = index($oldtext,'&',$temp+1)) != -1){
push(@escapes,[$temp,'&']);
}
}
@escapes = sort({ $a->[0] <=> $b->[0] } @escapes);
foreach (@escapes){
print $_->[0]." = ".$_->[1]."\n";
}
my $i = 0;
my $b = 0;
my $u = 0;
my $text = '';
my $offset = 0;
foreach my $x (0..length($oldtext)){
$re->Select($x,$x+1);
my %att = $re->GetCharFormat();
if(($i && !exists($att{-italic})) || (!$i && exists($att{-italic}))){
$i = $att{-italic};
$text .= ($i ? '<I>' : '</I>');
}
if(($b && !exists($att{-bold})) || (!$b && exists($att{-bold}))){
$b = $att{-bold};
$text .= ($b ? '<B>' : '</B>');
}
if(($u && !exists($att{-underline})) || (!$u &&
exists($att{-underline}))){
$u = $att{-underline};
$text .= ($u ? '<U>' : '</U>');
}
if(defined($escapes[0]->[0]) && $x == $escapes[0]->[0]){
my $temp = shift(@escapes);
$text .= $temp->[1];
}else{
$text .= substr($oldtext,$x,1);
}
}
$text =~ s/\r//g;
$text =~ s/\n/<BR>/gi;
return $text;
}
Date: Thu, 07 Mar 2002 09:47:52 +0100
To: perl-win32-gui-users@lists.sourceforge.net
From: Johan Lindstrom <[EMAIL PROTECTED]>
Subject: Re: [perl-win32-gui-users] RTF 2 HTML
At 23:37 2002-03-06 -0500, Ultimate Red Dragon wrote:
>It's not that great, I don't claim it's efficient, just that it works.
>
>Currently, it supports new lines, bold, italics and underline.
This seems to be similar to what you want:
http://search.cpan.org/search?dist=RTF-Parser
>I'm working on converting < and > correctly, as well as a HTML 2 RTF sub
>(or is there already one?)
There are HTML parsers and RTF generators on CPAN.
Here is the search for module names with RTF:
http://search.cpan.org/search?mode=module&query=rtf
(but note that you often can get a lot more results by searching the
documentation rather than the module name)
/J
-------- ------ ---- --- -- -- -- - - - - -
Johan Lindström Sourcerer @ Boss Casinos [EMAIL PROTECTED]
Latest bookmark: "(GUI) Windows Programming FAQ"
http://www.perlmonks.org/index.pl?node_id=108708
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com