support text colors in Word-to-HTML and Word-to-FO converters

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1150612 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sergey Vladimirov 2011-07-25 09:57:53 +00:00
parent 55ed7e8d77
commit 5e6b7c6879
4 changed files with 62 additions and 0 deletions

View File

@ -298,6 +298,58 @@ public class AbstractWordUtils
}
}
public static String getColor24( int value )
{
if ( value == -1 )
throw new IllegalArgumentException( "This colorref is empty" );
// http://www.w3.org/TR/REC-html40/types.html#h-6.5
switch ( value )
{
case 0xFFFFFF:
return "white";
case 0xC0C0C0:
return "silver";
case 0x808080:
return "gray";
case 0x000000:
return "black";
case 0xFF0000:
return "red";
case 0x800000:
return "maroon";
case 0xFFFF00:
return "yellow";
case 0x808000:
return "olive";
case 0x00FF00:
return "lime";
case 0x008000:
return "green";
case 0x00FFFF:
return "aqua";
case 0x008080:
return "teal";
case 0x0000FF:
return "blue";
case 0x000080:
return "navy";
case 0xFF00FF:
return "fuchsia";
case 0x800080:
return "purple";
}
StringBuilder result = new StringBuilder( "#" );
String hex = Integer.toHexString( value );
for ( int i = hex.length(); i < 6; i++ )
{
result.append( '0' );
}
result.append( hex );
return result.toString();
}
public static String getJustification( int js )
{
switch ( js )

View File

@ -70,6 +70,10 @@ public class WordToFoUtils extends AbstractWordUtils
setBorder( inline, characterRun.getBorder(), EMPTY );
if ( characterRun.getIco24() != -1 )
{
inline.setAttribute( "color", getColor24( characterRun.getIco24() ) );
}
if ( characterRun.isCapitalized() )
{
inline.setAttribute( "text-transform", "uppercase" );

View File

@ -67,6 +67,11 @@ public class WordToHtmlUtils extends AbstractWordUtils
{
style.append( "text-transform:uppercase;" );
}
if ( characterRun.getIco24() != -1 )
{
style.append( "color:" + getColor24( characterRun.getIco24() )
+ ";" );
}
if ( characterRun.isHighlighted() )
{
style.append( "background-color:"

View File

@ -126,6 +126,7 @@ public class TestWordToHtmlConverter extends TestCase
assertFalse( result.contains( "FORMTEXT" ) );
assertContains( result, "color:#28624f;" );
assertContains( result, "Passport No and the date of expire" );
assertContains( result, "mfa.gov.cy" );
}