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

Bug 328940

Summary: [Canvas] GC not drawing as in SWT
Product: [RT] RAP Reporter: Samy Abou-Shama <sa>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: tbuschto
Version: 1.4   
Target Milestone: 1.4   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
code example
none
Image that shows the difference between RCP and RAP (zoomed)
none
screenshot better showcasing the issue none

Description Samy Abou-Shama CLA 2010-10-28 11:24:44 EDT
Created attachment 181959 [details]
code example

Hi there, 

I have am drawing my own rounded borders for my composites/canvas, using the GC. 

I developed it in RCP and now that want to use it in RAP it does not draw as expected. 

Please see the attachments for the snippet used and for screenshots that show the results.

Note, that I will help myself for now by using images instaed of drawing the border myself, therefore the bug has not a high prio for me :-)

Thank you 

Samy
Comment 1 Samy Abou-Shama CLA 2010-10-28 11:32:09 EDT
Created attachment 181961 [details]
Image that shows the difference between RCP and RAP (zoomed)
Comment 2 Tim Buschtoens CLA 2010-11-04 09:24:50 EDT
Created attachment 182367 [details]
screenshot better showcasing the issue

                  GC gc = e.gc;
                  gc.setLineWidth(1);
                  gc.setForeground(new Color(parent.getDisplay(), 255, 0, 0));
                  gc.drawPoint( 0, 0);
                  gc.drawLine(5, 5, 5, 15);
                  gc.setLineWidth(2);
                  gc.drawLine(5, 15, 5, 30);
                  gc.setLineWidth(3);
                  gc.drawLine(5, 30, 5, 45);
                  gc.setLineWidth(4);
                  gc.drawLine(5, 45, 5, 60);
Comment 3 Tim Buschtoens CLA 2010-11-04 10:19:12 EDT
So apparently the HTML5 canvas used here, coordinates are relative to the upper-left corner of a pixel (like in SVG), while in GC they address the center of the pixel (like VML), at least when the stroke-width is 1. (The canvas coordinate system is very well explained here: http://diveintohtml5.org/canvas.html#coordinates). However, if the stroke-width is even, GC behaves like it also addresses the pixels corner, causing the stroke to always exactly fill a full number of pixels. (This always assumes that the stroke expands equally in all directions from its point of origin.)

Fill-commands are not bothered by this at all, the behave like SVG in Canvas and GC.

Af far as i can tell, IE behaves like FF in this case, as we did a good job adapting VML to Canvas-behavior.
Comment 4 Tim Buschtoens CLA 2010-11-04 10:52:04 EDT
Okay, i tried fixing the GC.js with this method:

    _fixOffset : function( value ) {
      var result = value;
      if( this._context.lineWidth % 2 !== 0 ) {
        result += 0.5
      }
      return result;
    },
    
But then another problem occurs: Using the (default) lineCap "butt", the stroke does not extend in the direction of the line drawn, causing the line to start/end between pixels again, looking blurry... Not sure there is a way around that, but it looks okay using lineCap "square"...
Comment 5 Tim Buschtoens CLA 2011-03-08 05:03:57 EST
Using antialiasing in SWT brings the result much closer to the result in RAP (solves the CAP problem), but there a still a number of differences:
- The offset problem discussed here
- RoundRects have the wrong radius
- Rectangles dont respect the line-join attribute in IE.
Comment 6 Tim Buschtoens CLA 2011-03-08 06:22:18 EST
Fix for offset and roundrect issue in in CVS HEAD. The ie-rect-join issue is more difficult to fix.
Comment 7 Tim Buschtoens CLA 2012-02-01 05:03:29 EST
Since the remaining line-cap issue can be considered a minor flaw and no one has complained about it, i'm closing this bug.