Bug 568777 - `GC.drawText(.., transparent = true)` uses wrong font for short texts in 2020-12 M2
Summary: `GC.drawText(.., transparent = true)` uses wrong font for short texts in 2020...
Status: REOPENED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.17   Edit
Hardware: PC Mac OS X
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-12 21:40 EST by Michael Golubev CLA
Modified: 2021-06-20 02:54 EDT (History)
8 users (show)

See Also:


Attachments
Snippet to show the problem (1.95 KB, application/octet-stream)
2020-11-12 21:42 EST, Michael Golubev CLA
no flags Details
Screenshot of the problem (64.96 KB, image/png)
2020-11-12 21:44 EST, Michael Golubev CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Golubev CLA 2020-11-12 21:40:11 EST
Apparently, when the text is short, and `transparent` is set to true, GC.drawText(..) reuses the last used font for the same text. 

Reproduced on Mac with Mojave and Big Sur.

An attached snippet draws "3" using a small font and then "3" and "6" using a bigger font. When transparent flag is true, both "3" looks identical if run against 2020-12 M2 SWT. 

If one makes all digits different or sets transparent flag to false (right column), everything is fine again.

Attached is the snippet and a screenshot.
Comment 1 Michael Golubev CLA 2020-11-12 21:42:01 EST
Created attachment 284753 [details]
Snippet to show the problem
Comment 2 Michael Golubev CLA 2020-11-12 21:44:04 EST
Created attachment 284754 [details]
Screenshot of the problem

The left column draws two identical "3"s, which is wrong
Comment 3 Michael Golubev CLA 2020-11-12 21:47:37 EST
The legacy draw2d uses transparent=true for all drawText's in SWTGraphics, so with the described problem, all single-digit labels on my diagrams look the same.
Comment 4 Justin Dolezy CLA 2020-11-13 04:36:20 EST
This is a showstopper for us, it's blocking us from releasing a Big Sur compatible build of our product, unfortunately.

As Michael mentions it's not limited to Big Sur though, I've tested on Catalina & High Sierra which are also affected, so probably occurs on all supported macOS builds.
Comment 5 Sravan Kumar Lakkimsetti CLA 2020-11-13 07:51:02 EST
This behaviour is introduced by Bug 366471. Specifically https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/92329

@Lakshmi Can we revert this?
Comment 6 Eclipse Genie CLA 2020-11-13 08:02:50 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/172205
Comment 7 Sravan Kumar Lakkimsetti CLA 2020-11-13 08:16:27 EST
(In reply to Eclipse Genie from comment #6)
> New Gerrit change created:
> https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/172205

This is a revert of https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/92329

The problem here is the end user is trying to draw a single and same character twice but changing font in between. The cache mechanism implemented in the above commit does not take into account of changing font. So same font is being used to draw second call as well. This will happen every time we use same letter.
Comment 8 Eclipse Genie CLA 2020-11-13 08:25:31 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/172207
Comment 9 Sravan Kumar Lakkimsetti CLA 2020-11-13 08:28:18 EST
(In reply to Eclipse Genie from comment #8)
> New Gerrit change created:
> https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/172207

This patch resets textCache. 

@Lakshmi Can you please let me know which is better. My preference would be https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/172207

Both these patches work. The differentiating factor would be performance.
Comment 10 Lakshmi P Shanmugam CLA 2020-11-13 08:59:21 EST
(In reply to Sravan Kumar Lakkimsetti from comment #9)
> (In reply to Eclipse Genie from comment #8)
> > New Gerrit change created:
> > https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/172207
> 
> This patch resets textCache. 
> 
> @Lakshmi Can you please let me know which is better. My preference would be
> https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/172207
> 
> Both these patches work. The differentiating factor would be performance.

@Sravan, I agree, it's better to reset the cache. Can you please check if there are other cases where a cache reset is required such setForeground() and setForegroundPattern()?
Comment 11 Sravan Kumar Lakkimsetti CLA 2020-11-13 09:39:36 EST
(In reply to Lakshmi P Shanmugam from comment #10)
> (In reply to Sravan Kumar Lakkimsetti from comment #9)
> > (In reply to Eclipse Genie from comment #8)
> > > New Gerrit change created:
> > > https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/172207
> > 
> > This patch resets textCache. 
> > 
> > @Lakshmi Can you please let me know which is better. My preference would be
> > https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/172207
> > 
> > Both these patches work. The differentiating factor would be performance.
> 
> @Sravan, I agree, it's better to reset the cache. Can you please check if
> there are other cases where a cache reset is required such setForeground()
> and setForegroundPattern()?

The cache works only on the text. Basically we need to see what are the parameters affect the object created by GC.createString(). 

Apart from Font I can see foregroundpattern. So we need to do cache reset for setForegroundPattern as well.
Comment 12 Sravan Kumar Lakkimsetti CLA 2020-11-13 09:57:44 EST
(In reply to Sravan Kumar Lakkimsetti from comment #11)
> (In reply to Lakshmi P Shanmugam from comment #10)
> > (In reply to Sravan Kumar Lakkimsetti from comment #9)
> > > (In reply to Eclipse Genie from comment #8)
> > > > New Gerrit change created:
> > > > https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/172207
> > > 
> > > This patch resets textCache. 
> > > 
> > > @Lakshmi Can you please let me know which is better. My preference would be
> > > https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/172207
> > > 
> > > Both these patches work. The differentiating factor would be performance.
> > 
> > @Sravan, I agree, it's better to reset the cache. Can you please check if
> > there are other cases where a cache reset is required such setForeground()
> > and setForegroundPattern()?
> 
> The cache works only on the text. Basically we need to see what are the
> parameters affect the object created by GC.createString(). 
> 
> Apart from Font I can see foregroundpattern. So we need to do cache reset
> for setForegroundPattern as well.

Updated the patch now. Can you please review?
Comment 14 Sravan Kumar Lakkimsetti CLA 2020-11-13 10:36:50 EST
Merged to master
Comment 15 Sravan Kumar Lakkimsetti CLA 2020-11-17 02:35:58 EST
Verified in 
Eclipse SDK
Version: 2020-12 (4.18)
Build id: I20201116-1800
OS: Mac OS X, v.10.16, x86_64 / cocoa
Java version: 15.0.1
Comment 16 Eclipse Genie CLA 2020-12-02 02:13:10 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/173195
Comment 17 Sravan Kumar Lakkimsetti CLA 2020-12-02 02:14:05 EST
(In reply to Eclipse Genie from comment #16)
> New Gerrit change created:
> https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/173195

Reverting as this fix caused a regression bug 569367
Comment 18 Sravan Kumar Lakkimsetti CLA 2020-12-02 03:41:10 EST
During the test I noticed the whitespace character turning to bold briefly. This is resulting in cache reset causing regression

We will take a look again in 4.19
Comment 19 Sravan Kumar Lakkimsetti CLA 2021-02-05 04:11:18 EST
there are no plans currently. Removing the target
Comment 20 Jonah Graham CLA 2021-06-19 09:55:46 EDT
This bug is affecting the TM Terminal - see Bug 574271 and the screenshot https://bugzillaattachments.eclipsecontent.org/bugs/attachment.cgi?id=286612 which shows how some characters are drawn in the wrong color.