You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jmeter.apache.org by Philippe Mouawad <ph...@gmail.com> on 2014/11/19 15:36:56 UTC
Fwd: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
derived Fonts ?
Hello Rory,
For information, I submitted this question on Swing-dev , I am not sure it
is the right list, if so hope you can help.
Regards
Philippe
---------- Forwarded message ----------
From: Philippe Mouawad <ph...@gmail.com>
Date: Wed, Nov 19, 2014 at 3:34 PM
Subject: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of derived
Fonts ?
To: swing-dev@openjdk.java.net
Hello,
We had recently a report of a bug on Apache JMeter:
- https://issues.apache.org/bugzilla/show_bug.cgi?id=57221
The bug only occurs on Java 8 (u20 and u25).
We use jCharts library.
I narrowed the bug and it seems to come from the way derived fonts are
drawn:
Library uses:
public static final AffineTransform VERTICAL_ROTATION =
AffineTransform.getRotateInstance( -Math.PI / 2 );
Then
this.affineTransform= VERTICAL_ROTATION;
this.font.deriveFont( this.affineTransform )
So I build a stupid and ugly isolated class to show issue, run it on Java 7
display is fine , run it on Java8 result is strange.
package org.jCharts;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.font.LineMetrics;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Test extends JPanel {
Rectangle2D.Float rect = new Rectangle2D.Float(200, 200, 220, 35);
// float theta = 1.1748778437843f;
double theta = Math.PI / 6;
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_PURE);
g2.setPaint(Color.blue);
Font font = g2.getFont().deriveFont(18f);
g2.setFont(font);
FontRenderContext frc = g2.getFontRenderContext();
String s = "This text should be rotated";
float width = (float) font.getStringBounds(s, frc).getWidth();
LineMetrics lm = font.getLineMetrics(s, frc);
float height = lm.getAscent() + lm.getDescent();
// Scale text into rect.
float xScale = rect.width / width;
float yScale = rect.height / height;
float scale = (xScale > yScale) ? yScale : xScale;
// Locate string origin.
double x = rect.x;
double y = rect.y + (rect.height + scale * height) / 2 - scale
* lm.getDescent();
AffineTransform at = AffineTransform.getTranslateInstance(x, y);
at.scale(scale, scale);
AffineTransform rotator = new AffineTransform();
rotator.rotate(theta, rect.getCenterX(), rect.getCenterY());
GeneralPath rect2 = new GeneralPath(
rotator.createTransformedShape(rect));
// Draw with no rotation.
g2.draw(rect);
g2.setPaint(Color.red);
g2.setFont(font.deriveFont(at));
g2.drawString(s, 0, 0);
// Rotate once.
g2.setPaint(Color.blue);
g2.draw(rect2);
rotator.concatenate(at);
g2.setFont(font.deriveFont(rotator));
g2.setPaint(Color.red);
g2.drawString(s, 0, 0);
// Rotate again.
rotator.setToIdentity();
rotator.rotate(2 * theta, rect.getCenterX(), rect.getCenterY());
rect2 = new GeneralPath(rotator.createTransformedShape(rect));
g2.setPaint(Color.blue);
g2.draw(rect2);
rotator.concatenate(at);
g2.setFont(font.deriveFont(rotator));
g2.setPaint(Color.red);
g2.drawString(s, 0, 0);
// Check scaled string bounds.
// this was handled by the fractional metrics rendering hint
}
public static void main(String[] args) {
Test test = new Test();
test.setPreferredSize(new Dimension(800, 600));
JFrame f = new JFrame();
f.getContentPane().add(test);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
}
}
Regards
Philippe M.
--
Cordialement.
Philippe Mouawad.
--
Cordialement.
Philippe Mouawad.
Fwd: Fwd: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
derived Fonts ?
Posted by Philippe Mouawad <ph...@gmail.com>.
Hi ,
Could you make some tests on Linux and Windows platform please to see if
issue is also there ?
Thanks
---------- Forwarded message ----------
From: Philippe Mouawad <ph...@gmail.com>
Date: Wed, Nov 19, 2014 at 4:10 PM
Subject: Re: Fwd: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
derived Fonts ?
To: "dev@jmeter.apache.org" <de...@jmeter.apache.org>
Cc: rory.odonnell@oracle.com, Dalibor Topic <da...@oracle.com>,
Vaidya Balchandra <Ba...@oracle.com>
Hello Rory,
I posted a bug, waiting for mail notification.
It seems bug appeared after Java 7 u40 as I just tested now with Java7 u71
and it is also broken there.
I didn't test versions between 7u40 and 7u71.
Regards
Philippe
On Wed, Nov 19, 2014 at 3:44 PM, Rory O'Donnell <ro...@oracle.com>
wrote:
> Hi Philippe,
>
> Can you log a Java Incident and send us the JI number ?
>
> Rgds,Rory
> On 19/11/2014 14:36, Philippe Mouawad wrote:
>
>> Hello Rory,
>> For information, I submitted this question on Swing-dev , I am not sure it
>> is the right list, if so hope you can help.
>>
>> Regards
>> Philippe
>> ---------- Forwarded message ----------
>> From: Philippe Mouawad <ph...@gmail.com>
>> Date: Wed, Nov 19, 2014 at 3:34 PM
>> Subject: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of derived
>> Fonts ?
>> To: swing-dev@openjdk.java.net
>>
>>
>> Hello,
>> We had recently a report of a bug on Apache JMeter:
>>
>> - https://issues.apache.org/bugzilla/show_bug.cgi?id=57221
>>
>>
>> The bug only occurs on Java 8 (u20 and u25).
>>
>> We use jCharts library.
>>
>> I narrowed the bug and it seems to come from the way derived fonts are
>> drawn:
>>
>> Library uses:
>>
>> public static final AffineTransform VERTICAL_ROTATION =
>> AffineTransform.getRotateInstance( -Math.PI / 2 );
>>
>> Then
>>
>> this.affineTransform= VERTICAL_ROTATION;
>> this.font.deriveFont( this.affineTransform )
>>
>> So I build a stupid and ugly isolated class to show issue, run it on Java
>> 7
>> display is fine , run it on Java8 result is strange.
>>
>> package org.jCharts;
>>
>> import java.awt.Color;
>> import java.awt.Dimension;
>> import java.awt.Font;
>> import java.awt.Graphics;
>> import java.awt.Graphics2D;
>> import java.awt.RenderingHints;
>> import java.awt.font.FontRenderContext;
>> import java.awt.font.LineMetrics;
>> import java.awt.geom.AffineTransform;
>> import java.awt.geom.GeneralPath;
>> import java.awt.geom.Rectangle2D;
>>
>> import javax.swing.JFrame;
>> import javax.swing.JPanel;
>>
>> public class Test extends JPanel {
>> Rectangle2D.Float rect = new Rectangle2D.Float(200, 200, 220, 35);
>> // float theta = 1.1748778437843f;
>> double theta = Math.PI / 6;
>>
>> @Override
>> protected void paintComponent(Graphics g) {
>> super.paintComponent(g);
>> Graphics2D g2 = (Graphics2D) g;
>> g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
>> RenderingHints.VALUE_ANTIALIAS_ON);
>> g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
>> RenderingHints.VALUE_FRACTIONALMETRICS_ON);
>> g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
>> RenderingHints.VALUE_STROKE_PURE);
>> g2.setPaint(Color.blue);
>> Font font = g2.getFont().deriveFont(18f);
>> g2.setFont(font);
>> FontRenderContext frc = g2.getFontRenderContext();
>> String s = "This text should be rotated";
>> float width = (float) font.getStringBounds(s, frc).getWidth();
>> LineMetrics lm = font.getLineMetrics(s, frc);
>> float height = lm.getAscent() + lm.getDescent();
>> // Scale text into rect.
>> float xScale = rect.width / width;
>> float yScale = rect.height / height;
>> float scale = (xScale > yScale) ? yScale : xScale;
>> // Locate string origin.
>> double x = rect.x;
>> double y = rect.y + (rect.height + scale * height) / 2 - scale
>> * lm.getDescent();
>> AffineTransform at = AffineTransform.getTranslateInstance(x, y);
>> at.scale(scale, scale);
>> AffineTransform rotator = new AffineTransform();
>> rotator.rotate(theta, rect.getCenterX(), rect.getCenterY());
>> GeneralPath rect2 = new GeneralPath(
>> rotator.createTransformedShape(rect));
>> // Draw with no rotation.
>> g2.draw(rect);
>> g2.setPaint(Color.red);
>> g2.setFont(font.deriveFont(at));
>> g2.drawString(s, 0, 0);
>> // Rotate once.
>> g2.setPaint(Color.blue);
>> g2.draw(rect2);
>> rotator.concatenate(at);
>> g2.setFont(font.deriveFont(rotator));
>> g2.setPaint(Color.red);
>> g2.drawString(s, 0, 0);
>> // Rotate again.
>> rotator.setToIdentity();
>> rotator.rotate(2 * theta, rect.getCenterX(), rect.getCenterY());
>> rect2 = new GeneralPath(rotator.createTransformedShape(rect));
>> g2.setPaint(Color.blue);
>> g2.draw(rect2);
>> rotator.concatenate(at);
>> g2.setFont(font.deriveFont(rotator));
>> g2.setPaint(Color.red);
>> g2.drawString(s, 0, 0);
>> // Check scaled string bounds.
>> // this was handled by the fractional metrics rendering hint
>> }
>>
>> public static void main(String[] args) {
>> Test test = new Test();
>> test.setPreferredSize(new Dimension(800, 600));
>> JFrame f = new JFrame();
>> f.getContentPane().add(test);
>> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>> f.pack();
>> f.setVisible(true);
>> }
>> }
>>
>> Regards
>> Philippe M.
>>
>>
>>
>>
> --
> Rgds,Rory O'Donnell
> Quality Engineering Manager
> Oracle EMEA , Dublin, Ireland
>
>
--
Cordialement.
Philippe Mouawad.
--
Cordialement.
Philippe Mouawad.
Re: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of derived
Fonts ?
Posted by Philippe Mouawad <ph...@gmail.com>.
Thanks Felix
On Wednesday, November 19, 2014, Felix Schumacher <
felix.schumacher@internetallee.de> wrote:
> Am 19.11.2014 um 17:58 schrieb Philippe Mouawad:
>
>> Hi,
>> I tested on windows 7 , issue is not reproduced.
>> Don't have Linux to test.
>>
>> Maybe other member of team can do this.
>>
> Looks good on (well, I can read all text and none is mirrored).
> ubuntu 14.04 and
>
> java version "1.8.0_25"
> Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
> Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
>
> and
>
> java version "1.7.0_65"
> OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-0ubuntu0.14.04.1)
> OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
>
> Regards
> Felix
>
>>
>> Regards
>>
>> On Wed, Nov 19, 2014 at 4:45 PM, Balchandra Vaidya <
>> balchandra.vaidya@oracle.com> wrote:
>>
>> Hi Philippe,
>>>
>>> Here is the JBS ID - https://bugs.openjdk.java.net/browse/JDK-8065373.
>>> Did you see this issue only on Mac OS or did you see it on another
>>> OS/platform such as Windows?
>>>
>>> Thanks for reporting it.
>>>
>>> Regards,
>>> Balchandra
>>>
>>>
>>>
>>>
>>> On 11/19/14 03:11 PM, Philippe Mouawad wrote:
>>>
>>> Hi,
>>> JI-9016915 Regards
>>> Philippe
>>>
>>> On Wed, Nov 19, 2014 at 4:10 PM, Philippe Mouawad <
>>> philippe.mouawad@gmail.com> wrote:
>>>
>>> Hello Rory,
>>>> I posted a bug, waiting for mail notification.
>>>> It seems bug appeared after Java 7 u40 as I just tested now with Java7
>>>> u71 and it is also broken there.
>>>> I didn't test versions between 7u40 and 7u71.
>>>>
>>>> Regards
>>>> Philippe
>>>>
>>>> On Wed, Nov 19, 2014 at 3:44 PM, Rory O'Donnell <
>>>> rory.odonnell@oracle.com
>>>>
>>>>> wrote:
>>>>> Hi Philippe,
>>>>>
>>>>> Can you log a Java Incident and send us the JI number ?
>>>>>
>>>>> Rgds,Rory
>>>>> On 19/11/2014 14:36, Philippe Mouawad wrote:
>>>>>
>>>>> Hello Rory,
>>>>>> For information, I submitted this question on Swing-dev , I am not
>>>>>> sure
>>>>>> it
>>>>>> is the right list, if so hope you can help.
>>>>>>
>>>>>> Regards
>>>>>> Philippe
>>>>>> ---------- Forwarded message ----------
>>>>>> From: Philippe Mouawad <ph...@gmail.com>
>>>>>> Date: Wed, Nov 19, 2014 at 3:34 PM
>>>>>> Subject: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
>>>>>> derived
>>>>>> Fonts ?
>>>>>> To: swing-dev@openjdk.java.net
>>>>>>
>>>>>>
>>>>>> Hello,
>>>>>> We had recently a report of a bug on Apache JMeter:
>>>>>>
>>>>>> - https://issues.apache.org/bugzilla/show_bug.cgi?id=57221
>>>>>>
>>>>>>
>>>>>> The bug only occurs on Java 8 (u20 and u25).
>>>>>>
>>>>>> We use jCharts library.
>>>>>>
>>>>>> I narrowed the bug and it seems to come from the way derived fonts are
>>>>>> drawn:
>>>>>>
>>>>>> Library uses:
>>>>>>
>>>>>> public static final AffineTransform VERTICAL_ROTATION =
>>>>>> AffineTransform.getRotateInstance( -Math.PI / 2 );
>>>>>>
>>>>>> Then
>>>>>>
>>>>>> this.affineTransform= VERTICAL_ROTATION;
>>>>>> this.font.deriveFont( this.affineTransform )
>>>>>>
>>>>>> So I build a stupid and ugly isolated class to show issue, run it on
>>>>>> Java 7
>>>>>> display is fine , run it on Java8 result is strange.
>>>>>>
>>>>>> package org.jCharts;
>>>>>>
>>>>>> import java.awt.Color;
>>>>>> import java.awt.Dimension;
>>>>>> import java.awt.Font;
>>>>>> import java.awt.Graphics;
>>>>>> import java.awt.Graphics2D;
>>>>>> import java.awt.RenderingHints;
>>>>>> import java.awt.font.FontRenderContext;
>>>>>> import java.awt.font.LineMetrics;
>>>>>> import java.awt.geom.AffineTransform;
>>>>>> import java.awt.geom.GeneralPath;
>>>>>> import java.awt.geom.Rectangle2D;
>>>>>>
>>>>>> import javax.swing.JFrame;
>>>>>> import javax.swing.JPanel;
>>>>>>
>>>>>> public class Test extends JPanel {
>>>>>> Rectangle2D.Float rect = new Rectangle2D.Float(200, 200, 220,
>>>>>> 35);
>>>>>> // float theta = 1.1748778437843f;
>>>>>> double theta = Math.PI / 6;
>>>>>>
>>>>>> @Override
>>>>>> protected void paintComponent(Graphics g) {
>>>>>> super.paintComponent(g);
>>>>>> Graphics2D g2 = (Graphics2D) g;
>>>>>> g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
>>>>>> RenderingHints.VALUE_ANTIALIAS_ON);
>>>>>> g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
>>>>>> RenderingHints.VALUE_FRACTIONALMETRICS_ON);
>>>>>> g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
>>>>>> RenderingHints.VALUE_STROKE_PURE);
>>>>>> g2.setPaint(Color.blue);
>>>>>> Font font = g2.getFont().deriveFont(18f);
>>>>>> g2.setFont(font);
>>>>>> FontRenderContext frc = g2.getFontRenderContext();
>>>>>> String s = "This text should be rotated";
>>>>>> float width = (float) font.getStringBounds(s,
>>>>>> frc).getWidth();
>>>>>> LineMetrics lm = font.getLineMetrics(s, frc);
>>>>>> float height = lm.getAscent() + lm.getDescent();
>>>>>> // Scale text into rect.
>>>>>> float xScale = rect.width / width;
>>>>>> float yScale = rect.height / height;
>>>>>> float scale = (xScale > yScale) ? yScale : xScale;
>>>>>> // Locate string origin.
>>>>>> double x = rect.x;
>>>>>> double y = rect.y + (rect.height + scale * height) / 2 -
>>>>>> scale
>>>>>> * lm.getDescent();
>>>>>> AffineTransform at = AffineTransform.
>>>>>> getTranslateInstance(x,
>>>>>> y);
>>>>>> at.scale(scale, scale);
>>>>>> AffineTransform rotator = new AffineTransform();
>>>>>> rotator.rotate(theta, rect.getCenterX(), rect.getCenterY());
>>>>>> GeneralPath rect2 = new GeneralPath(
>>>>>> rotator.createTransformedShape(rect));
>>>>>> // Draw with no rotation.
>>>>>> g2.draw(rect);
>>>>>> g2.setPaint(Color.red);
>>>>>> g2.setFont(font.deriveFont(at));
>>>>>> g2.drawString(s, 0, 0);
>>>>>> // Rotate once.
>>>>>> g2.setPaint(Color.blue);
>>>>>> g2.draw(rect2);
>>>>>> rotator.concatenate(at);
>>>>>> g2.setFont(font.deriveFont(rotator));
>>>>>> g2.setPaint(Color.red);
>>>>>> g2.drawString(s, 0, 0);
>>>>>> // Rotate again.
>>>>>> rotator.setToIdentity();
>>>>>> rotator.rotate(2 * theta, rect.getCenterX(),
>>>>>> rect.getCenterY());
>>>>>> rect2 = new GeneralPath(rotator.
>>>>>> createTransformedShape(rect));
>>>>>> g2.setPaint(Color.blue);
>>>>>> g2.draw(rect2);
>>>>>> rotator.concatenate(at);
>>>>>> g2.setFont(font.deriveFont(rotator));
>>>>>> g2.setPaint(Color.red);
>>>>>> g2.drawString(s, 0, 0);
>>>>>> // Check scaled string bounds.
>>>>>> // this was handled by the fractional metrics rendering hint
>>>>>> }
>>>>>>
>>>>>> public static void main(String[] args) {
>>>>>> Test test = new Test();
>>>>>> test.setPreferredSize(new Dimension(800, 600));
>>>>>> JFrame f = new JFrame();
>>>>>> f.getContentPane().add(test);
>>>>>> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>>>>>> f.pack();
>>>>>> f.setVisible(true);
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> Regards
>>>>>> Philippe M.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>> Rgds,Rory O'Donnell
>>>>> Quality Engineering Manager
>>>>> Oracle EMEA , Dublin, Ireland
>>>>>
>>>>>
>>>>>
>>>> --
>>>> Cordialement.
>>>> Philippe Mouawad.
>>>>
>>>>
>>>>
>>>>
>>> --
>>> Cordialement.
>>> Philippe Mouawad.
>>>
>>>
>>>
>>>
>>>
>>
>
--
Cordialement.
Philippe Mouawad.
Re: Fwd: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
derived Fonts ?
Posted by Felix Schumacher <fe...@internetallee.de>.
Am 19.11.2014 um 17:58 schrieb Philippe Mouawad:
> Hi,
> I tested on windows 7 , issue is not reproduced.
> Don't have Linux to test.
>
> Maybe other member of team can do this.
Looks good on (well, I can read all text and none is mirrored).
ubuntu 14.04 and
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
and
java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-0ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
Regards
Felix
>
> Regards
>
> On Wed, Nov 19, 2014 at 4:45 PM, Balchandra Vaidya <
> balchandra.vaidya@oracle.com> wrote:
>
>> Hi Philippe,
>>
>> Here is the JBS ID - https://bugs.openjdk.java.net/browse/JDK-8065373.
>> Did you see this issue only on Mac OS or did you see it on another
>> OS/platform such as Windows?
>>
>> Thanks for reporting it.
>>
>> Regards,
>> Balchandra
>>
>>
>>
>>
>> On 11/19/14 03:11 PM, Philippe Mouawad wrote:
>>
>> Hi,
>> JI-9016915 Regards
>> Philippe
>>
>> On Wed, Nov 19, 2014 at 4:10 PM, Philippe Mouawad <
>> philippe.mouawad@gmail.com> wrote:
>>
>>> Hello Rory,
>>> I posted a bug, waiting for mail notification.
>>> It seems bug appeared after Java 7 u40 as I just tested now with Java7
>>> u71 and it is also broken there.
>>> I didn't test versions between 7u40 and 7u71.
>>>
>>> Regards
>>> Philippe
>>>
>>> On Wed, Nov 19, 2014 at 3:44 PM, Rory O'Donnell <rory.odonnell@oracle.com
>>>> wrote:
>>>> Hi Philippe,
>>>>
>>>> Can you log a Java Incident and send us the JI number ?
>>>>
>>>> Rgds,Rory
>>>> On 19/11/2014 14:36, Philippe Mouawad wrote:
>>>>
>>>>> Hello Rory,
>>>>> For information, I submitted this question on Swing-dev , I am not sure
>>>>> it
>>>>> is the right list, if so hope you can help.
>>>>>
>>>>> Regards
>>>>> Philippe
>>>>> ---------- Forwarded message ----------
>>>>> From: Philippe Mouawad <ph...@gmail.com>
>>>>> Date: Wed, Nov 19, 2014 at 3:34 PM
>>>>> Subject: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
>>>>> derived
>>>>> Fonts ?
>>>>> To: swing-dev@openjdk.java.net
>>>>>
>>>>>
>>>>> Hello,
>>>>> We had recently a report of a bug on Apache JMeter:
>>>>>
>>>>> - https://issues.apache.org/bugzilla/show_bug.cgi?id=57221
>>>>>
>>>>>
>>>>> The bug only occurs on Java 8 (u20 and u25).
>>>>>
>>>>> We use jCharts library.
>>>>>
>>>>> I narrowed the bug and it seems to come from the way derived fonts are
>>>>> drawn:
>>>>>
>>>>> Library uses:
>>>>>
>>>>> public static final AffineTransform VERTICAL_ROTATION =
>>>>> AffineTransform.getRotateInstance( -Math.PI / 2 );
>>>>>
>>>>> Then
>>>>>
>>>>> this.affineTransform= VERTICAL_ROTATION;
>>>>> this.font.deriveFont( this.affineTransform )
>>>>>
>>>>> So I build a stupid and ugly isolated class to show issue, run it on
>>>>> Java 7
>>>>> display is fine , run it on Java8 result is strange.
>>>>>
>>>>> package org.jCharts;
>>>>>
>>>>> import java.awt.Color;
>>>>> import java.awt.Dimension;
>>>>> import java.awt.Font;
>>>>> import java.awt.Graphics;
>>>>> import java.awt.Graphics2D;
>>>>> import java.awt.RenderingHints;
>>>>> import java.awt.font.FontRenderContext;
>>>>> import java.awt.font.LineMetrics;
>>>>> import java.awt.geom.AffineTransform;
>>>>> import java.awt.geom.GeneralPath;
>>>>> import java.awt.geom.Rectangle2D;
>>>>>
>>>>> import javax.swing.JFrame;
>>>>> import javax.swing.JPanel;
>>>>>
>>>>> public class Test extends JPanel {
>>>>> Rectangle2D.Float rect = new Rectangle2D.Float(200, 200, 220, 35);
>>>>> // float theta = 1.1748778437843f;
>>>>> double theta = Math.PI / 6;
>>>>>
>>>>> @Override
>>>>> protected void paintComponent(Graphics g) {
>>>>> super.paintComponent(g);
>>>>> Graphics2D g2 = (Graphics2D) g;
>>>>> g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
>>>>> RenderingHints.VALUE_ANTIALIAS_ON);
>>>>> g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
>>>>> RenderingHints.VALUE_FRACTIONALMETRICS_ON);
>>>>> g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
>>>>> RenderingHints.VALUE_STROKE_PURE);
>>>>> g2.setPaint(Color.blue);
>>>>> Font font = g2.getFont().deriveFont(18f);
>>>>> g2.setFont(font);
>>>>> FontRenderContext frc = g2.getFontRenderContext();
>>>>> String s = "This text should be rotated";
>>>>> float width = (float) font.getStringBounds(s, frc).getWidth();
>>>>> LineMetrics lm = font.getLineMetrics(s, frc);
>>>>> float height = lm.getAscent() + lm.getDescent();
>>>>> // Scale text into rect.
>>>>> float xScale = rect.width / width;
>>>>> float yScale = rect.height / height;
>>>>> float scale = (xScale > yScale) ? yScale : xScale;
>>>>> // Locate string origin.
>>>>> double x = rect.x;
>>>>> double y = rect.y + (rect.height + scale * height) / 2 - scale
>>>>> * lm.getDescent();
>>>>> AffineTransform at = AffineTransform.getTranslateInstance(x,
>>>>> y);
>>>>> at.scale(scale, scale);
>>>>> AffineTransform rotator = new AffineTransform();
>>>>> rotator.rotate(theta, rect.getCenterX(), rect.getCenterY());
>>>>> GeneralPath rect2 = new GeneralPath(
>>>>> rotator.createTransformedShape(rect));
>>>>> // Draw with no rotation.
>>>>> g2.draw(rect);
>>>>> g2.setPaint(Color.red);
>>>>> g2.setFont(font.deriveFont(at));
>>>>> g2.drawString(s, 0, 0);
>>>>> // Rotate once.
>>>>> g2.setPaint(Color.blue);
>>>>> g2.draw(rect2);
>>>>> rotator.concatenate(at);
>>>>> g2.setFont(font.deriveFont(rotator));
>>>>> g2.setPaint(Color.red);
>>>>> g2.drawString(s, 0, 0);
>>>>> // Rotate again.
>>>>> rotator.setToIdentity();
>>>>> rotator.rotate(2 * theta, rect.getCenterX(),
>>>>> rect.getCenterY());
>>>>> rect2 = new GeneralPath(rotator.createTransformedShape(rect));
>>>>> g2.setPaint(Color.blue);
>>>>> g2.draw(rect2);
>>>>> rotator.concatenate(at);
>>>>> g2.setFont(font.deriveFont(rotator));
>>>>> g2.setPaint(Color.red);
>>>>> g2.drawString(s, 0, 0);
>>>>> // Check scaled string bounds.
>>>>> // this was handled by the fractional metrics rendering hint
>>>>> }
>>>>>
>>>>> public static void main(String[] args) {
>>>>> Test test = new Test();
>>>>> test.setPreferredSize(new Dimension(800, 600));
>>>>> JFrame f = new JFrame();
>>>>> f.getContentPane().add(test);
>>>>> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>>>>> f.pack();
>>>>> f.setVisible(true);
>>>>> }
>>>>> }
>>>>>
>>>>> Regards
>>>>> Philippe M.
>>>>>
>>>>>
>>>>>
>>>>>
>>>> --
>>>> Rgds,Rory O'Donnell
>>>> Quality Engineering Manager
>>>> Oracle EMEA , Dublin, Ireland
>>>>
>>>>
>>>
>>> --
>>> Cordialement.
>>> Philippe Mouawad.
>>>
>>>
>>>
>>
>> --
>> Cordialement.
>> Philippe Mouawad.
>>
>>
>>
>>
>
Re: Fwd: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
derived Fonts ?
Posted by Balchandra Vaidya <ba...@oracle.com>.
Hi Philippe,
On 11/19/14 08:53 PM, Philippe Mouawad wrote:
> Hello,
> Thanks for fast answer and workaround although as it's a third party
> library it will be a problem. I tested workaround it is not enough as
> with it test is moved from its location.
>
Updated the bug JDK-8065373
<https://bugs.openjdk.java.net/browse/JDK-8065373> with your comments.
> Another point, looking at:
> https://bugs.openjdk.java.net/browse/JDK-8031109
>
> I don't see any progress on it , any chance it gets fixed ? I tested
> on Java 9, it is still there.
Thanks for confirming. I have added jdk 9 as affected version and also
increased the priority.
Thanks for reporting it.
Regards
Balchandra
> As there is a comment saying this, I am someone who is reporting it :-) :/
> Nevertheless if someone have a report against 9 - please reopen and
> add affectedVersion 9 or 7u specific escalations might be reopen to
> Sustaining /
>
> Regards
> Philippe
>
> On Wed, Nov 19, 2014 at 7:02 PM, Balchandra Vaidya
> <balchandra.vaidya@oracle.com <ma...@oracle.com>>
> wrote:
>
>
> Hi Philippe,
>
>
> Thanks for the update. Sergey Bylokhov provided a following
> workaround in the bug JDK-8065373
> <https://bugs.openjdk.java.net/browse/JDK-8065373>.
>
> Workaround is to apply a transfrom to the graphics instead of
> font:
> + g2.transform(rotator);
> - g2.setFont(font.deriveFont(rotator));
>
>
> He has also provided a suggested fix. A blog [1] from Dalibor
> might help you to track the JBS bug yourself.
>
>
>
> Thanks
> Balchandra
>
> [1] http://robilad.livejournal.com/139637.html
>
>
>
>
>
> On 11/19/14 04:58 PM, Philippe Mouawad wrote:
>> Hi,
>> I tested on windows 7 , issue is not reproduced.
>> Don't have Linux to test.
>>
>> Maybe other member of team can do this.
>>
>> Regards
>>
>> On Wed, Nov 19, 2014 at 4:45 PM, Balchandra Vaidya
>> <balchandra.vaidya@oracle.com
>> <ma...@oracle.com>> wrote:
>>
>>
>> Hi Philippe,
>>
>> Here is the JBS ID -
>> https://bugs.openjdk.java.net/browse/JDK-8065373.
>> Did you see this issue only on Mac OS or did you see it on
>> another
>> OS/platform such as Windows?
>>
>> Thanks for reporting it.
>>
>> Regards,
>> Balchandra
>>
>>
>>
>>
>> On 11/19/14 03:11 PM, Philippe Mouawad wrote:
>>> Hi,
>>>
>>>
>>> JI-9016915
>>>
>>> Regards
>>> Philippe
>>>
>>> On Wed, Nov 19, 2014 at 4:10 PM, Philippe Mouawad
>>> <philippe.mouawad@gmail.com
>>> <ma...@gmail.com>> wrote:
>>>
>>> Hello Rory,
>>> I posted a bug, waiting for mail notification.
>>> It seems bug appeared after Java 7 u40 as I just tested
>>> now with Java7 u71 and it is also broken there.
>>> I didn't test versions between 7u40 and 7u71.
>>>
>>> Regards
>>> Philippe
>>>
>>> On Wed, Nov 19, 2014 at 3:44 PM, Rory O'Donnell
>>> <rory.odonnell@oracle.com
>>> <ma...@oracle.com>> wrote:
>>>
>>> Hi Philippe,
>>>
>>> Can you log a Java Incident and send us the JI number ?
>>>
>>> Rgds,Rory
>>> On 19/11/2014 14:36, Philippe Mouawad wrote:
>>>
>>> Hello Rory,
>>> For information, I submitted this question on
>>> Swing-dev , I am not sure it
>>> is the right list, if so hope you can help.
>>>
>>> Regards
>>> Philippe
>>> ---------- Forwarded message ----------
>>> From: Philippe Mouawad
>>> <philippe.mouawad@gmail.com
>>> <ma...@gmail.com>>
>>> Date: Wed, Nov 19, 2014 at 3:34 PM
>>> Subject: JAVA8u20 and JAVA8u25 Regression in
>>> Graphics2D drawing of derived
>>> Fonts ?
>>> To: swing-dev@openjdk.java.net
>>> <ma...@openjdk.java.net>
>>>
>>>
>>> Hello,
>>> We had recently a report of a bug on Apache JMeter:
>>>
>>> -
>>> https://issues.apache.org/bugzilla/show_bug.cgi?id=57221
>>>
>>>
>>>
>>> The bug only occurs on Java 8 (u20 and u25).
>>>
>>> We use jCharts library.
>>>
>>> I narrowed the bug and it seems to come from the
>>> way derived fonts are
>>> drawn:
>>>
>>> Library uses:
>>>
>>> public static final AffineTransform
>>> VERTICAL_ROTATION =
>>> AffineTransform.getRotateInstance( -Math.PI / 2 );
>>>
>>> Then
>>>
>>> this.affineTransform= VERTICAL_ROTATION;
>>> this.font.deriveFont( this.affineTransform )
>>>
>>> So I build a stupid and ugly isolated class to
>>> show issue, run it on Java 7
>>> display is fine , run it on Java8 result is strange.
>>>
>>> package org.jCharts;
>>>
>>> import java.awt.Color;
>>> import java.awt.Dimension;
>>> import java.awt.Font;
>>> import java.awt.Graphics;
>>> import java.awt.Graphics2D;
>>> import java.awt.RenderingHints;
>>> import java.awt.font.FontRenderContext;
>>> import java.awt.font.LineMetrics;
>>> import java.awt.geom.AffineTransform;
>>> import java.awt.geom.GeneralPath;
>>> import java.awt.geom.Rectangle2D;
>>>
>>> import javax.swing.JFrame;
>>> import javax.swing.JPanel;
>>>
>>> public class Test extends JPanel {
>>> Rectangle2D.Float rect = new
>>> Rectangle2D.Float(200, 200, 220, 35);
>>> // float theta = 1.1748778437843f;
>>> double theta = Math.PI / 6;
>>>
>>> @Override
>>> protected void paintComponent(Graphics g) {
>>> super.paintComponent(g);
>>> Graphics2D g2 = (Graphics2D) g;
>>> g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
>>> RenderingHints.VALUE_ANTIALIAS_ON);
>>> g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
>>> RenderingHints.VALUE_FRACTIONALMETRICS_ON);
>>> g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
>>> RenderingHints.VALUE_STROKE_PURE);
>>> g2.setPaint(Color.blue);
>>> Font font = g2.getFont().deriveFont(18f);
>>> g2.setFont(font);
>>> FontRenderContext frc = g2.getFontRenderContext();
>>> String s = "This text should be rotated";
>>> float width = (float)
>>> font.getStringBounds(s, frc).getWidth();
>>> LineMetrics lm = font.getLineMetrics(s, frc);
>>> float height = lm.getAscent() +
>>> lm.getDescent();
>>> // Scale text into rect.
>>> float xScale = rect.width / width;
>>> float yScale = rect.height / height;
>>> float scale = (xScale > yScale) ?
>>> yScale : xScale;
>>> // Locate string origin.
>>> double x = rect.x;
>>> double y = rect.y + (rect.height +
>>> scale * height) / 2 - scale
>>> * lm.getDescent();
>>> AffineTransform at =
>>> AffineTransform.getTranslateInstance(x, y);
>>> at.scale(scale, scale);
>>> AffineTransform rotator = new AffineTransform();
>>> rotator.rotate(theta, rect.getCenterX(),
>>> rect.getCenterY());
>>> GeneralPath rect2 = new GeneralPath(
>>> rotator.createTransformedShape(rect));
>>> // Draw with no rotation.
>>> g2.draw(rect);
>>> g2.setPaint(Color.red);
>>> g2.setFont(font.deriveFont(at));
>>> g2.drawString(s, 0, 0);
>>> // Rotate once.
>>> g2.setPaint(Color.blue);
>>> g2.draw(rect2);
>>> rotator.concatenate(at);
>>> g2.setFont(font.deriveFont(rotator));
>>> g2.setPaint(Color.red);
>>> g2.drawString(s, 0, 0);
>>> // Rotate again.
>>> rotator.setToIdentity();
>>> rotator.rotate(2 * theta, rect.getCenterX(),
>>> rect.getCenterY());
>>> rect2 = new
>>> GeneralPath(rotator.createTransformedShape(rect));
>>> g2.setPaint(Color.blue);
>>> g2.draw(rect2);
>>> rotator.concatenate(at);
>>> g2.setFont(font.deriveFont(rotator));
>>> g2.setPaint(Color.red);
>>> g2.drawString(s, 0, 0);
>>> // Check scaled string bounds.
>>> // this was handled by the fractional
>>> metrics rendering hint
>>> }
>>>
>>> public static void main(String[] args) {
>>> Test test = new Test();
>>> test.setPreferredSize(new Dimension(800, 600));
>>> JFrame f = new JFrame();
>>> f.getContentPane().add(test);
>>> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>>> f.pack();
>>> f.setVisible(true);
>>> }
>>> }
>>>
>>> Regards
>>> Philippe M.
>>>
>>>
>>>
>>>
>>> --
>>> Rgds,Rory O'Donnell
>>> Quality Engineering Manager
>>> Oracle EMEA , Dublin, Ireland
>>>
>>>
>>>
>>>
>>> --
>>> Cordialement.
>>> Philippe Mouawad.
>>>
>>>
>>>
>>>
>>>
>>> --
>>> Cordialement.
>>> Philippe Mouawad.
>>>
>>>
>>
>>
>>
>>
>> --
>> Cordialement.
>> Philippe Mouawad.
>>
>>
>
>
>
>
> --
> Cordialement.
> Philippe Mouawad.
>
>
Re: Fwd: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
derived Fonts ?
Posted by Philippe Mouawad <ph...@gmail.com>.
Hello,
Thanks for fast answer and workaround although as it's a third party
library it will be a problem. I tested workaround it is not enough as with
it test is moved from its location.
Another point, looking at:
https://bugs.openjdk.java.net/browse/JDK-8031109
I don't see any progress on it , any chance it gets fixed ? I tested on
Java 9, it is still there.
As there is a comment saying this, I am someone who is reporting it :-) :
*Nevertheless if someone have a report against 9 - please reopen and add
affectedVersion 9 or 7u specific escalations might be reopen to Sustaining *
Regards
Philippe
On Wed, Nov 19, 2014 at 7:02 PM, Balchandra Vaidya <
balchandra.vaidya@oracle.com> wrote:
>
> Hi Philippe,
>
>
> Thanks for the update. Sergey Bylokhov provided a following
> workaround in the bug JDK-8065373
> <https://bugs.openjdk.java.net/browse/JDK-8065373>.
>
> Workaround is to apply a transfrom to the graphics instead of font:
> + g2.transform(rotator);
> - g2.setFont(font.deriveFont(rotator));
>
>
> He has also provided a suggested fix. A blog [1] from Dalibor
> might help you to track the JBS bug yourself.
>
>
>
> Thanks
> Balchandra
>
> [1] http://robilad.livejournal.com/139637.html
>
>
>
>
>
> On 11/19/14 04:58 PM, Philippe Mouawad wrote:
>
> Hi,
> I tested on windows 7 , issue is not reproduced.
> Don't have Linux to test.
>
> Maybe other member of team can do this.
>
> Regards
>
> On Wed, Nov 19, 2014 at 4:45 PM, Balchandra Vaidya <
> balchandra.vaidya@oracle.com> wrote:
>
>>
>> Hi Philippe,
>>
>> Here is the JBS ID - https://bugs.openjdk.java.net/browse/JDK-8065373.
>> Did you see this issue only on Mac OS or did you see it on another
>> OS/platform such as Windows?
>>
>> Thanks for reporting it.
>>
>> Regards,
>> Balchandra
>>
>>
>>
>>
>> On 11/19/14 03:11 PM, Philippe Mouawad wrote:
>>
>> Hi,
>> JI-9016915 Regards
>> Philippe
>>
>> On Wed, Nov 19, 2014 at 4:10 PM, Philippe Mouawad <
>> philippe.mouawad@gmail.com> wrote:
>>
>>> Hello Rory,
>>> I posted a bug, waiting for mail notification.
>>> It seems bug appeared after Java 7 u40 as I just tested now with Java7
>>> u71 and it is also broken there.
>>> I didn't test versions between 7u40 and 7u71.
>>>
>>> Regards
>>> Philippe
>>>
>>> On Wed, Nov 19, 2014 at 3:44 PM, Rory O'Donnell <
>>> rory.odonnell@oracle.com> wrote:
>>>
>>>> Hi Philippe,
>>>>
>>>> Can you log a Java Incident and send us the JI number ?
>>>>
>>>> Rgds,Rory
>>>> On 19/11/2014 14:36, Philippe Mouawad wrote:
>>>>
>>>>> Hello Rory,
>>>>> For information, I submitted this question on Swing-dev , I am not
>>>>> sure it
>>>>> is the right list, if so hope you can help.
>>>>>
>>>>> Regards
>>>>> Philippe
>>>>> ---------- Forwarded message ----------
>>>>> From: Philippe Mouawad <ph...@gmail.com>
>>>>> Date: Wed, Nov 19, 2014 at 3:34 PM
>>>>> Subject: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
>>>>> derived
>>>>> Fonts ?
>>>>> To: swing-dev@openjdk.java.net
>>>>>
>>>>>
>>>>> Hello,
>>>>> We had recently a report of a bug on Apache JMeter:
>>>>>
>>>>> - https://issues.apache.org/bugzilla/show_bug.cgi?id=57221
>>>>>
>>>>>
>>>>> The bug only occurs on Java 8 (u20 and u25).
>>>>>
>>>>> We use jCharts library.
>>>>>
>>>>> I narrowed the bug and it seems to come from the way derived fonts are
>>>>> drawn:
>>>>>
>>>>> Library uses:
>>>>>
>>>>> public static final AffineTransform VERTICAL_ROTATION =
>>>>> AffineTransform.getRotateInstance( -Math.PI / 2 );
>>>>>
>>>>> Then
>>>>>
>>>>> this.affineTransform= VERTICAL_ROTATION;
>>>>> this.font.deriveFont( this.affineTransform )
>>>>>
>>>>> So I build a stupid and ugly isolated class to show issue, run it on
>>>>> Java 7
>>>>> display is fine , run it on Java8 result is strange.
>>>>>
>>>>> package org.jCharts;
>>>>>
>>>>> import java.awt.Color;
>>>>> import java.awt.Dimension;
>>>>> import java.awt.Font;
>>>>> import java.awt.Graphics;
>>>>> import java.awt.Graphics2D;
>>>>> import java.awt.RenderingHints;
>>>>> import java.awt.font.FontRenderContext;
>>>>> import java.awt.font.LineMetrics;
>>>>> import java.awt.geom.AffineTransform;
>>>>> import java.awt.geom.GeneralPath;
>>>>> import java.awt.geom.Rectangle2D;
>>>>>
>>>>> import javax.swing.JFrame;
>>>>> import javax.swing.JPanel;
>>>>>
>>>>> public class Test extends JPanel {
>>>>> Rectangle2D.Float rect = new Rectangle2D.Float(200, 200, 220, 35);
>>>>> // float theta = 1.1748778437843f;
>>>>> double theta = Math.PI / 6;
>>>>>
>>>>> @Override
>>>>> protected void paintComponent(Graphics g) {
>>>>> super.paintComponent(g);
>>>>> Graphics2D g2 = (Graphics2D) g;
>>>>> g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
>>>>> RenderingHints.VALUE_ANTIALIAS_ON);
>>>>> g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
>>>>> RenderingHints.VALUE_FRACTIONALMETRICS_ON);
>>>>> g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
>>>>> RenderingHints.VALUE_STROKE_PURE);
>>>>> g2.setPaint(Color.blue);
>>>>> Font font = g2.getFont().deriveFont(18f);
>>>>> g2.setFont(font);
>>>>> FontRenderContext frc = g2.getFontRenderContext();
>>>>> String s = "This text should be rotated";
>>>>> float width = (float) font.getStringBounds(s, frc).getWidth();
>>>>> LineMetrics lm = font.getLineMetrics(s, frc);
>>>>> float height = lm.getAscent() + lm.getDescent();
>>>>> // Scale text into rect.
>>>>> float xScale = rect.width / width;
>>>>> float yScale = rect.height / height;
>>>>> float scale = (xScale > yScale) ? yScale : xScale;
>>>>> // Locate string origin.
>>>>> double x = rect.x;
>>>>> double y = rect.y + (rect.height + scale * height) / 2 - scale
>>>>> * lm.getDescent();
>>>>> AffineTransform at = AffineTransform.getTranslateInstance(x,
>>>>> y);
>>>>> at.scale(scale, scale);
>>>>> AffineTransform rotator = new AffineTransform();
>>>>> rotator.rotate(theta, rect.getCenterX(), rect.getCenterY());
>>>>> GeneralPath rect2 = new GeneralPath(
>>>>> rotator.createTransformedShape(rect));
>>>>> // Draw with no rotation.
>>>>> g2.draw(rect);
>>>>> g2.setPaint(Color.red);
>>>>> g2.setFont(font.deriveFont(at));
>>>>> g2.drawString(s, 0, 0);
>>>>> // Rotate once.
>>>>> g2.setPaint(Color.blue);
>>>>> g2.draw(rect2);
>>>>> rotator.concatenate(at);
>>>>> g2.setFont(font.deriveFont(rotator));
>>>>> g2.setPaint(Color.red);
>>>>> g2.drawString(s, 0, 0);
>>>>> // Rotate again.
>>>>> rotator.setToIdentity();
>>>>> rotator.rotate(2 * theta, rect.getCenterX(),
>>>>> rect.getCenterY());
>>>>> rect2 = new GeneralPath(rotator.createTransformedShape(rect));
>>>>> g2.setPaint(Color.blue);
>>>>> g2.draw(rect2);
>>>>> rotator.concatenate(at);
>>>>> g2.setFont(font.deriveFont(rotator));
>>>>> g2.setPaint(Color.red);
>>>>> g2.drawString(s, 0, 0);
>>>>> // Check scaled string bounds.
>>>>> // this was handled by the fractional metrics rendering hint
>>>>> }
>>>>>
>>>>> public static void main(String[] args) {
>>>>> Test test = new Test();
>>>>> test.setPreferredSize(new Dimension(800, 600));
>>>>> JFrame f = new JFrame();
>>>>> f.getContentPane().add(test);
>>>>> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>>>>> f.pack();
>>>>> f.setVisible(true);
>>>>> }
>>>>> }
>>>>>
>>>>> Regards
>>>>> Philippe M.
>>>>>
>>>>>
>>>>>
>>>>>
>>>> --
>>>> Rgds,Rory O'Donnell
>>>> Quality Engineering Manager
>>>> Oracle EMEA , Dublin, Ireland
>>>>
>>>>
>>>
>>>
>>> --
>>> Cordialement.
>>> Philippe Mouawad.
>>>
>>>
>>>
>>
>>
>> --
>> Cordialement.
>> Philippe Mouawad.
>>
>>
>>
>>
>
>
> --
> Cordialement.
> Philippe Mouawad.
>
>
>
>
--
Cordialement.
Philippe Mouawad.
Re: Fwd: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
derived Fonts ?
Posted by Philippe Mouawad <ph...@gmail.com>.
Hi,
I tested on windows 7 , issue is not reproduced.
Don't have Linux to test.
Maybe other member of team can do this.
Regards
On Wed, Nov 19, 2014 at 4:45 PM, Balchandra Vaidya <
balchandra.vaidya@oracle.com> wrote:
>
> Hi Philippe,
>
> Here is the JBS ID - https://bugs.openjdk.java.net/browse/JDK-8065373.
> Did you see this issue only on Mac OS or did you see it on another
> OS/platform such as Windows?
>
> Thanks for reporting it.
>
> Regards,
> Balchandra
>
>
>
>
> On 11/19/14 03:11 PM, Philippe Mouawad wrote:
>
> Hi,
> JI-9016915 Regards
> Philippe
>
> On Wed, Nov 19, 2014 at 4:10 PM, Philippe Mouawad <
> philippe.mouawad@gmail.com> wrote:
>
>> Hello Rory,
>> I posted a bug, waiting for mail notification.
>> It seems bug appeared after Java 7 u40 as I just tested now with Java7
>> u71 and it is also broken there.
>> I didn't test versions between 7u40 and 7u71.
>>
>> Regards
>> Philippe
>>
>> On Wed, Nov 19, 2014 at 3:44 PM, Rory O'Donnell <rory.odonnell@oracle.com
>> > wrote:
>>
>>> Hi Philippe,
>>>
>>> Can you log a Java Incident and send us the JI number ?
>>>
>>> Rgds,Rory
>>> On 19/11/2014 14:36, Philippe Mouawad wrote:
>>>
>>>> Hello Rory,
>>>> For information, I submitted this question on Swing-dev , I am not sure
>>>> it
>>>> is the right list, if so hope you can help.
>>>>
>>>> Regards
>>>> Philippe
>>>> ---------- Forwarded message ----------
>>>> From: Philippe Mouawad <ph...@gmail.com>
>>>> Date: Wed, Nov 19, 2014 at 3:34 PM
>>>> Subject: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
>>>> derived
>>>> Fonts ?
>>>> To: swing-dev@openjdk.java.net
>>>>
>>>>
>>>> Hello,
>>>> We had recently a report of a bug on Apache JMeter:
>>>>
>>>> - https://issues.apache.org/bugzilla/show_bug.cgi?id=57221
>>>>
>>>>
>>>> The bug only occurs on Java 8 (u20 and u25).
>>>>
>>>> We use jCharts library.
>>>>
>>>> I narrowed the bug and it seems to come from the way derived fonts are
>>>> drawn:
>>>>
>>>> Library uses:
>>>>
>>>> public static final AffineTransform VERTICAL_ROTATION =
>>>> AffineTransform.getRotateInstance( -Math.PI / 2 );
>>>>
>>>> Then
>>>>
>>>> this.affineTransform= VERTICAL_ROTATION;
>>>> this.font.deriveFont( this.affineTransform )
>>>>
>>>> So I build a stupid and ugly isolated class to show issue, run it on
>>>> Java 7
>>>> display is fine , run it on Java8 result is strange.
>>>>
>>>> package org.jCharts;
>>>>
>>>> import java.awt.Color;
>>>> import java.awt.Dimension;
>>>> import java.awt.Font;
>>>> import java.awt.Graphics;
>>>> import java.awt.Graphics2D;
>>>> import java.awt.RenderingHints;
>>>> import java.awt.font.FontRenderContext;
>>>> import java.awt.font.LineMetrics;
>>>> import java.awt.geom.AffineTransform;
>>>> import java.awt.geom.GeneralPath;
>>>> import java.awt.geom.Rectangle2D;
>>>>
>>>> import javax.swing.JFrame;
>>>> import javax.swing.JPanel;
>>>>
>>>> public class Test extends JPanel {
>>>> Rectangle2D.Float rect = new Rectangle2D.Float(200, 200, 220, 35);
>>>> // float theta = 1.1748778437843f;
>>>> double theta = Math.PI / 6;
>>>>
>>>> @Override
>>>> protected void paintComponent(Graphics g) {
>>>> super.paintComponent(g);
>>>> Graphics2D g2 = (Graphics2D) g;
>>>> g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
>>>> RenderingHints.VALUE_ANTIALIAS_ON);
>>>> g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
>>>> RenderingHints.VALUE_FRACTIONALMETRICS_ON);
>>>> g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
>>>> RenderingHints.VALUE_STROKE_PURE);
>>>> g2.setPaint(Color.blue);
>>>> Font font = g2.getFont().deriveFont(18f);
>>>> g2.setFont(font);
>>>> FontRenderContext frc = g2.getFontRenderContext();
>>>> String s = "This text should be rotated";
>>>> float width = (float) font.getStringBounds(s, frc).getWidth();
>>>> LineMetrics lm = font.getLineMetrics(s, frc);
>>>> float height = lm.getAscent() + lm.getDescent();
>>>> // Scale text into rect.
>>>> float xScale = rect.width / width;
>>>> float yScale = rect.height / height;
>>>> float scale = (xScale > yScale) ? yScale : xScale;
>>>> // Locate string origin.
>>>> double x = rect.x;
>>>> double y = rect.y + (rect.height + scale * height) / 2 - scale
>>>> * lm.getDescent();
>>>> AffineTransform at = AffineTransform.getTranslateInstance(x,
>>>> y);
>>>> at.scale(scale, scale);
>>>> AffineTransform rotator = new AffineTransform();
>>>> rotator.rotate(theta, rect.getCenterX(), rect.getCenterY());
>>>> GeneralPath rect2 = new GeneralPath(
>>>> rotator.createTransformedShape(rect));
>>>> // Draw with no rotation.
>>>> g2.draw(rect);
>>>> g2.setPaint(Color.red);
>>>> g2.setFont(font.deriveFont(at));
>>>> g2.drawString(s, 0, 0);
>>>> // Rotate once.
>>>> g2.setPaint(Color.blue);
>>>> g2.draw(rect2);
>>>> rotator.concatenate(at);
>>>> g2.setFont(font.deriveFont(rotator));
>>>> g2.setPaint(Color.red);
>>>> g2.drawString(s, 0, 0);
>>>> // Rotate again.
>>>> rotator.setToIdentity();
>>>> rotator.rotate(2 * theta, rect.getCenterX(),
>>>> rect.getCenterY());
>>>> rect2 = new GeneralPath(rotator.createTransformedShape(rect));
>>>> g2.setPaint(Color.blue);
>>>> g2.draw(rect2);
>>>> rotator.concatenate(at);
>>>> g2.setFont(font.deriveFont(rotator));
>>>> g2.setPaint(Color.red);
>>>> g2.drawString(s, 0, 0);
>>>> // Check scaled string bounds.
>>>> // this was handled by the fractional metrics rendering hint
>>>> }
>>>>
>>>> public static void main(String[] args) {
>>>> Test test = new Test();
>>>> test.setPreferredSize(new Dimension(800, 600));
>>>> JFrame f = new JFrame();
>>>> f.getContentPane().add(test);
>>>> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>>>> f.pack();
>>>> f.setVisible(true);
>>>> }
>>>> }
>>>>
>>>> Regards
>>>> Philippe M.
>>>>
>>>>
>>>>
>>>>
>>> --
>>> Rgds,Rory O'Donnell
>>> Quality Engineering Manager
>>> Oracle EMEA , Dublin, Ireland
>>>
>>>
>>
>>
>> --
>> Cordialement.
>> Philippe Mouawad.
>>
>>
>>
>
>
> --
> Cordialement.
> Philippe Mouawad.
>
>
>
>
--
Cordialement.
Philippe Mouawad.
Re: Fwd: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
derived Fonts ?
Posted by Philippe Mouawad <ph...@gmail.com>.
Hi,
JI-9016915Regards
Philippe
On Wed, Nov 19, 2014 at 4:10 PM, Philippe Mouawad <
philippe.mouawad@gmail.com> wrote:
> Hello Rory,
> I posted a bug, waiting for mail notification.
> It seems bug appeared after Java 7 u40 as I just tested now with Java7 u71
> and it is also broken there.
> I didn't test versions between 7u40 and 7u71.
>
> Regards
> Philippe
>
> On Wed, Nov 19, 2014 at 3:44 PM, Rory O'Donnell <ro...@oracle.com>
> wrote:
>
>> Hi Philippe,
>>
>> Can you log a Java Incident and send us the JI number ?
>>
>> Rgds,Rory
>> On 19/11/2014 14:36, Philippe Mouawad wrote:
>>
>>> Hello Rory,
>>> For information, I submitted this question on Swing-dev , I am not sure
>>> it
>>> is the right list, if so hope you can help.
>>>
>>> Regards
>>> Philippe
>>> ---------- Forwarded message ----------
>>> From: Philippe Mouawad <ph...@gmail.com>
>>> Date: Wed, Nov 19, 2014 at 3:34 PM
>>> Subject: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
>>> derived
>>> Fonts ?
>>> To: swing-dev@openjdk.java.net
>>>
>>>
>>> Hello,
>>> We had recently a report of a bug on Apache JMeter:
>>>
>>> - https://issues.apache.org/bugzilla/show_bug.cgi?id=57221
>>>
>>>
>>> The bug only occurs on Java 8 (u20 and u25).
>>>
>>> We use jCharts library.
>>>
>>> I narrowed the bug and it seems to come from the way derived fonts are
>>> drawn:
>>>
>>> Library uses:
>>>
>>> public static final AffineTransform VERTICAL_ROTATION =
>>> AffineTransform.getRotateInstance( -Math.PI / 2 );
>>>
>>> Then
>>>
>>> this.affineTransform= VERTICAL_ROTATION;
>>> this.font.deriveFont( this.affineTransform )
>>>
>>> So I build a stupid and ugly isolated class to show issue, run it on
>>> Java 7
>>> display is fine , run it on Java8 result is strange.
>>>
>>> package org.jCharts;
>>>
>>> import java.awt.Color;
>>> import java.awt.Dimension;
>>> import java.awt.Font;
>>> import java.awt.Graphics;
>>> import java.awt.Graphics2D;
>>> import java.awt.RenderingHints;
>>> import java.awt.font.FontRenderContext;
>>> import java.awt.font.LineMetrics;
>>> import java.awt.geom.AffineTransform;
>>> import java.awt.geom.GeneralPath;
>>> import java.awt.geom.Rectangle2D;
>>>
>>> import javax.swing.JFrame;
>>> import javax.swing.JPanel;
>>>
>>> public class Test extends JPanel {
>>> Rectangle2D.Float rect = new Rectangle2D.Float(200, 200, 220, 35);
>>> // float theta = 1.1748778437843f;
>>> double theta = Math.PI / 6;
>>>
>>> @Override
>>> protected void paintComponent(Graphics g) {
>>> super.paintComponent(g);
>>> Graphics2D g2 = (Graphics2D) g;
>>> g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
>>> RenderingHints.VALUE_ANTIALIAS_ON);
>>> g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
>>> RenderingHints.VALUE_FRACTIONALMETRICS_ON);
>>> g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
>>> RenderingHints.VALUE_STROKE_PURE);
>>> g2.setPaint(Color.blue);
>>> Font font = g2.getFont().deriveFont(18f);
>>> g2.setFont(font);
>>> FontRenderContext frc = g2.getFontRenderContext();
>>> String s = "This text should be rotated";
>>> float width = (float) font.getStringBounds(s, frc).getWidth();
>>> LineMetrics lm = font.getLineMetrics(s, frc);
>>> float height = lm.getAscent() + lm.getDescent();
>>> // Scale text into rect.
>>> float xScale = rect.width / width;
>>> float yScale = rect.height / height;
>>> float scale = (xScale > yScale) ? yScale : xScale;
>>> // Locate string origin.
>>> double x = rect.x;
>>> double y = rect.y + (rect.height + scale * height) / 2 - scale
>>> * lm.getDescent();
>>> AffineTransform at = AffineTransform.getTranslateInstance(x,
>>> y);
>>> at.scale(scale, scale);
>>> AffineTransform rotator = new AffineTransform();
>>> rotator.rotate(theta, rect.getCenterX(), rect.getCenterY());
>>> GeneralPath rect2 = new GeneralPath(
>>> rotator.createTransformedShape(rect));
>>> // Draw with no rotation.
>>> g2.draw(rect);
>>> g2.setPaint(Color.red);
>>> g2.setFont(font.deriveFont(at));
>>> g2.drawString(s, 0, 0);
>>> // Rotate once.
>>> g2.setPaint(Color.blue);
>>> g2.draw(rect2);
>>> rotator.concatenate(at);
>>> g2.setFont(font.deriveFont(rotator));
>>> g2.setPaint(Color.red);
>>> g2.drawString(s, 0, 0);
>>> // Rotate again.
>>> rotator.setToIdentity();
>>> rotator.rotate(2 * theta, rect.getCenterX(), rect.getCenterY());
>>> rect2 = new GeneralPath(rotator.createTransformedShape(rect));
>>> g2.setPaint(Color.blue);
>>> g2.draw(rect2);
>>> rotator.concatenate(at);
>>> g2.setFont(font.deriveFont(rotator));
>>> g2.setPaint(Color.red);
>>> g2.drawString(s, 0, 0);
>>> // Check scaled string bounds.
>>> // this was handled by the fractional metrics rendering hint
>>> }
>>>
>>> public static void main(String[] args) {
>>> Test test = new Test();
>>> test.setPreferredSize(new Dimension(800, 600));
>>> JFrame f = new JFrame();
>>> f.getContentPane().add(test);
>>> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>>> f.pack();
>>> f.setVisible(true);
>>> }
>>> }
>>>
>>> Regards
>>> Philippe M.
>>>
>>>
>>>
>>>
>> --
>> Rgds,Rory O'Donnell
>> Quality Engineering Manager
>> Oracle EMEA , Dublin, Ireland
>>
>>
>
>
> --
> Cordialement.
> Philippe Mouawad.
>
>
>
--
Cordialement.
Philippe Mouawad.
Re: Fwd: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
derived Fonts ?
Posted by Philippe Mouawad <ph...@gmail.com>.
Hello Rory,
I posted a bug, waiting for mail notification.
It seems bug appeared after Java 7 u40 as I just tested now with Java7 u71
and it is also broken there.
I didn't test versions between 7u40 and 7u71.
Regards
Philippe
On Wed, Nov 19, 2014 at 3:44 PM, Rory O'Donnell <ro...@oracle.com>
wrote:
> Hi Philippe,
>
> Can you log a Java Incident and send us the JI number ?
>
> Rgds,Rory
> On 19/11/2014 14:36, Philippe Mouawad wrote:
>
>> Hello Rory,
>> For information, I submitted this question on Swing-dev , I am not sure it
>> is the right list, if so hope you can help.
>>
>> Regards
>> Philippe
>> ---------- Forwarded message ----------
>> From: Philippe Mouawad <ph...@gmail.com>
>> Date: Wed, Nov 19, 2014 at 3:34 PM
>> Subject: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of derived
>> Fonts ?
>> To: swing-dev@openjdk.java.net
>>
>>
>> Hello,
>> We had recently a report of a bug on Apache JMeter:
>>
>> - https://issues.apache.org/bugzilla/show_bug.cgi?id=57221
>>
>>
>> The bug only occurs on Java 8 (u20 and u25).
>>
>> We use jCharts library.
>>
>> I narrowed the bug and it seems to come from the way derived fonts are
>> drawn:
>>
>> Library uses:
>>
>> public static final AffineTransform VERTICAL_ROTATION =
>> AffineTransform.getRotateInstance( -Math.PI / 2 );
>>
>> Then
>>
>> this.affineTransform= VERTICAL_ROTATION;
>> this.font.deriveFont( this.affineTransform )
>>
>> So I build a stupid and ugly isolated class to show issue, run it on Java
>> 7
>> display is fine , run it on Java8 result is strange.
>>
>> package org.jCharts;
>>
>> import java.awt.Color;
>> import java.awt.Dimension;
>> import java.awt.Font;
>> import java.awt.Graphics;
>> import java.awt.Graphics2D;
>> import java.awt.RenderingHints;
>> import java.awt.font.FontRenderContext;
>> import java.awt.font.LineMetrics;
>> import java.awt.geom.AffineTransform;
>> import java.awt.geom.GeneralPath;
>> import java.awt.geom.Rectangle2D;
>>
>> import javax.swing.JFrame;
>> import javax.swing.JPanel;
>>
>> public class Test extends JPanel {
>> Rectangle2D.Float rect = new Rectangle2D.Float(200, 200, 220, 35);
>> // float theta = 1.1748778437843f;
>> double theta = Math.PI / 6;
>>
>> @Override
>> protected void paintComponent(Graphics g) {
>> super.paintComponent(g);
>> Graphics2D g2 = (Graphics2D) g;
>> g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
>> RenderingHints.VALUE_ANTIALIAS_ON);
>> g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
>> RenderingHints.VALUE_FRACTIONALMETRICS_ON);
>> g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
>> RenderingHints.VALUE_STROKE_PURE);
>> g2.setPaint(Color.blue);
>> Font font = g2.getFont().deriveFont(18f);
>> g2.setFont(font);
>> FontRenderContext frc = g2.getFontRenderContext();
>> String s = "This text should be rotated";
>> float width = (float) font.getStringBounds(s, frc).getWidth();
>> LineMetrics lm = font.getLineMetrics(s, frc);
>> float height = lm.getAscent() + lm.getDescent();
>> // Scale text into rect.
>> float xScale = rect.width / width;
>> float yScale = rect.height / height;
>> float scale = (xScale > yScale) ? yScale : xScale;
>> // Locate string origin.
>> double x = rect.x;
>> double y = rect.y + (rect.height + scale * height) / 2 - scale
>> * lm.getDescent();
>> AffineTransform at = AffineTransform.getTranslateInstance(x, y);
>> at.scale(scale, scale);
>> AffineTransform rotator = new AffineTransform();
>> rotator.rotate(theta, rect.getCenterX(), rect.getCenterY());
>> GeneralPath rect2 = new GeneralPath(
>> rotator.createTransformedShape(rect));
>> // Draw with no rotation.
>> g2.draw(rect);
>> g2.setPaint(Color.red);
>> g2.setFont(font.deriveFont(at));
>> g2.drawString(s, 0, 0);
>> // Rotate once.
>> g2.setPaint(Color.blue);
>> g2.draw(rect2);
>> rotator.concatenate(at);
>> g2.setFont(font.deriveFont(rotator));
>> g2.setPaint(Color.red);
>> g2.drawString(s, 0, 0);
>> // Rotate again.
>> rotator.setToIdentity();
>> rotator.rotate(2 * theta, rect.getCenterX(), rect.getCenterY());
>> rect2 = new GeneralPath(rotator.createTransformedShape(rect));
>> g2.setPaint(Color.blue);
>> g2.draw(rect2);
>> rotator.concatenate(at);
>> g2.setFont(font.deriveFont(rotator));
>> g2.setPaint(Color.red);
>> g2.drawString(s, 0, 0);
>> // Check scaled string bounds.
>> // this was handled by the fractional metrics rendering hint
>> }
>>
>> public static void main(String[] args) {
>> Test test = new Test();
>> test.setPreferredSize(new Dimension(800, 600));
>> JFrame f = new JFrame();
>> f.getContentPane().add(test);
>> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>> f.pack();
>> f.setVisible(true);
>> }
>> }
>>
>> Regards
>> Philippe M.
>>
>>
>>
>>
> --
> Rgds,Rory O'Donnell
> Quality Engineering Manager
> Oracle EMEA , Dublin, Ireland
>
>
--
Cordialement.
Philippe Mouawad.
Re: Fwd: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of
derived Fonts ?
Posted by Rory O'Donnell <ro...@oracle.com>.
Hi Philippe,
Can you log a Java Incident and send us the JI number ?
Rgds,Rory
On 19/11/2014 14:36, Philippe Mouawad wrote:
> Hello Rory,
> For information, I submitted this question on Swing-dev , I am not sure it
> is the right list, if so hope you can help.
>
> Regards
> Philippe
> ---------- Forwarded message ----------
> From: Philippe Mouawad <ph...@gmail.com>
> Date: Wed, Nov 19, 2014 at 3:34 PM
> Subject: JAVA8u20 and JAVA8u25 Regression in Graphics2D drawing of derived
> Fonts ?
> To: swing-dev@openjdk.java.net
>
>
> Hello,
> We had recently a report of a bug on Apache JMeter:
>
> - https://issues.apache.org/bugzilla/show_bug.cgi?id=57221
>
> The bug only occurs on Java 8 (u20 and u25).
>
> We use jCharts library.
>
> I narrowed the bug and it seems to come from the way derived fonts are
> drawn:
>
> Library uses:
>
> public static final AffineTransform VERTICAL_ROTATION =
> AffineTransform.getRotateInstance( -Math.PI / 2 );
>
> Then
>
> this.affineTransform= VERTICAL_ROTATION;
> this.font.deriveFont( this.affineTransform )
>
> So I build a stupid and ugly isolated class to show issue, run it on Java 7
> display is fine , run it on Java8 result is strange.
>
> package org.jCharts;
>
> import java.awt.Color;
> import java.awt.Dimension;
> import java.awt.Font;
> import java.awt.Graphics;
> import java.awt.Graphics2D;
> import java.awt.RenderingHints;
> import java.awt.font.FontRenderContext;
> import java.awt.font.LineMetrics;
> import java.awt.geom.AffineTransform;
> import java.awt.geom.GeneralPath;
> import java.awt.geom.Rectangle2D;
>
> import javax.swing.JFrame;
> import javax.swing.JPanel;
>
> public class Test extends JPanel {
> Rectangle2D.Float rect = new Rectangle2D.Float(200, 200, 220, 35);
> // float theta = 1.1748778437843f;
> double theta = Math.PI / 6;
>
> @Override
> protected void paintComponent(Graphics g) {
> super.paintComponent(g);
> Graphics2D g2 = (Graphics2D) g;
> g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
> RenderingHints.VALUE_ANTIALIAS_ON);
> g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
> RenderingHints.VALUE_FRACTIONALMETRICS_ON);
> g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
> RenderingHints.VALUE_STROKE_PURE);
> g2.setPaint(Color.blue);
> Font font = g2.getFont().deriveFont(18f);
> g2.setFont(font);
> FontRenderContext frc = g2.getFontRenderContext();
> String s = "This text should be rotated";
> float width = (float) font.getStringBounds(s, frc).getWidth();
> LineMetrics lm = font.getLineMetrics(s, frc);
> float height = lm.getAscent() + lm.getDescent();
> // Scale text into rect.
> float xScale = rect.width / width;
> float yScale = rect.height / height;
> float scale = (xScale > yScale) ? yScale : xScale;
> // Locate string origin.
> double x = rect.x;
> double y = rect.y + (rect.height + scale * height) / 2 - scale
> * lm.getDescent();
> AffineTransform at = AffineTransform.getTranslateInstance(x, y);
> at.scale(scale, scale);
> AffineTransform rotator = new AffineTransform();
> rotator.rotate(theta, rect.getCenterX(), rect.getCenterY());
> GeneralPath rect2 = new GeneralPath(
> rotator.createTransformedShape(rect));
> // Draw with no rotation.
> g2.draw(rect);
> g2.setPaint(Color.red);
> g2.setFont(font.deriveFont(at));
> g2.drawString(s, 0, 0);
> // Rotate once.
> g2.setPaint(Color.blue);
> g2.draw(rect2);
> rotator.concatenate(at);
> g2.setFont(font.deriveFont(rotator));
> g2.setPaint(Color.red);
> g2.drawString(s, 0, 0);
> // Rotate again.
> rotator.setToIdentity();
> rotator.rotate(2 * theta, rect.getCenterX(), rect.getCenterY());
> rect2 = new GeneralPath(rotator.createTransformedShape(rect));
> g2.setPaint(Color.blue);
> g2.draw(rect2);
> rotator.concatenate(at);
> g2.setFont(font.deriveFont(rotator));
> g2.setPaint(Color.red);
> g2.drawString(s, 0, 0);
> // Check scaled string bounds.
> // this was handled by the fractional metrics rendering hint
> }
>
> public static void main(String[] args) {
> Test test = new Test();
> test.setPreferredSize(new Dimension(800, 600));
> JFrame f = new JFrame();
> f.getContentPane().add(test);
> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> f.pack();
> f.setVisible(true);
> }
> }
>
> Regards
> Philippe M.
>
>
>
--
Rgds,Rory O'Donnell
Quality Engineering Manager
Oracle EMEA , Dublin, Ireland