From da8e38019aa8e641948a313bbc67fc1eef7a59ad Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Mon, 22 Aug 2011 11:52:11 +0000 Subject: [PATCH] handle colors with opacity git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1160220 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hwpf/converter/AbstractWordUtils.java | 15 +++++++++++++-- .../apache/poi/hwpf/converter/WordToFoUtils.java | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) 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 eeb5d7843f..455eb21b05 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java @@ -306,11 +306,22 @@ public class AbstractWordUtils } } - public static String getColor24( int value ) + public static String getOpacity( int argbValue ) { - if ( value == -1 ) + int opacity = (int) ( ( argbValue & 0xFF000000l ) >>> 24 ); + if ( opacity == 0 || opacity == 0xFF ) + return ".0"; + + return "" + ( opacity / (float) 0xFF ); + } + + public static String getColor24( int argbValue ) + { + if ( argbValue == -1 ) throw new IllegalArgumentException( "This colorref is empty" ); + int value = argbValue & 0x00FFFFFF; + // http://www.w3.org/TR/REC-html40/types.html#h-6.5 switch ( value ) { 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 29723cfced..f80f59c68b 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java @@ -76,6 +76,12 @@ public class WordToFoUtils extends AbstractWordUtils { inline.setAttribute( "color", getColor24( characterRun.getIco24() ) ); } + final int opacity = (int) ( characterRun.getIco24() & 0xFF000000l ) >>> 24; + if ( opacity != 0 && opacity != 0xFF ) + { + inline.setAttribute( "opacity", + getOpacity( characterRun.getIco24() ) ); + } if ( characterRun.getLanguageCode() != 0 ) { final String language = getLanguage( characterRun.getLanguageCode() ); -- 2.39.5