Issue 126531 - different behaviour for "CharColor" and "CharBackColor" properties in java
Summary: different behaviour for "CharColor" and "CharBackColor" properties in java
Alias: None
Product: App Dev
Classification: Unclassified
Component: api (show other issues)
Version: 4.1.1
Hardware: PC Windows 10
: P5 (lowest) Normal
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
Keywords: usability
Depends on:
Reported: 2015-09-16 00:25 UTC by John R. D'Orazio
Modified: 2015-09-21 18:55 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Note You need to log in before you can comment on or make changes to this issue.
Description John R. D'Orazio 2015-09-16 00:25:29 UTC
When using the interface in a java extension, I am seeing different behaviour for the "CharColor" property and the "CharBackColor" property. The API documentation says that they take a "long" value; and it then gives as an example the usage of a hex number such as 0x00FFFF00 ( The "CharBackColor" property, differently from the "CharColor" property, will not take an integer value such as the one produced by the Color.getRGB() method.

==Steps to reproduce==
The "CharColor" property will take an integer as produced by the getRGB() method:

    xPropertySet.setPropertyValue("CharColor", Color.YELLOW.getRGB());
This will correctly set the character color to yellow.
However this will not work for the "CharBackColor" property:

    xPropertySet.setPropertyValue("CharBackColor", Color.YELLOW.getRGB());
This simply will not do anything, it does not give an error but it also does not set the background to yellow. This will work instead:

    xPropertySet.setPropertyValue("CharBackColor", 0x00FFFF00);

Casting a variable as "long" and passing it in as value for the "CharBackColor" property results in an error:

long bgColor = 0x00FFFF00; //Long bgColor = (long) 0x00FFFF00
xPropertySet.setPropertyValue("CharBackColor", bgColor); 
	at Method)
	at com.sun.proxy.$Proxy6.setPropertyValue(Unknown Source)

==Actual results==
Passing an integer value as produced by Color.getRGB() into the "CharBackColor" property will not throw an error but will have no result. Passing a value cast as "long" or "Long" or "int" will result in an error.

==Expected results==
Passing a Color.getRGB() value into the "CharBackColor" property should be sufficient to correctly set the color.
Comment 1 John R. D'Orazio 2015-09-17 13:18:35 UTC
I have run some further tests, and I see that the CharBackColor property has swapped the alpha value such that a value of 0 (or 0.0, or 0x00) is treated as opaque and a value of 255 (or 1.0, or 0xFF) is treated as transparent.

This is not the case for the CharColor property which seems to behave as it should.

xPropertySet.setPropertyValue("CharBackColor", Color.YELLOW.getRGB()); //-> has no visible effect because is treated as transparent!

xPropertySet.setPropertyValue("CharBackColor", Color.YELLOW.getRGB() - 0xFF000000); //-> sets an opaque yellow background color! having subtracted the alpha bits and setting them 0 should give a transparent color, but Open Office is treating transparent as opaque in this case!
Comment 2 John R. D'Orazio 2015-09-19 23:20:06 UTC
I think I understand a little better what is happening here.
It seems that OpenOffice perhaps doesn't support the alpha bit for background colors, and so assumes an empty bit such as 0x00. However 0x00 actually means 100% transparency, compared to 0xFF which means 0% transparency (full opacity).

However, since Java automatically sets the alpha bit with the Color object or with JColorChooser or any similar handling of colors, the only way to get OpenOffice to correctly accept the color value is to explicitly unset or clear the alpha bit before setting the integer value for the "CharBackColor" property. I am currently doing this with a bitwise operation that clears the bit. Example:

xPropertySet.setPropertyValue("CharBackColor", Color.YELLOW.getRGB() & ~0xFF000000);

I will do a little more investigation to see if I can gather any more information on this issue...
Comment 3 John R. D'Orazio 2015-09-20 21:32:23 UTC
I can also add that "int" is the correct type in Java for the "long" type in UNO, I found a page about type mapping for Java:
Comment 4 John R. D'Orazio 2015-09-20 21:37:38 UTC
I can also add that I have tried to set the "CharBackTransparent" property both to true and to false before setting the "CharBackColor" property, but it had no effect. In any case I have to clear the alpha bit.
(So what exactly does the "CharBackTransparent" property do? Is it supposed to enable transparency for background colors? Doesn't seem to be working if it is...)
Comment 5 John R. D'Orazio 2015-09-21 18:55:32 UTC
I believe I understand what the "CharBackTransparent" property is doing, basically it means if you want "no color" as opposed to white background, then you set "CharBackTransparent" to true so that no matter what the "CharBackColor" is set to, there will still be no background at all (you would need this property if the alpha bit is not read from the "CharBackColor" property in fact).

Therefore it is of no help when you are wanting to see and set a Character Background Color. "CharBackTransparent" would have to be set to false in order to see any background color, but it does not modify how the alpha bit in "CharBackColor" is being dealt with, it's a simple ovverride is what I'm guessing.