diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java index 6e974ea6d9..ef1d82a75b 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java @@ -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 ) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java index fdea671039..783896f096 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java @@ -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" ); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java index 2b1848a3ef..3745a53faa 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java @@ -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:" diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java b/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java index 83b1236498..4fd3ac216c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java @@ -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" ); }