<Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

classic Classic list List threaded Threaded
54 messages Options
123
Reply | Threaded
Open this post in threaded view
|

<Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

prasanta sadhukhan
Hi All,

Please review a fix for an issue whereby, when using a non-integer
resolution (e.g. 225%) for a HiDPI display,
the Swing HTML rendering incorrectly calculates the width of SPAN
elements which results in SPANs being
incorrectly positioned and overlapping with each other.

Issue was, when a JLabel with an html text is created, the
GlyphPainter1.getSpan() uses a FontrenderedContext with transform scale 1
and also the obtained width is converted to int and not to float.

Proposed fix is to use correct transform while calculating the string
width and also use floating point API to get floating point width.

webrev:http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.00/
Bug: https://bugs.openjdk.java.net/browse/JDK-8178025

Regards
Prasanta
Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

Semyon Sadetsky
+1

--Semyon


On 10/11/2017 02:43 AM, Prasanta Sadhukhan wrote:

> Hi All,
>
> Please review a fix for an issue whereby, when using a non-integer
> resolution (e.g. 225%) for a HiDPI display,
> the Swing HTML rendering incorrectly calculates the width of SPAN
> elements which results in SPANs being
> incorrectly positioned and overlapping with each other.
>
> Issue was, when a JLabel with an html text is created, the
> GlyphPainter1.getSpan() uses a FontrenderedContext with transform scale 1
> and also the obtained width is converted to int and not to float.
>
> Proposed fix is to use correct transform while calculating the string
> width and also use floating point API to get floating point width.
>
> webrev:http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.00/
> Bug: https://bugs.openjdk.java.net/browse/JDK-8178025
>
> Regards
> Prasanta

Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

Sergey Bylokhov
In reply to this post by prasanta sadhukhan
Hi, Prasanta.

On 11/10/2017 02:43, Prasanta Sadhukhan wrote:
> Issue was, when a JLabel with an html text is created, the
> GlyphPainter1.getSpan() uses a FontrenderedContext with transform scale 1
> and also the obtained width is converted to int and not to float.

Probably this is a root cause of the bug? FontrenderedContext is an
abstraction which encapsulate information about text attributes for some
specific surface such as screen, window, etc. If the label or any other
components will use some FRC for rendering then the same FRC should be
used for font size measurement. So why the scale is 1?

> Proposed fix is to use correct transform while calculating the string
> width and also use floating point API to get floating point width.

It will apply the screens scale to the FRC even if the component is
located on some other screen.


--
Best regards, Sergey.
Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

Alan Snyder-3
Having run into similar problems, I believe this is an area where Swing has a serious design flaw. When a component is created, it has no idea which window it will be displayed in, and even when the window is known, the window could be moved to a different screen at any time. In addition, it seems the antialiasing and fractional metrics options are sometimes obtained from the Look and Feel, the rationale for which puzzles me. If these are not actual problems, please point me to appropriate documentation or supply an explanation.

  Alan






> On Oct 13, 2017, at 6:10 PM, Sergey Bylokhov <[hidden email]> wrote:
>
> Hi, Prasanta.
>
> On 11/10/2017 02:43, Prasanta Sadhukhan wrote:
>> Issue was, when a JLabel with an html text is created, the GlyphPainter1.getSpan() uses a FontrenderedContext with transform scale 1
>> and also the obtained width is converted to int and not to float.
>
> Probably this is a root cause of the bug? FontrenderedContext is an abstraction which encapsulate information about text attributes for some specific surface such as screen, window, etc. If the label or any other components will use some FRC for rendering then the same FRC should be used for font size measurement. So why the scale is 1?
>
>> Proposed fix is to use correct transform while calculating the string width and also use floating point API to get floating point width.
>
> It will apply the screens scale to the FRC even if the component is located on some other screen.
>
>
> --
> Best regards, Sergey.

Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

prasanta sadhukhan
In reply to this post by Sergey Bylokhov

Hi Sergey,


On 10/14/2017 6:40 AM, Sergey Bylokhov wrote:
Hi, Prasanta.

On 11/10/2017 02:43, Prasanta Sadhukhan wrote:
Issue was, when a JLabel with an html text is created, the GlyphPainter1.getSpan() uses a FontrenderedContext with transform scale 1
and also the obtained width is converted to int and not to float.

Probably this is a root cause of the bug?
Does not seem like. If we only use floating point API getTabbedTextWidth() in GlyphPainter1.getSpan() to get floating point width, it calls SwingUtilities2.getFontStringWidth() which calls getStringBounds() with default FRC.
When getStringBounds() calls fm.getFontRenderContext(), it returns DEFAULT_FRC which has a null AffineTransform so when we try to get the transform for that through getTransform(), it creates a new AffineTransform with scale 1
public AffineTransform getTransform() {
        return (tx == null) ? new AffineTransform() : new AffineTransform(tx);
    }
FontrenderedContext is an abstraction which encapsulate information about text attributes for some specific surface such as screen, window, etc. If the label or any other components will use some FRC for rendering then the same FRC should be used for font size measurement. So why the scale is 1?

Proposed fix is to use correct transform while calculating the string width and also use floating point API to get floating point width.

It will apply the screens scale to the FRC even if the component is located on some other screen.
I was of the opinion that this
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform().getScaleX()

will give the scale factor as passed to sun.java2d.uiScale which should be applicable for all screen(s), which is what I leveraged in my fix.


Regards
Prasanta
Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

Sergey Bylokhov
On 16/10/2017 02:50, Prasanta Sadhukhan wrote:

>> Probably this is a root cause of the bug?
> Does not seem like. If we only use floating point API
> getTabbedTextWidth() in GlyphPainter1.getSpan() to get floating point
> width, it calls SwingUtilities2.getFontStringWidth() which calls
> getStringBounds() with default FRC.
> When getStringBounds() calls fm.getFontRenderContext(), it returns
> DEFAULT_FRC which has a null AffineTransform so when we try to get the
> transform for that through getTransform(), it creates a new
> AffineTransform with scale 1
> public AffineTransform getTransform() {
>          return (tx == null) ? new AffineTransform() : new
> AffineTransform(tx);
>      }

So this is a problem why default FRC is used. We should find a way to
create a correct one instead.

>> It will apply the screens scale to the FRC even if the component is
>> located on some other screen.
> I was of the opinion that this
>
> GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform().getScaleX()
>
>
> will give the scale factor as passed to sun.java2d.uiScale which should
> be applicable for all screen(s), which is what I leveraged in my fix.

The "sun.java2d.uiScale" is a debug option which applies the scale on
all screens, but in case of the common configuration it is possible to
have different scales(example: hidpi laptop + lowdpi external screen).

GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform().getScaleX()

Will returns default transform for default configuration of the
main/default screen.

--
Best regards, Sergey.
Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

prasanta sadhukhan


On 10/17/2017 1:08 AM, Sergey Bylokhov wrote:

> On 16/10/2017 02:50, Prasanta Sadhukhan wrote:
>>> Probably this is a root cause of the bug?
>> Does not seem like. If we only use floating point API
>> getTabbedTextWidth() in GlyphPainter1.getSpan() to get floating point
>> width, it calls SwingUtilities2.getFontStringWidth() which calls
>> getStringBounds() with default FRC.
>> When getStringBounds() calls fm.getFontRenderContext(), it returns
>> DEFAULT_FRC which has a null AffineTransform so when we try to get
>> the transform for that through getTransform(), it creates a new
>> AffineTransform with scale 1
>> public AffineTransform getTransform() {
>>          return (tx == null) ? new AffineTransform() : new
>> AffineTransform(tx);
>>      }
>
> So this is a problem why default FRC is used. We should find a way to
> create a correct one instead.
I guess that is what I did which is to create a FRC with correct transform .

Regards
Prasanta

>
>>> It will apply the screens scale to the FRC even if the component is
>>> located on some other screen.
>> I was of the opinion that this
>>
>> GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform().getScaleX()
>>
>>
>> will give the scale factor as passed to sun.java2d.uiScale which
>> should be applicable for all screen(s), which is what I leveraged in
>> my fix.
>
> The "sun.java2d.uiScale" is a debug option which applies the scale on
> all screens, but in case of the common configuration it is possible to
> have different scales(example: hidpi laptop + lowdpi external screen).
>
> GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform().getScaleX()
>
> Will returns default transform for default configuration of the
> main/default screen.
>

Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

prasanta sadhukhan


On 10/17/2017 10:22 AM, Prasanta Sadhukhan wrote:

>
>
> On 10/17/2017 1:08 AM, Sergey Bylokhov wrote:
>> On 16/10/2017 02:50, Prasanta Sadhukhan wrote:
>>>> Probably this is a root cause of the bug?
>>> Does not seem like. If we only use floating point API
>>> getTabbedTextWidth() in GlyphPainter1.getSpan() to get floating
>>> point width, it calls SwingUtilities2.getFontStringWidth() which
>>> calls getStringBounds() with default FRC.
>>> When getStringBounds() calls fm.getFontRenderContext(), it returns
>>> DEFAULT_FRC which has a null AffineTransform so when we try to get
>>> the transform for that through getTransform(), it creates a new
>>> AffineTransform with scale 1
>>> public AffineTransform getTransform() {
>>>          return (tx == null) ? new AffineTransform() : new
>>> AffineTransform(tx);
>>>      }
>>
>> So this is a problem why default FRC is used. We should find a way to
>> create a correct one instead.
> I guess that is what I did which is to create a FRC with correct
> transform .
>
When JLabel with html tag span is created, GlyphPainter1.getSpan() calls
sync() which finds JLabel.getFontMetrics() which calls
SwingUtilities2.getFontMetrics which calls getFRCProperty() and it tries
to find
JLabel.getGraphicsConfiguration() which comes out to be null so
affinetransform also becomes null.
AffineTransform tx = (gc == null) ? null : gc.getDefaultTransform();

It seems for JLabel, Component.updateGraphicsData() with proper
GraphicsConfiguraiton is never called which it does for JTextComponent
or JDialog. Do you know why? Because of this, correct FRC is not created.
I am not sure what else I can do to create correct FRC.

> Regards
> Prasanta
>>
>>>> It will apply the screens scale to the FRC even if the component is
>>>> located on some other screen.
>>> I was of the opinion that this
>>>
>>> GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform().getScaleX()
>>>
>>>
>>> will give the scale factor as passed to sun.java2d.uiScale which
>>> should be applicable for all screen(s), which is what I leveraged in
>>> my fix.
>>
>> The "sun.java2d.uiScale" is a debug option which applies the scale on
>> all screens, but in case of the common configuration it is possible
>> to have different scales(example: hidpi laptop + lowdpi external
>> screen).
>>
>> GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform().getScaleX()
>>
>> Will returns default transform for default configuration of the
>> main/default screen.
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

Semyon Sadetsky
Hi Prasanta,

Hi Prasanta,

It seems another global issue was missed during this bug evaluation.
After HiDPI support is introduced all text UIs need to receive
notifications about graphics configuration update as about font change.
This is because another GC scale changes font size but since symbols and
spaces are not scaled linearly the text layout should be fully refreshed
with the new GC.

--Semyon


On 10/17/2017 03:48 AM, Prasanta Sadhukhan wrote:

>
>
> On 10/17/2017 10:22 AM, Prasanta Sadhukhan wrote:
>>
>>
>> On 10/17/2017 1:08 AM, Sergey Bylokhov wrote:
>>> On 16/10/2017 02:50, Prasanta Sadhukhan wrote:
>>>>> Probably this is a root cause of the bug?
>>>> Does not seem like. If we only use floating point API
>>>> getTabbedTextWidth() in GlyphPainter1.getSpan() to get floating
>>>> point width, it calls SwingUtilities2.getFontStringWidth() which
>>>> calls getStringBounds() with default FRC.
>>>> When getStringBounds() calls fm.getFontRenderContext(), it returns
>>>> DEFAULT_FRC which has a null AffineTransform so when we try to get
>>>> the transform for that through getTransform(), it creates a new
>>>> AffineTransform with scale 1
>>>> public AffineTransform getTransform() {
>>>>          return (tx == null) ? new AffineTransform() : new
>>>> AffineTransform(tx);
>>>>      }
>>>
>>> So this is a problem why default FRC is used. We should find a way
>>> to create a correct one instead.
>> I guess that is what I did which is to create a FRC with correct
>> transform .
>>
> When JLabel with html tag span is created, GlyphPainter1.getSpan()
> calls sync() which finds JLabel.getFontMetrics() which calls
> SwingUtilities2.getFontMetrics which calls getFRCProperty() and it
> tries to find
> JLabel.getGraphicsConfiguration() which comes out to be null so
> affinetransform also becomes null.
> AffineTransform tx = (gc == null) ? null : gc.getDefaultTransform();
>
> It seems for JLabel, Component.updateGraphicsData() with proper
> GraphicsConfiguraiton is never called which it does for JTextComponent
> or JDialog. Do you know why? Because of this, correct FRC is not created.
> I am not sure what else I can do to create correct FRC.
>> Regards
>> Prasanta
>>>
>>>>> It will apply the screens scale to the FRC even if the component
>>>>> is located on some other screen.
>>>> I was of the opinion that this
>>>>
>>>> GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform().getScaleX()
>>>>
>>>>
>>>> will give the scale factor as passed to sun.java2d.uiScale which
>>>> should be applicable for all screen(s), which is what I leveraged
>>>> in my fix.
>>>
>>> The "sun.java2d.uiScale" is a debug option which applies the scale
>>> on all screens, but in case of the common configuration it is
>>> possible to have different scales(example: hidpi laptop + lowdpi
>>> external screen).
>>>
>>> GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform().getScaleX()
>>>
>>> Will returns default transform for default configuration of the
>>> main/default screen.
>>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

Sergey Bylokhov
In reply to this post by prasanta sadhukhan
On 17/10/2017 03:48, Prasanta Sadhukhan wrote:
> It seems for JLabel, Component.updateGraphicsData() with proper
> GraphicsConfiguraiton is never called which it does for JTextComponent
> or JDialog. Do you know why? Because of this, correct FRC is not created.
> I am not sure what else I can do to create correct FRC.

But at some point we will get a correct GraphicsConfiguraiton for a
component, right? It should be called for the window and child when we
show the window on the screen, when we move the window to another
screen, etc.


--
Best regards, Sergey.
Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

prasanta sadhukhan


On 10/19/2017 3:49 AM, Sergey Bylokhov wrote:

> On 17/10/2017 03:48, Prasanta Sadhukhan wrote:
>> It seems for JLabel, Component.updateGraphicsData() with proper
>> GraphicsConfiguraiton is never called which it does for
>> JTextComponent or JDialog. Do you know why? Because of this, correct
>> FRC is not created.
>> I am not sure what else I can do to create correct FRC.
>
> But at some point we will get a correct GraphicsConfiguraiton for a
> component, right? It should be called for the window and child when we
> show the window on the screen, when we move the window to another
> screen, etc.
>
>
Yes, it seems to be called when JLabel is added to JFrame but not before.
Span is calculated in GlyphPainter1.getSpan() which is called when
JLabel is created and
as it seems, not when JLabel is added to JFrame (which is when we get
the correct graphics configuration and therefore correct transform).

So, we need to make sure spans are recalculated when the JLabel is added
to frame, which is what modified webrev does by calling JLabel.updateUI()
http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.01/

Regards
Prasana

Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

Alan Snyder-3
Do you mean JLabel.updateGraphicsData()?

Also, this issue could affect applications as well, if they are computing data based on layout information such as the default preferred size.

What is the recommended method for an application to respond to a change in the graphics configuration?

From looking at the code, it appears that addNotify() would be the right place, but I would never guess that just from the documentation.

  Alan



> On Oct 19, 2017, at 3:12 AM, Prasanta Sadhukhan <[hidden email]> wrote:
>
>
>
> On 10/19/2017 3:49 AM, Sergey Bylokhov wrote:
>> On 17/10/2017 03:48, Prasanta Sadhukhan wrote:
>>> It seems for JLabel, Component.updateGraphicsData() with proper GraphicsConfiguraiton is never called which it does for JTextComponent or JDialog. Do you know why? Because of this, correct FRC is not created.
>>> I am not sure what else I can do to create correct FRC.
>>
>> But at some point we will get a correct GraphicsConfiguraiton for a component, right? It should be called for the window and child when we show the window on the screen, when we move the window to another screen, etc.
>>
>>
> Yes, it seems to be called when JLabel is added to JFrame but not before.
> Span is calculated in GlyphPainter1.getSpan() which is called when JLabel is created and
> as it seems, not when JLabel is added to JFrame (which is when we get the correct graphics configuration and therefore correct transform).
>
> So, we need to make sure spans are recalculated when the JLabel is added to frame, which is what modified webrev does by calling JLabel.updateUI()
> http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.01/
>
> Regards
> Prasana
>

Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

prasanta sadhukhan
updateGraphicsData() is called implicitly when component is added to frame.
We need to call JLabel.updateUI() for this, as it will trigger calling
BasicHTML.updateRenderer() which will go on to recalculate spans.
Ideally, I would guess, we should wait for propertyChange() in
BasicLabelUI to be called when graphics configuration is updated
but I only see it being called with "ancestor" property name, I am not
sure if that is property that would be used to notify if gc is updated
or not.

Regards
Prasanta
On 10/19/2017 7:54 PM, Alan Snyder wrote:

> Do you mean JLabel.updateGraphicsData()?
>
> Also, this issue could affect applications as well, if they are computing data based on layout information such as the default preferred size.
>
> What is the recommended method for an application to respond to a change in the graphics configuration?
>
>  From looking at the code, it appears that addNotify() would be the right place, but I would never guess that just from the documentation.
>
>    Alan
>
>
>
>> On Oct 19, 2017, at 3:12 AM, Prasanta Sadhukhan <[hidden email]> wrote:
>>
>>
>>
>> On 10/19/2017 3:49 AM, Sergey Bylokhov wrote:
>>> On 17/10/2017 03:48, Prasanta Sadhukhan wrote:
>>>> It seems for JLabel, Component.updateGraphicsData() with proper GraphicsConfiguraiton is never called which it does for JTextComponent or JDialog. Do you know why? Because of this, correct FRC is not created.
>>>> I am not sure what else I can do to create correct FRC.
>>> But at some point we will get a correct GraphicsConfiguraiton for a component, right? It should be called for the window and child when we show the window on the screen, when we move the window to another screen, etc.
>>>
>>>
>> Yes, it seems to be called when JLabel is added to JFrame but not before.
>> Span is calculated in GlyphPainter1.getSpan() which is called when JLabel is created and
>> as it seems, not when JLabel is added to JFrame (which is when we get the correct graphics configuration and therefore correct transform).
>>
>> So, we need to make sure spans are recalculated when the JLabel is added to frame, which is what modified webrev does by calling JLabel.updateUI()
>> http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.01/
>>
>> Regards
>> Prasana
>>

Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

Alan Snyder-3
updateGraphicsData() is also called when the graphics configuration changes, which is what you want.

Without that, you are stuck with the default graphics configuration, which is all that is available until the window is displayed.

updateUI() seems like the wrong place to trigger the layout related recalculation, as layout calculation is only one of things that updateUI() does.

  Alan



> On Oct 19, 2017, at 10:21 PM, Prasanta Sadhukhan <[hidden email]> wrote:
>
> updateGraphicsData() is called implicitly when component is added to frame.
> We need to call JLabel.updateUI() for this, as it will trigger calling BasicHTML.updateRenderer() which will go on to recalculate spans.
> Ideally, I would guess, we should wait for propertyChange() in BasicLabelUI to be called when graphics configuration is updated
> but I only see it being called with "ancestor" property name, I am not sure if that is property that would be used to notify if gc is updated or not.
>
> Regards
> Prasanta
> On 10/19/2017 7:54 PM, Alan Snyder wrote:
>> Do you mean JLabel.updateGraphicsData()?
>>
>> Also, this issue could affect applications as well, if they are computing data based on layout information such as the default preferred size.
>>
>> What is the recommended method for an application to respond to a change in the graphics configuration?
>>
>> From looking at the code, it appears that addNotify() would be the right place, but I would never guess that just from the documentation.
>>
>>   Alan
>>
>>
>>
>>> On Oct 19, 2017, at 3:12 AM, Prasanta Sadhukhan <[hidden email]> wrote:
>>>
>>>
>>>
>>> On 10/19/2017 3:49 AM, Sergey Bylokhov wrote:
>>>> On 17/10/2017 03:48, Prasanta Sadhukhan wrote:
>>>>> It seems for JLabel, Component.updateGraphicsData() with proper GraphicsConfiguraiton is never called which it does for JTextComponent or JDialog. Do you know why? Because of this, correct FRC is not created.
>>>>> I am not sure what else I can do to create correct FRC.
>>>> But at some point we will get a correct GraphicsConfiguraiton for a component, right? It should be called for the window and child when we show the window on the screen, when we move the window to another screen, etc.
>>>>
>>>>
>>> Yes, it seems to be called when JLabel is added to JFrame but not before.
>>> Span is calculated in GlyphPainter1.getSpan() which is called when JLabel is created and
>>> as it seems, not when JLabel is added to JFrame (which is when we get the correct graphics configuration and therefore correct transform).
>>>
>>> So, we need to make sure spans are recalculated when the JLabel is added to frame, which is what modified webrev does by calling JLabel.updateUI()
>>> http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.01/
>>>
>>> Regards
>>> Prasana
>>>
>

Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

prasanta sadhukhan
I do not see how updateGraphicsData() woud trigger layout/span
calculation. Moreover, it has package-protected access to be called for
JLabel.

Regards
Prasanta
On 10/20/2017 8:09 PM, Alan Snyder wrote:

> updateGraphicsData() is also called when the graphics configuration changes, which is what you want.
>
> Without that, you are stuck with the default graphics configuration, which is all that is available until the window is displayed.
>
> updateUI() seems like the wrong place to trigger the layout related recalculation, as layout calculation is only one of things that updateUI() does.
>
>    Alan
>
>
>
>> On Oct 19, 2017, at 10:21 PM, Prasanta Sadhukhan <[hidden email]> wrote:
>>
>> updateGraphicsData() is called implicitly when component is added to frame.
>> We need to call JLabel.updateUI() for this, as it will trigger calling BasicHTML.updateRenderer() which will go on to recalculate spans.
>> Ideally, I would guess, we should wait for propertyChange() in BasicLabelUI to be called when graphics configuration is updated
>> but I only see it being called with "ancestor" property name, I am not sure if that is property that would be used to notify if gc is updated or not.
>>
>> Regards
>> Prasanta
>> On 10/19/2017 7:54 PM, Alan Snyder wrote:
>>> Do you mean JLabel.updateGraphicsData()?
>>>
>>> Also, this issue could affect applications as well, if they are computing data based on layout information such as the default preferred size.
>>>
>>> What is the recommended method for an application to respond to a change in the graphics configuration?
>>>
>>>  From looking at the code, it appears that addNotify() would be the right place, but I would never guess that just from the documentation.
>>>
>>>    Alan
>>>
>>>
>>>
>>>> On Oct 19, 2017, at 3:12 AM, Prasanta Sadhukhan <[hidden email]> wrote:
>>>>
>>>>
>>>>
>>>> On 10/19/2017 3:49 AM, Sergey Bylokhov wrote:
>>>>> On 17/10/2017 03:48, Prasanta Sadhukhan wrote:
>>>>>> It seems for JLabel, Component.updateGraphicsData() with proper GraphicsConfiguraiton is never called which it does for JTextComponent or JDialog. Do you know why? Because of this, correct FRC is not created.
>>>>>> I am not sure what else I can do to create correct FRC.
>>>>> But at some point we will get a correct GraphicsConfiguraiton for a component, right? It should be called for the window and child when we show the window on the screen, when we move the window to another screen, etc.
>>>>>
>>>>>
>>>> Yes, it seems to be called when JLabel is added to JFrame but not before.
>>>> Span is calculated in GlyphPainter1.getSpan() which is called when JLabel is created and
>>>> as it seems, not when JLabel is added to JFrame (which is when we get the correct graphics configuration and therefore correct transform).
>>>>
>>>> So, we need to make sure spans are recalculated when the JLabel is added to frame, which is what modified webrev does by calling JLabel.updateUI()
>>>> http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.01/
>>>>
>>>> Regards
>>>> Prasana
>>>>

Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

Alan Snyder-3
Code would have to be changed to make it do that. I’m suggesting that is the right hook, but it is up to you to use it.

Presumably as Swing is part of the JDK, access can be arranged...


> On Oct 20, 2017, at 10:01 AM, Prasanta Sadhukhan <[hidden email]> wrote:
>
> I do not see how updateGraphicsData() woud trigger layout/span calculation. Moreover, it has package-protected access to be called for JLabel.
>
> Regards
> Prasanta

Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

prasanta sadhukhan
In reply to this post by prasanta sadhukhan


On 10/19/2017 3:42 PM, Prasanta Sadhukhan wrote:

>
>
> On 10/19/2017 3:49 AM, Sergey Bylokhov wrote:
>> On 17/10/2017 03:48, Prasanta Sadhukhan wrote:
>>> It seems for JLabel, Component.updateGraphicsData() with proper
>>> GraphicsConfiguraiton is never called which it does for
>>> JTextComponent or JDialog. Do you know why? Because of this, correct
>>> FRC is not created.
>>> I am not sure what else I can do to create correct FRC.
>>
>> But at some point we will get a correct GraphicsConfiguraiton for a
>> component, right? It should be called for the window and child when
>> we show the window on the screen, when we move the window to another
>> screen, etc.
>>
>>
> Yes, it seems to be called when JLabel is added to JFrame but not before.
> Span is calculated in GlyphPainter1.getSpan() which is called when
> JLabel is created and
> as it seems, not when JLabel is added to JFrame (which is when we get
> the correct graphics configuration and therefore correct transform).
>
> So, we need to make sure spans are recalculated when the JLabel is
> added to frame, which is what modified webrev does by calling
> JLabel.updateUI()
> http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.01/
>
Modified webrev to only update html renderer when JLabel is added to
frame by listening to property "ancestor" which implies component is
added/made visible, at which point correct graphics configuration is set.
http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.02/

Regards
Prasanta
> Regards
> Prasana
>

Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

Alan Snyder-3
Does it handle the case where the graphics configuration is later changed?

  Alan


On Oct 22, 2017, at 11:23 PM, Prasanta Sadhukhan <[hidden email]> wrote:



On 10/19/2017 3:42 PM, Prasanta Sadhukhan wrote:


On 10/19/2017 3:49 AM, Sergey Bylokhov wrote:
On 17/10/2017 03:48, Prasanta Sadhukhan wrote:
It seems for JLabel, Component.updateGraphicsData() with proper GraphicsConfiguraiton is never called which it does for JTextComponent or JDialog. Do you know why? Because of this, correct FRC is not created.
I am not sure what else I can do to create correct FRC.

But at some point we will get a correct GraphicsConfiguraiton for a component, right? It should be called for the window and child when we show the window on the screen, when we move the window to another screen, etc.


Yes, it seems to be called when JLabel is added to JFrame but not before.
Span is calculated in GlyphPainter1.getSpan() which is called when JLabel is created and
as it seems, not when JLabel is added to JFrame (which is when we get the correct graphics configuration and therefore correct transform).

So, we need to make sure spans are recalculated when the JLabel is added to frame, which is what modified webrev does by calling JLabel.updateUI()
http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.01/

Modified webrev to only update html renderer when JLabel is added to frame by listening to property "ancestor" which implies component is added/made visible, at which point correct graphics configuration is set.
http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.02/

Regards
Prasanta
Regards
Prasana

Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

prasanta sadhukhan
In reply to this post by prasanta sadhukhan

I would guess so as "ancestor" listener is to support notification when changes occur to a JComponent or one of its ancestors.

Regards
Prasanta
On 10/23/2017 7:45 PM, Alan Snyder wrote:
Does it handle the case where the graphics configuration is later changed?

  Alan


On Oct 22, 2017, at 11:23 PM, Prasanta Sadhukhan <[hidden email]> wrote:



On 10/19/2017 3:42 PM, Prasanta Sadhukhan wrote:


On 10/19/2017 3:49 AM, Sergey Bylokhov wrote:
On 17/10/2017 03:48, Prasanta Sadhukhan wrote:
It seems for JLabel, Component.updateGraphicsData() with proper GraphicsConfiguraiton is never called which it does for JTextComponent or JDialog. Do you know why? Because of this, correct FRC is not created.
I am not sure what else I can do to create correct FRC.

But at some point we will get a correct GraphicsConfiguraiton for a component, right? It should be called for the window and child when we show the window on the screen, when we move the window to another screen, etc.


Yes, it seems to be called when JLabel is added to JFrame but not before.
Span is calculated in GlyphPainter1.getSpan() which is called when JLabel is created and
as it seems, not when JLabel is added to JFrame (which is when we get the correct graphics configuration and therefore correct transform).

So, we need to make sure spans are recalculated when the JLabel is added to frame, which is what modified webrev does by calling JLabel.updateUI()
http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.01/

Modified webrev to only update html renderer when JLabel is added to frame by listening to property "ancestor" which implies component is added/made visible, at which point correct graphics configuration is set.
http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.02/

Regards
Prasanta
Regards
Prasana


Reply | Threaded
Open this post in threaded view
|

Re: <Swing Dev> [10] RFR JDK-8178025:HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other

Alan Snyder-3
You’re guessing? Really?

On Oct 23, 2017, at 10:19 PM, Prasanta Sadhukhan <[hidden email]> wrote:

I would guess so as "ancestor" listener is to support notification when changes occur to a JComponent or one of its ancestors.

Regards
Prasanta
On 10/23/2017 7:45 PM, Alan Snyder wrote:
Does it handle the case where the graphics configuration is later changed?

  Alan


On Oct 22, 2017, at 11:23 PM, Prasanta Sadhukhan <[hidden email]> wrote:



On 10/19/2017 3:42 PM, Prasanta Sadhukhan wrote:


On 10/19/2017 3:49 AM, Sergey Bylokhov wrote:
On 17/10/2017 03:48, Prasanta Sadhukhan wrote:
It seems for JLabel, Component.updateGraphicsData() with proper GraphicsConfiguraiton is never called which it does for JTextComponent or JDialog. Do you know why? Because of this, correct FRC is not created.
I am not sure what else I can do to create correct FRC.

But at some point we will get a correct GraphicsConfiguraiton for a component, right? It should be called for the window and child when we show the window on the screen, when we move the window to another screen, etc.


Yes, it seems to be called when JLabel is added to JFrame but not before.
Span is calculated in GlyphPainter1.getSpan() which is called when JLabel is created and
as it seems, not when JLabel is added to JFrame (which is when we get the correct graphics configuration and therefore correct transform).

So, we need to make sure spans are recalculated when the JLabel is added to frame, which is what modified webrev does by calling JLabel.updateUI()
http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.01/

Modified webrev to only update html renderer when JLabel is added to frame by listening to property "ancestor" which implies component is added/made visible, at which point correct graphics configuration is set.
http://cr.openjdk.java.net/~psadhukhan/8178025/webrev.02/

Regards
Prasanta
Regards
Prasana



123