]> source.dussan.org Git - poi.git/commitdiff
support text colors in Word-to-HTML and Word-to-FO converters
authorSergey Vladimirov <sergey@apache.org>
Mon, 25 Jul 2011 09:57:53 +0000 (09:57 +0000)
committerSergey Vladimirov <sergey@apache.org>
Mon, 25 Jul 2011 09:57:53 +0000 (09:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1150612 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java
src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java
src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java
src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java

index 6e974ea6d983da0f6e90f08d51896399a4ee27db..ef1d82a75b96e91ca3976600f6a5364ecf73362c 100644 (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 )
index fdea671039b3edbb2b5f721720419a2b325c9ce1..783896f096c14bedf86cf6d50a6c0982aa2bea0e 100644 (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" );
index 2b1848a3efae6faf12f0a817f90b87d83439e636..3745a53faad197aaf3e93f53ae3d2a211420c8f3 100644 (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:"
index 83b1236498db708522dfe10d49477e178ed57a57..4fd3ac216c22f5802bac7afde2fef72bba583fd5 100644 (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" );
     }