Menu

#1373 Long dashed lines cause problems on canvases

obsolete: 8.4.1
open
5
2003-01-07
2003-01-07
No

Long dashed horizontal lines cause problems for the
canvas. Consider
the following script:

pack [canvas .c]
.c create line 0 20 100000 20 -width 4 -fill red -dash .
.c create line -100000 40 100000 40 -width 4 -fill
blue -dash .
.c create line -32767 60 32767 60 -width 4 -fill
green -dash .

On Unix (RedHat 7.3), the top red line is displayed
correctly. The
middle blue line does not appear at all. The lower
green line initially
does not appear. But if you take another window and
drag it slowly
over top of the canvas, bits of the green line will
appear as Expose
events are processed.

On win2k, (VMWare on the same RedHat 7.3 machine) the
canvas
displays correctly but expose events take about 10
seconds to process.
While expose events are pending, the CPU is maxed out
at 100%
usage and the display is locked up.

The lines are displayed correctly (and quickly) if the
-dash option is
omitted.

Discussion

  • D. Richard Hipp

    D. Richard Hipp - 2003-01-07
    • assigned_to: hobbs --> hobbs
     
  • George A. Howlett

    Logged In: YES
    user_id=137748

    I don't think the problem is dashed lines.

    Rather it has to do with the fact that

    1) the coordinates are beyond the size of a short integer
    (the size of an X coordinate) and
    2) the canvas does no clipping of lines.

    You'll notice that if the lines aren't horizontal (or
    vertical) that
    it doesn't matter if the lines are dashed or not.

    This could be remedied by clipping the generated line segments
    before asking X to draw them. The same type of thing would
    need to be done for polygons and arcs.

    --gah

     
  • Jeffrey Hobbs

    Jeffrey Hobbs - 2003-01-08

    Logged In: YES
    user_id=72656

    It appears that tkCanvUtil.c:Tk_CanvasDrawableCoords does
    the clipping, but it is incorrect before it just clips a point
    without respect to how it might change the geometry of a
    larger object that uses it. The clipping needs to be done
    upstream somewhere, and should probably also be done to
    clip to the viewable area instead of just 16-bit coords. No
    need to ask X to draw something that will be clipped.

     
  • George A. Howlett

    Logged In: YES
    user_id=137748

    It's generous to call what Tk_CanvasDrawableCoords does
    clipping.

    Instead it's bounding the coordinates to the size of short
    ints. I did this
    for a while in the graph widget. It doesn't work. Except
    for horizontal
    or vertical lines, it changes the slope of the line badly.

    Tk_CanvasDrawableCoords also doesn't leave room (dashes would
    probably work if it clipped to +/-30000) for other
    calcuations like
    dash offsets.

    A Liang-Barsky or Cohen-Sutherland clipper is easy enough to
    implement. But it would change the drawing code, since multiple
    traces might be generated for a single continuous line. A
    single
    XDrawLines call would no longer be sufficient.

    --gah

     
  • D. Richard Hipp

    D. Richard Hipp - 2003-01-08

    Logged In: YES
    user_id=69293

    I'm working on a clipper now. I should be able to check in
    code soon.

     
  • George A. Howlett

    Logged In: YES
    user_id=137748

    I have code for both Liang-Barsky and Cohen-Sutherland clipping
    routines if you want it. For the canvas, I think the
    Liang-Barsky
    algorithm is a better fit since canvas coordinates are
    floating point.

    --gah

     
  • D. Richard Hipp

    D. Richard Hipp - 2003-01-08

    Logged In: YES
    user_id=69293

    The code to fix this problem for "line"s is in.
    But I'm going to leave the bug open as a reminder
    to myself to go back and check for the same problem
    in polygons, arcs, rectangles, etc.

     
MongoDB Logo MongoDB