Discussion:
How to Set Underline Color?
Eliot Kimber
2018-08-01 21:26:19 UTC
Permalink
I'm implementing additional set and get methods for Run properties that I need (or might likely need) [it's not complete over the set of all run properties but it adds a lot more.]

The only one that has stymied me is underline color.

The underline color value is an RGB color string but the OOXML API doesn't seem to provide for it--I suspect it's a limitation in the class generation from the schema.

The CTUnderline API is:

CTUnderline underline = (pr.getU() == null) ? pr.addNewU() : pr.getU();
Object color = underline.getColor();

That is, underline.getColor() returns Object, not something more specialized.

In my tests, color is null (not a surprise).

So my question is: how do I set the color? Should I simply be constructing the XML or is there a better way?

Thanks,

Eliot
--
Eliot Kimber
http://contrext.com




---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@poi.apache.org
For additional commands, e-mail: user-***@poi.apache.org
Mark Murphy
2018-08-02 02:30:16 UTC
Permalink
Here's how I would do it:

public void setUnderlineColor(String color) {
CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
CTUnderline underline = (pr.getU() == null) ? pr.addNewU() :
pr.getU();
SimpleValue svColor = null;
if (color.equals("string")) {
STHexColorAuto hexColor = STHexColorAuto.Factory.newInstance();
hexColor.set(STHexColorAuto.Enum.forString(color));
svColor = (SimpleValue) hexColor;
} else {
STHexColorRGB rgbColor = STHexColorRGB.Factory.newInstance();
rgbColor.setStringValue(color);
svColor = (SimpleValue) rgbColor;
}
underline.setColor(svColor);
}

But see that code to get run properties? That is duplicated everywhere, I
would incorporate it into a new private method named
getRunProperties(boolean create) {} which would encapsulate that code and
create a new CTRPr object if necessary when create is true. So I can then
use it with getters by passing false, or setters by passing true. That can
then be refactored into the other run property methods. Similarly I would
have a private getUnderline(boolean create) {} so that I could use it in
setUnderlineColor(), or setUnderlineThemeColor(), ...
Post by Eliot Kimber
I'm implementing additional set and get methods for Run properties that I
need (or might likely need) [it's not complete over the set of all run
properties but it adds a lot more.]
The only one that has stymied me is underline color.
The underline color value is an RGB color string but the OOXML API doesn't
seem to provide for it--I suspect it's a limitation in the class generation
from the schema.
CTUnderline underline = (pr.getU() == null) ? pr.addNewU() : pr.getU();
Object color = underline.getColor();
That is, underline.getColor() returns Object, not something more specialized.
In my tests, color is null (not a surprise).
So my question is: how do I set the color? Should I simply be constructing
the XML or is there a better way?
Thanks,
Eliot
--
Eliot Kimber
http://contrext.com
---------------------------------------------------------------------
Mark Murphy
2018-08-02 02:41:47 UTC
Permalink
Crap, not "string" but "auto".
Post by Mark Murphy
public void setUnderlineColor(String color) {
CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
CTUnderline underline = (pr.getU() == null) ? pr.addNewU() : pr.getU();
SimpleValue svColor = null;
if (color.equals("string")) {
STHexColorAuto hexColor = STHexColorAuto.Factory.newInstance();
hexColor.set(STHexColorAuto.Enum.forString(color));
svColor = (SimpleValue) hexColor;
} else {
STHexColorRGB rgbColor = STHexColorRGB.Factory.newInstance();
rgbColor.setStringValue(color);
svColor = (SimpleValue) rgbColor;
}
underline.setColor(svColor);
}
But see that code to get run properties? That is duplicated everywhere, I
would incorporate it into a new private method named
getRunProperties(boolean create) {} which would encapsulate that code and
create a new CTRPr object if necessary when create is true. So I can then
use it with getters by passing false, or setters by passing true. That can
then be refactored into the other run property methods. Similarly I would
have a private getUnderline(boolean create) {} so that I could use it in
setUnderlineColor(), or setUnderlineThemeColor(), ...
Post by Eliot Kimber
I'm implementing additional set and get methods for Run properties that I
need (or might likely need) [it's not complete over the set of all run
properties but it adds a lot more.]
The only one that has stymied me is underline color.
The underline color value is an RGB color string but the OOXML API
doesn't seem to provide for it--I suspect it's a limitation in the class
generation from the schema.
CTUnderline underline = (pr.getU() == null) ? pr.addNewU() : pr.getU();
Object color = underline.getColor();
That is, underline.getColor() returns Object, not something more specialized.
In my tests, color is null (not a surprise).
So my question is: how do I set the color? Should I simply be
constructing the XML or is there a better way?
Thanks,
Eliot
--
Eliot Kimber
http://contrext.com
---------------------------------------------------------------------
Eliot Kimber
2018-08-02 14:32:20 UTC
Permalink
I have implemented Mark's requests as well as set/get for underline theme color and added to the pull request.

Cheers,

E.

--
Eliot Kimber
http://contrext.com


On 8/1/18, 9:30 PM, "Mark Murphy" <***@gmail.com> wrote:

Here's how I would do it:

public void setUnderlineColor(String color) {
CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
CTUnderline underline = (pr.getU() == null) ? pr.addNewU() :
pr.getU();
SimpleValue svColor = null;
if (color.equals("string")) {
STHexColorAuto hexColor = STHexColorAuto.Factory.newInstance();
hexColor.set(STHexColorAuto.Enum.forString(color));
svColor = (SimpleValue) hexColor;
} else {
STHexColorRGB rgbColor = STHexColorRGB.Factory.newInstance();
rgbColor.setStringValue(color);
svColor = (SimpleValue) rgbColor;
}
underline.setColor(svColor);
}

But see that code to get run properties? That is duplicated everywhere, I
would incorporate it into a new private method named
getRunProperties(boolean create) {} which would encapsulate that code and
create a new CTRPr object if necessary when create is true. So I can then
use it with getters by passing false, or setters by passing true. That can
then be refactored into the other run property methods. Similarly I would
have a private getUnderline(boolean create) {} so that I could use it in
setUnderlineColor(), or setUnderlineThemeColor(), ...
Post by Eliot Kimber
I'm implementing additional set and get methods for Run properties that I
need (or might likely need) [it's not complete over the set of all run
properties but it adds a lot more.]
The only one that has stymied me is underline color.
The underline color value is an RGB color string but the OOXML API doesn't
seem to provide for it--I suspect it's a limitation in the class generation
from the schema.
CTUnderline underline = (pr.getU() == null) ? pr.addNewU() : pr.getU();
Object color = underline.getColor();
That is, underline.getColor() returns Object, not something more specialized.
In my tests, color is null (not a surprise).
So my question is: how do I set the color? Should I simply be constructing
the XML or is there a better way?
Thanks,
Eliot
--
Eliot Kimber
http://contrext.com
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@poi.apache.org
For additional commands, e-mail: user-***@poi.apache.org

Mark Murphy
2018-08-02 02:35:11 UTC
Permalink
One more thing, I want to keep naming consistent. For Abstract classes it
should be XWPFAbstract vs. AbstractXWPF. If you could rename your footnote
and endnote classes that would be great. And any other place that XWPF
exists, it goes first. This will keep things consistent with the rest of
POI.
Post by Eliot Kimber
I'm implementing additional set and get methods for Run properties that I
need (or might likely need) [it's not complete over the set of all run
properties but it adds a lot more.]
The only one that has stymied me is underline color.
The underline color value is an RGB color string but the OOXML API doesn't
seem to provide for it--I suspect it's a limitation in the class generation
from the schema.
CTUnderline underline = (pr.getU() == null) ? pr.addNewU() : pr.getU();
Object color = underline.getColor();
That is, underline.getColor() returns Object, not something more specialized.
In my tests, color is null (not a surprise).
So my question is: how do I set the color? Should I simply be constructing
the XML or is there a better way?
Thanks,
Eliot
--
Eliot Kimber
http://contrext.com
---------------------------------------------------------------------
Eliot Kimber
2018-08-02 12:50:19 UTC
Permalink
I have submitted a pull request with the name changes.

Cheers,

E.

--
Eliot Kimber
http://contrext.com


On 8/1/18, 9:35 PM, "Mark Murphy" <***@gmail.com> wrote:

One more thing, I want to keep naming consistent. For Abstract classes it
should be XWPFAbstract vs. AbstractXWPF. If you could rename your footnote
and endnote classes that would be great. And any other place that XWPF
exists, it goes first. This will keep things consistent with the rest of
POI.
Post by Eliot Kimber
I'm implementing additional set and get methods for Run properties that I
need (or might likely need) [it's not complete over the set of all run
properties but it adds a lot more.]
The only one that has stymied me is underline color.
The underline color value is an RGB color string but the OOXML API doesn't
seem to provide for it--I suspect it's a limitation in the class generation
from the schema.
CTUnderline underline = (pr.getU() == null) ? pr.addNewU() : pr.getU();
Object color = underline.getColor();
That is, underline.getColor() returns Object, not something more specialized.
In my tests, color is null (not a surprise).
So my question is: how do I set the color? Should I simply be constructing
the XML or is there a better way?
Thanks,
Eliot
--
Eliot Kimber
http://contrext.com
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@poi.apache.org
For additional commands, e-mail: user-***@poi.apache.org
Continue reading on narkive:
Loading...