Font style : can JFreeChart display underlined font ?
Font style : can JFreeChart display underlined font ?
Hello,
I need to underline the title of my charts, so I tried the following code :
Map m = new HashMap();
m.put(TextAttribute.SIZE, new Float(30));
m.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
Font font = new Font(m);
myGraph.setTitleFont(font);
but it doesn't seem to work. The font has the right size, but is not underlined... is there a solution for this ?
Thanks
I need to underline the title of my charts, so I tried the following code :
Map m = new HashMap();
m.put(TextAttribute.SIZE, new Float(30));
m.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
Font font = new Font(m);
myGraph.setTitleFont(font);
but it doesn't seem to work. The font has the right size, but is not underlined... is there a solution for this ?
Thanks
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
There's nothing in JFreeChart 1.0.0 that will support that. There is an AttributedTextTitle class in CVS that you could mess about with - I'm not even sure it will compile with 1.0.0, but it shouldn't be that hard to get working:
http://cvs.sourceforge.net/viewcvs.py/j ... iew=markup
http://cvs.sourceforge.net/viewcvs.py/j ... iew=markup
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Ok, I made a quick-and-dirty solution that works :
in TextUtilities.java, drawRotatedString method (line 539), I modified the code :
to :
in TextUtilities.java, drawRotatedString method (line 539), I modified the code :
Code: Select all
if (useDrawRotatedStringWorkaround) {
(...)
}
else
g2.drawString(text, textX, textY);
Code: Select all
if (useDrawRotatedStringWorkaround) {
(...)
}
else {
if (g2.getFont().getAttributes().get(TextAttribute.UNDERLINE) == TextAttribute.UNDERLINE_ON) {
AttributedString as = new AttributedString(text);
as.addAttribute(TextAttribute.FONT, g2.getFont());
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 0, text.length());
g2.drawString(as.getIterator(), textX, textY);
}
else
g2.drawString(text, textX, textY);
}
Here is a better solution :
change
to
With this modification, fonts can have all supported styles (underline, strikeout...).
change
Code: Select all
if (useDrawRotatedStringWorkaround) {
(...)
}
else
g2.drawString(text, textX, textY);
Code: Select all
if (useDrawRotatedStringWorkaround) {
(...)
}
else {
AttributedString as = new AttributedString(text, g2.getFont().getAttributes());
g2.drawString(as.getIterator(), textX, textY);
}
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
That looks pretty good...thanks for digging it up!
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 10
- Joined: Mon Jun 22, 2009 2:42 pm
Re: Font style : can JFreeChart display underlined font ?
Is there a reason why this was not included in the JCommon 1.0.16 release?
Will it be released in the next version?
Will it be released in the next version?
Re: Font style : can JFreeChart display underlined font ?
I have been using this patch continuously for a year and a half, and it seems solid.
It would be a big help to commit this patch to the main trunk and to the 1.0.x branch!
It would be a big help to commit this patch to the main trunk and to the 1.0.x branch!
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Font style : can JFreeChart display underlined font ?
OK, I've committed this to JCommon (for inclusion with the next release of JFreeChart, 1.0.14). And also to the trunk in Subversion for inclusion in JFreeChart 1.2.0.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Font style : can JFreeChart display underlined font ?
It turns out that this incurs quite a high cost for JFreeChart output to SVG and PDF formats (using JFreeSVG and OrsonPDF), because all the strings are being pushed through TextLayout and rendered to SVG/PDF as vector output. So for JCommon 1.0.21 I will add a flag to enable/disable this feature, and default it to false.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

