IntervalMarker not honouring setLabelFont()?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
kgi
Posts: 2
Joined: Thu Dec 08, 2011 3:43 pm
antibot: No, of course not.

IntervalMarker not honouring setLabelFont()?

Post by kgi » Thu Dec 08, 2011 4:00 pm

Hi all.

I'm not sure if I've found a bug, or whether I'm just going crazy and am suffering from code blindness, but it looks to me as if IntervalMarker is ignoring any font set using setLabelFont().

In brief, my code looks a bit like:

Code: Select all

JFreeChart chart = ...
// ...
IntervalMarker marker = new IntervalMarker(min, max);
String label = "blah";
marker.setLabel(label);
marker.setLabelAnchor(RectangleAnchor.BOTTOM);
marker.setLabelTextAnchor(TextAnchor.BOTTOM_CENTER);
marker.setOutlineStroke(null);
marker.setPaint(new Color(222, 222, 255, 128));
Font labelFont = new Font("Serif", Font.PLAIN, 8);
marker.setLabelFont(labelFont);
chart.getXYPlot().addDomainMarker(marker, Layer.BACKGROUND);
The marker is being added correctly, and the label is also appearing, but it seems not to honour the font or the font size.

I've tried ferreting down into the source code, and it looks like TextUtilities.drawAlignedString() computes a pair of (x,y) adjustments for the text position based upon the size of the font, using deriveTextBoundsAnchorOffsets(), and this changes with the font size, so that looks to be working.

Having done that, it calls g2.drawString(String, float, float). Now, g2 knows about the font, because it is set on it in AbstractXYItemRenderer.drawDomainMarker() around line 1203, so g2.drawString() should/could know about the font and Do The Right Thing.

Is there anything I've missed that might be causing the text not to be rendered in the specified font?

Cheers!

kgi

mkrauskopf
Posts: 31
Joined: Thu May 27, 2010 4:23 pm
antibot: No, of course not.

Re: IntervalMarker not honouring setLabelFont()?

Post by mkrauskopf » Thu Dec 08, 2011 4:22 pm

Hi kgi,

I do not have a solution for you. Just an information that your code is perfectly working on my machine - the font style and size is honored and properly displayed (did not ever try markers - thanks ;) ).

Might be problem with availability of the selected font on your machine?

Cheers,
-- m.

kgi
Posts: 2
Joined: Thu Dec 08, 2011 3:43 pm
antibot: No, of course not.

Re: IntervalMarker not honouring setLabelFont()?

Post by kgi » Fri Dec 09, 2011 10:50 am

mkrauskopf wrote:Hi kgi,

I do not have a solution for you. Just an information that your code is perfectly working on my machine - the font style and size is honored and properly displayed (did not ever try markers - thanks ;) ).

Might be problem with availability of the selected font on your machine?

Cheers,
-- m.
Hi; thanks for your reply.

Gosh; that's interesting. I did some further digging and it might actually be a problem with the Graphics2D I'm using. Even though TextUtils bandies about a Graphics2D declaration, my code actually uses PdfGraphics2D (extends Graphics2D) from the iText library. It might be that that isn't obeying the Font directive; it never occurred to me that that might be the case.

I'll try and come up with a minimal test case comparing the two Graphics2D types, and if it's iText then I'll go and moan over there :P

Thanks for your time, and sorry for the possibly false alarm.

Locked