Tk Source Code

View Ticket
Login
Ticket UUID: 220796
Title: -stipple option for canvas text item disrupts positioning, b
Type: Bug Version: 8.1b2, 8.6.18, 9.0.5, 9.1.0
Submitter: welch Created on: 2000-11-01 00:54:14
Subsystem: 05. Canvas Items Assigned To: aku
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-11-02 16:51:19
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-11-02 16:51:19
Description:
OriginalBugID: 1522 Bug
Version: 8.1b2
SubmitDate: '1999-03-18'
LastModified: '2000-04-03'
Severity: SER
Status: Assigned
Submitter: pat
ChangedBy: ericm
OS: Windows 95
OSVersion: OSR2, US English
Machine: X86


Name:
Bill Schongar

Extensions:
None

CustomShell:
None

ReproducibleScript:
    pack [canvas .c]
    .c create text 10 10 "Foo" -tags a
    .c create text 90 10 "Foo" -stipple gray12 -tags b
    eval .c create rectangle [.c bbox b] -fill green
    



ObservedBehavior:
    1) The text is not stippled, it appears in a "selected" state
    2) The text with the '-stipple' option applied does not occupy the
      bounds reported by bbox, as shown by the rectangle drawn to occupy
      that reported space.
    



DesiredBehavior:
    1) Text stippled based on the bitmap pattern specified
    2) Text occupies spaces which it's supposed to, and which it
      reports that it is.
    





    Not unique to 8.1b2, occurs in 8.1b1
---
Only occurs on Windows.  Unix is OK.    
There are two interesting bugs that appear in this report.  In interactive mode, enter in the following lines:

BUG #1
-----------
    pack [canvas .c]
    .c create text 20 10 -text "Default" -tags a
    .c create text 90 10 -text "Stipple Off" -tags b

Notice that both strings are drawn at even Y-axis.  Now enter:

    .c create text 90 10 -text "Stipple ON" -stipple gray12 -tags b

The stippled test, although it has the same coords, is drawn with a different Y-axis.
Now enter:

    eval .c create rectangle [.c bbox b] -fill green

Notice we did a bbox on the stipppled text.  However we got the coords for the non-stippled text.

BUG #2
-----------
Notice that the stippled text is cropped.  Resize the window and the full text is now displayed.

03/25/1999 12:06 - surles -
User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-11-02 16:51:19:

Serhiy, many, many thanks for providing the 9.0 version of your fix! This worked immediately, without any code change. The fix is now merged into main, core-9-0-branch, and core-8-6-branch by commits [fde93bd2] (Jan), [29e1638b], and [89594d45]. Closing the ticket.


serhiy.storchaka added on 2026-11-02 13:31:27:

The 9.0 version is on branch win-text-stipple-9.0, [4fd4398349]. In 9.0, Tk_DrawChars() and TkDrawAngledChars() drew stippled text into the destination instead of the memory DC, so it was not drawn at all; they now use the same BeginStippledText()/EndStippledText() as 9.1.


kevin_walzer added on 2026-11-02 12:42:07:
Or, maybe we don’t backport?

jan.nijtmans added on 2026-11-02 12:33:39:

I tried the backport to 9.0 as well. Same result :-(


nemethi (claiming to be Csaba Nemethi) added on 2026-11-02 10:44:18:

I have tried to cherrypick Jan's commit from main into core-9-0-branch, but after several hours I had to give up because of the file win/tkWinFont.c, which, due to the bidi/shaping stuff, in Tk 9.1 is much more complicated than in Tk 9.0.

I see two possible ways for backporting to core-9-0-branch:

1. Someone more proficient in fonts and bidi/shaping on Windows masters the cherrypick;

2. Serhiy kindly provides a version of the bugfix which is ready for merge into core-9-0-branch.


jan.nijtmans added on 2026-10-27 20:34:49:

Thanks! Confirming the testcase works for me now. I also fixed frame-12.3 from the "tests-high-dpi" branch, which was also failing for me and now passed.

Let's see tomorrows CI run. If it passes, it can be backported to 9.0 and 8.6.


serhiy.storchaka added on 2026-10-27 18:02:34:

The failure of canvText-21.1 was in the test: the text is given in points, and from 200% display scaling it no longer fits in the 200×60 canvas, so countPixels read outside of it. Fixed in [5b8a105362]: a 200×200 canvas and a single "M", and the knownBug constraint removed. On Windows 11 with tk scaling 1.0 to 4.67 (350%), the test passes with the fix (half of the pixels are drawn, as expected) and fails without it.

Jan, many other tests fail at a high display scale for similar reasons, see [deca13e833]. Some of the fixes from branch tests-high-dpi were merged, but not those for fonts and sizes in points, scrollbar arrows and the default sizes in tk.tcl; the toplevel minimum width is addressed by branch tests-min-width. Could you have a look at them?


jan.nijtmans added on 2026-10-27 16:44:41:

Running the testcase on Windows 11, I see:

canvText.test
==== canvText-21.1 stippled text - bug 220796 FAILED
==== Contents of test case:
    .c create text 10 10 -anchor nw -text MMMM -font {Courier 30 bold} -fill black
    update
    set bbox [.c bbox 1]
    set plain [countPixels .c {*}$bbox]
    .c itemconfigure 1 -stipple gray50
    update
    set stippled [countPixels .c {*}$bbox]
    # About half of the pixels are drawn with a gray50 stipple.
    list [expr {[.c bbox 1] eq $bbox}]  [expr {$stippled * 10 > $plain * 3 && $stippled * 10 < $plain * 7}]
---- Test generated error; Return code was: 1
---- Return code should have been one of: 0 2
---- errorInfo: coordinates 9,60 are outside window ".c"
    while executing
"testpixel $w $x $y"
    (procedure "countPixels" line 5)
    invoked from within
"countPixels .c {*}$bbox"
    ("uplevel" body line 5)
    invoked from within
"uplevel 1 $script"
---- errorCode: NONE
==== canvText-21.1 FAILED

Manually running the code in the bug description works fine, so I suspect the problem is somewhere in the testcase. Therefore - for now - I will add the knownBug constraint.


serhiy.storchaka added on 2026-10-22 22:49:16:

Re-tested on Windows 11 with today's main: stippled text is still drawn solid, and angled stippled text is not drawn at all. With branch win-text-stipple both are stippled and the bounding box does not change; canvText.test, font.test and winFont.test pass with it.


serhiy.storchaka added on 2026-09-22 07:48:54:

There were more bugs here than reported. On Windows the stipple was ignored altogether for text drawn through the text layout (canvas text items, text widget), so the text was solid. Angled text with a stipple took a different path in TkDrawAngledChars(), which had three bugs of its own: it drew the text into the destination instead of the memory DC (so it was solid too), it measured the text on a DC without the font selected, and it passed the UTF-8 bytes to GetTextExtentPointA(); the last two gave a wrong size and position, which is the misplacement in the report.

Fixed in [99b9c92a0a] (branch win-text-stipple): text with a stipple is drawn into a memory DC and copied through the stipple pattern, like other stippled objects, in both paths; the size of the memory DC is taken from Tk_MeasureChars() and the font metrics. The bbox is not affected. Test canvText-21.1 (Windows and X11 without Xft; Xft and Aqua do not support stippled text).


nobody added on 2004-03-28 10:32:24:
Logged In: NO 

CL's willing to pay for progress on this.  Contact <[email protected]>.