#!@@PERL@@ -s
#
#	This script is part of rtfdtohtml.
#	Copyright (c) 1996  Elmar Ludwig - Universitaet Osnabrueck
#
#	Set the font colors (foreground only).

$index = $color = 0;
$color[0] = '000000';
$out = '';

while (<>)
{
    if ($html2)
    {
	print;
	next;
    }

    print $out;

    for ($pos = index($_, '{\\colortbl'); $pos != -1;
	 $pos = index($_, ';', $pos + 1), ++$index)
    {
	last unless substr($_, $pos) =~
		    /;\\red([0-9]+)\\green([0-9]+)\\blue([0-9]+)/;
	$color[$index] = sprintf("%02X%02X%02X", $1, $2, $3) if $index;
    }

    $out = '';

    while (/\\cf([0-9]+)/)
    {
	$out .= $`;
	$_ = $';

	if (substr($`, -1) ne '\\' && $color[$color] ne $color[$1])
	{
	    $out .= '{\\v1\\shad1</FONT>\\shad0\\v0}' if $color;
	    $color = $1;
	    $out .= "{\\v1\\shad1<FONT color=\"#$color[$1]\">\\shad0\\v0}"
		    if $color;
	}

	$out .= $&;
    }

    $out .= $_;
}

print '{\\v1\\shad1</FONT>\\shad0\\v0}' if $color;
print $out;
