Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 536588

Summary: [Cocoa]GC.copyArea() doesn't work for StyledText
Product: [Eclipse Project] Platform Reporter: Lakshmi P Shanmugam <lshanmug>
Component: SWTAssignee: Lakshmi P Shanmugam <lshanmug>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, loskutov, lshanmug, mistria, niraj.modi, sravankumarl, twolf
Version: 4.8Flags: sravankumarl: review+
niraj.modi: review+
Target Milestone: 4.9 RC2   
Hardware: PC   
OS: Mac OS X   
See Also: https://git.eclipse.org/r/128530
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=36bd428f1c9a3c2dfa7b0d8eab63495b292687e1
https://git.eclipse.org/r/128630
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=439ef5aad0500b5642b2b29398277de1e0fa3a3b
Whiteboard:
Bug Depends on:    
Bug Blocks: 536234    

Description Lakshmi P Shanmugam CLA 2018-07-02 09:03:46 EDT
GC.copyArea() is currently broken for StyledText.

Modified Snippet 95 to use StyledText:

public class Snippet95 {

public static void main(String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setText("Widget");

	StyledText text = new StyledText(shell, SWT.MULTI);
	text.setText("hello");
	text.setBounds(10, 10, 50, 50);

	Button button = new Button(shell, SWT.PUSH);
	button.setText("Capture");
	button.pack();
	button.setLocation(10, 140);
	button.addListener(SWT.Selection, event -> {
		Point textSize = text.getSize();
		GC gc = new GC(text);
		final Image image =
			new Image(display, textSize.x, textSize.y);
		gc.copyArea(image, 0, 0);
		gc.dispose();

		Shell popup = new Shell(shell);
		popup.setText("Image");
		popup.addListener(SWT.Close, e -> image.dispose());

		Canvas canvas = new Canvas(popup, SWT.NONE);
		canvas.setBounds(10, 10, textSize.x+10, textSize.y+10);
		canvas.addPaintListener(e -> e.gc.drawImage(image, 0, 0));
		popup.pack();
		popup.open();
	});
	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) display.sleep();
	}
	display.dispose();
}
}
Comment 1 Andrey Loskutov CLA 2018-07-02 09:28:16 EDT
(In reply to Lakshmi Shanmugam from comment #0)
> GC.copyArea() is currently broken for StyledText.

Regression in 4.9 or was it always the case? Is this Mac only issue?
Comment 2 Thomas Wolf CLA 2018-07-02 14:43:46 EDT
FWIW:

* Fails in 4.8.0RC2 (20180531-0841)
* Works in 4.7.3a (20180405-1200)
Comment 3 Andrey Loskutov CLA 2018-07-02 15:11:20 EDT
Which OS? Mac?
Comment 4 Thomas Wolf CLA 2018-07-02 15:12:48 EDT
(In reply to Andrey Loskutov from comment #3)
> Which OS? Mac?

Of course. OS X 10.12.6, non-HiDPI display.
Comment 5 Lakshmi P Shanmugam CLA 2018-07-03 01:50:10 EDT
Looks like it was broken in 4.8 by the fix for Bug 508129.
Comment 6 Andrey Loskutov CLA 2018-07-03 04:42:15 EDT
(In reply to Lakshmi Shanmugam from comment #0)
> GC.copyArea() is currently broken for StyledText.
> 
> Modified Snippet 95 to use StyledText:

If I run this snippet on GTK3 or GTK2, it shows me black rectangle on the second shell. I guess this is supposed to be not black :-)

So this is broken on GTK2 and GTK3 too. Just tested, on Windows 7 this works.
Comment 7 Lakshmi P Shanmugam CLA 2018-07-03 05:47:59 EDT
(In reply to Andrey Loskutov from comment #6)
> (In reply to Lakshmi Shanmugam from comment #0)
> > GC.copyArea() is currently broken for StyledText.
> > 
> > Modified Snippet 95 to use StyledText:
> 
> If I run this snippet on GTK3 or GTK2, it shows me black rectangle on the
> second shell. I guess this is supposed to be not black :-)
> 
> So this is broken on GTK2 and GTK3 too. Just tested, on Windows 7 this works.

I thought this worked on GTK since the test for Bug 536234 uses this.
Sravan, can you please verify on your GTK machine?
Comment 8 Sravan Kumar Lakkimsetti CLA 2018-07-03 08:38:10 EDT
It works for me on GTK3 with a scale of 1. In Hidpi mode I see a blank image
Comment 9 Andrey Loskutov CLA 2018-07-03 08:50:20 EDT
(In reply to Sravan Kumar Lakkimsetti from comment #8)
> It works for me on GTK3 with a scale of 1. In Hidpi mode I see a blank image

I have no HiDpi monitor, just two monitors and KDE, and test is on the second one, and I see black second shell.

Test_org_eclipse_swt_custom_StyledText is green in same environment.
Comment 10 Andrey Loskutov CLA 2018-07-03 08:51:14 EDT
My GTK versions are:
rpm -q gtk2 gtk3
gtk2-2.24.31-1.el7.x86_64
gtk3-3.22.10-4.el7.x86_64
Comment 11 Lakshmi P Shanmugam CLA 2018-07-31 04:52:07 EDT
Need to find a way to fix this without bringing back Bug 508129. Will investigate post M2.
Comment 12 Eclipse Genie CLA 2018-09-03 05:51:47 EDT
New Gerrit change created: https://git.eclipse.org/r/128530
Comment 14 Eclipse Genie CLA 2018-09-04 07:20:25 EDT
New Gerrit change created: https://git.eclipse.org/r/128630
Comment 16 Lakshmi P Shanmugam CLA 2018-09-04 08:05:53 EDT
This has been fixed for Cocoa. I've opened Bug 538586 to track the bug on GTK.
Comment 17 Lakshmi P Shanmugam CLA 2018-09-07 04:03:06 EDT
Verified in I20180906-0745
Comment 18 Mickael Istria CLA 2018-09-07 08:43:58 EDT
(In reply to Lakshmi Shanmugam from comment #16)
> This has been fixed for Cocoa. I've opened Bug 538586 to track the bug on
> GTK.

Some SWT tests are using it successfully on GTK and Windows. Why do you think there is a bug for GTK? Also, the new bug you've opened says it targets OSX.
Comment 19 Thomas Wolf CLA 2018-09-07 09:19:22 EDT
(In reply to Mickael Istria from comment #18)
> Some SWT tests are using it successfully on GTK and Windows. Why do you
> think there is a bug for GTK? Also, the new bug you've opened says it
> targets OSX.

comment 6, comment 8, comment 9.