Tk Source Code

View Ticket
Login
Ticket UUID: 1678582
Title: Use native curves (where available)
Type: RFE Version: None
Submitter: lars_h Created on: 2007-03-11 22:11:49
Subsystem: 05. Canvas Items Assigned To: das
Priority: 5 Medium Severity:
Status: Open Last Modified: 2007-10-31 02:35:24
Resolution: None Closed By:
    Closed on:
Description:
A couple of weeks ago, I upgraded my TclTkAqua installation because I needed dashed lines. I did get them, but I also got some rather disturbing sideeffects...

(At this point, please download and unpack the attachment images.tar.gz, since the text will make a lot more sense if you can also see the images.)

1. Before the upgrade, things looked as in CG0.png: smooth lines of constant width. Things still look this way if I set tk::mac::useCGDrawing to 0 (hence the image name), but this is hardly the way forward (I suspect I'd lose the ability to draw dashed lines, for one).

2. What shocked me is the image CG1-AAL3.png ($tk::mac::useCGDrawing==1 and $tk::mac::CGAntialiasLimit==3, i.e., the default). where several curves seem affected by extreme scurf, in some places being three times thicker than normal. This is BAD!

3. I then tried decreasing $tk::mac::CGAntialiasLimit to 1, which brings us to CG1-AAL1.png. This is acceptable, so it is what I use, but it is not good that one has to fiddle with such platform-specific settings in order to get an acceptable picture.

And what causes the horrible rendering in CG1-AAL3.png?

4. Following a hunch that the problem has to do with rounding in the rendering of curves as many small line segments, I try decreasing the -splinesteps setting to 3, resulting in CG1-AAL3-SS3.png. This looks very much like CG0.png, except for the occational pixel spur, so apparently the hunch was correct: the default rendering of curves is to blame. Turning on antialiasing can hide the problem, but Tk still sends data with a lot of noise in it to the rendering software, so it hardly qualifies as a cure.

What could be done?

One thing that comes to mind is to let Quartz (the Mac OS X graphics engine) do the rendering of curves, instead of insisting on doing it in Tk; there is a function CGContextAddCurveToPoint which takes the same kind of data as the postscript canvas subcommand needs, so why not take advantage of that? (It would most likely be both faster and produce higher quality pictures.) Why stick to lines (and arcs)?

Apparently because Xlib doesn't know about them, and Tk does all its drawing through the Xlib Emulation Layer. [Sigh.] There's no technical reason for Tk's emulation to be confined to what Xlib has native operations for however, so I guess this RFE boils down to:

* Add drawing "primitives" that deal with curves (whose segments are cubic Bezier curves), and use these when drawing -smooth canvas items. Implement as now (via XDrawLines etc.) on platforms which don't natively support curves, but take advantage of such support when available. The -splinesteps parameter could be an argument to the new drawing primitives, to be used or ignored depending on whether it makes sense for the implementation in question. *

Another thing that would be nice is if these new drawing primitives could be relieved of the Xlib restriction that all coordinates are integers. Subpixel precision is sometimes important!

Lars Hellström
User Comments: hobbs added on 2007-10-31 02:35:24:
Logged In: YES 
user_id=72656
Originator: NO

das has been working on this, perhaps this is already addressed.

lars_h added on 2007-03-12 05:11:49:

File Added - 219905: images.tar.gz

Attachments: