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

Bug 152555

Summary: Setting alpha transparency makes font style change unexpectedly.
Product: [Tools] GEF Reporter: Pavel Repkin <pavel.repkin>
Component: GEF-Legacy Draw2dAssignee: gef-inbox <gef-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: howfunny, nyssen
Version: 3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Piece of code that makes the bug appear none

Description Pavel Repkin CLA 2006-08-02 02:52:30 EDT
The following sample code illustrates the problem we experience in our product while working with half transparent Figures.
The problem is that a text is written in a bold style, though the current font style is plain.


import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.draw2d.*;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.draw2d.geometry.Point;
public class Main {
    public static void main(String args[]) {
        Shell shell = new Shell();
        shell.setSize(400, 400);
        shell.setLayout(new FillLayout());
        
        FigureCanvas canvas = new FigureCanvas(shell);
        canvas.setBackground(ColorConstants.white);
        canvas.setContents(new Figure() {
            public void paint(Graphics g) {
//Draw some text in bold
                Font oldFont = g.getFont();
                g.setFont(new Font(null, "Arial", 8, SWT.BOLD));//Bug is not repeatable if this line removed
                g.drawString("apple", new Point(10, 50));
                g.setFont(oldFont); //Restore default font style

//Fill a rectangle and draw some text transparently
                g.pushState();
                g.setAlpha(128); //Bug is not repeatable if this line removed
                g.fillRectangle(10, 70, 100, 30); //Bug is not repeatable if this line removed
                g.drawString("orange", new Point(10, 70));
                g.popState();
//Draw the last piece of text.
//The text is unexpectedly written in bold.
                g.drawString("banana", new Point(10, 90));
            }
        });
        
        shell.layout();
        shell.open();
        
        Display display = Display.getDefault();
        while(!shell.isDisposed())
            if (!display.readAndDispatch())
                display.sleep();
        display.dispose();
    }
}
Comment 1 cricri CLA 2006-09-18 11:17:14 EDT
Created attachment 50385 [details]
Piece of code that makes the bug appear

Creating two simple figures that use alphablending in their paint() method, have a border in common, and use a zoom ratio different from 1.0, display their text badly scaled.
Comment 2 cricri CLA 2006-09-18 11:18:51 EDT
Comment by Cricri: 
I encountered the same issue.
Randy (Hudson) told me to create a bug, but this one seems to depict what I experienced (although my OS is Windows Server 2003).

Please find attached a piece of code that shows the bug, and a possible resolution (although not satisfying).
Comment 3 Randy Hudson CLA 2006-09-18 11:51:44 EDT
Please try debugging popState() to see why this is happening. You've helped a lot by attaching a test case, but I suspect the problem is when switching back to non-advanced graphics.

If you can not reproduce this on the Mac or GTK, it is probably an SWT bug. Sometimes they have to maintain two representations of things like pens and fonts.
Comment 4 Alexander Nyßen CLA 2011-10-12 16:38:16 EDT
I tried to reproduce this on Windows 7 and MacOS X using a current GEF (3.7.1) and could not. Could you please confirm whether this is no longer an issue?
Comment 5 Alexander Nyßen CLA 2011-10-13 17:41:31 EDT
(In reply to comment #4)
> I tried to reproduce this on Windows 7 and MacOS X using a current GEF (3.7.1)
> and could not. Could you please confirm whether this is no longer an issue?

Resolving as WORKSFORME due to my last comment. Please reopen in case this can still be reproduced in some scenario.