| Ticket UUID: | 3df559ef7c7e618a96241d5ff20cd592aa03d3f0 | |||
| Title: | Negative bbox width on OS X | |||
| Type: | Bug | Version: | core-8-6-branch | |
| Submitter: | fvogel | Created on: | 2016-12-11 20:28:10 | |
| Subsystem: | 18. [text] | Assigned To: | fvogel | |
| Priority: | 6 | Severity: | Minor | |
| Status: | Closed | Last Modified: | 2017-01-07 15:07:00 | |
| Resolution: | Fixed | Closed By: | fvogel | |
| Closed on: | 2017-01-07 15:07:00 | |||
| Description: |
It is possible, on OS X only, to get (wrong) negative width returned by the bbox command of the text widget. This is only happening when TK_LAYOUT_WITH_BASE_CHUNKS is defined, which as of the current state of the text widget code only is the case on OS X (not on Linux nor on Windows). Example: package require Tk pack [text .t -width 20 -height 10 -wrap char] .t insert 1.0 "abcd\nefg hijkl mnop qrstuv wxyz" .t tag configure y -wrap none update .t tag add y 1.end 2.2 .t bbox 2.20 ; # returns a *negative* width! #destroy .t | |||
| User Comments: |
fvogel added on 2017-01-07 15:07:00:
Negative widths in OS X bboxes being fixed, they are now merged into core-8-6-branch and trunk. fvogel added on 2017-01-07 15:05:14: Thinking twice, in [0a5582b9] I have reverted [7ed6460f] since it fixes an issue unrelated to the present ticket about negative bbox widths. This specific problem is now followed up here: [ae32eb7e10] (Win + specific text widget configuration : textDisp-18.6, -20.2 -20.3 -20.4 fail fvogel added on 2016-12-30 22:32:21: Changed my mind. It's better to leave things as they were on OS X, for the following reasons: - performance (it saves a TkpMeasureCharsInContext()) - it matches the comments in TkpDrawCharsInContext() that state that x and y are "coordinates at which to place origin of the whole (not just the range) string when drawing" - less risk overall Therefore I have reverted [a076cf64] and [42e0339e]), and have fixed TkpDrawCharsInContext() on Win and Linux instead, just in case these platforms at some point of time decide to define TK_LAYOUT_WITH_BASE_CHUNKS and TK_DRAW_IN_CONTEXT to true. This is [afe41bdd]. fvogel added on 2016-12-30 21:53:12: With [42e0339e], OS X shows the same issue that Windows had before [42e0339e] when TK_LAYOUT_WITH_BASE_CHUNKS and TK_DRAW_IN_CONTEXT are true. [42e0339e] is a platform-independent fix (even if the fix is only used when TK_DRAW_IN_CONTEXT is 1 which in turn is only true on OS X). [42e0339e] changes the x position at which the text is drawn, and this new position is correct when TkpDrawCharsInContext() just calls Tk_DrawChars(), as is the case on Win and Linux. On OS X however, TkpDrawCharsInContext() calls DrawCharsInContext(), and the x position sent to DrawCharsInContext() must be corrected back. This is what [a076cf64] now does. fvogel added on 2016-12-30 09:11:29: Sorry, forget about my previous message below (dated 2016-12-25 20:46:20), this is pure bullshit based on a mistake of mine (I was not running the correct wish). All bbox results are correct in branch bug-3df559ef7c, at [42e0339e]. The status in my message dated 2016-12-25 15:17:23 is fully correct. fvogel added on 2016-12-25 20:46:20: Another way of getting negative width in bbox output is:
package require Tk
pack [text .t -width 20 -height 10]
.t insert 1.0 "abcdefgh"
.t tag configure y -foreground red
update
.t tag add y 1.1 1.3
.t bbox 1.4 ; # returns a *negative* width
for {set i 0} {$i < 8} {incr i} {puts [.t bbox 1.$i]}
Output produced:
32 4 -14 15
4 4 7 15
11 4 7 15
18 4 0 15
25 4 7 15
32 4 -14 15
39 4 -14 15
46 4 -14 15
53 4 -14 15
This is on OS X. Does not happen on Windows. Happens on OS X even when the configuration of the textDisp engine is changed to: #define TK_LAYOUT_WITH_BASE_CHUNKS 0 #define TK_DRAW_IN_CONTEXT 0Therefore this has nothing to do with base chunks and/or drawing "in context". If, instead of -foreground, the -font is configured in the tag, then it works OK. fvogel added on 2016-12-25 15:17:23: On Windows, when defining TK_LAYOUT_WITH_BASE_CHUNKS and TK_DRAW_IN_CONTEXT for testing purposes, the test suite for textDisp.test alone now runs 100% clean (no failure), same as when these flags are not defined (which is the case in the source code for the Windows platform). On OS X (TK_LAYOUT_WITH_BASE_CHUNKS and TK_DRAW_IN_CONTEXT are defined in the source code for this platform), core-8-6-branch shows 40 failures (including textDisp-18.6) for textDisp.test file alone. In branch bug-3df559ef7c, at [42e0339e], there are the same 39 failures, but textDisp-18.6 now passes. Therefore the fixes in this branch are believed to be OK, despite still not fixing all test results from textDisp.test. fvogel added on 2016-12-23 22:20:41: On top of all this, on Windows at least, there is a display issue when both TK_LAYOUT_WITH_BASE_CHUNKS and TK_DRAW_IN_CONTEXT are defined: some chunks are rendered at the wrong x position, leading to superimposition of some chunks. This can be seen by running either of the following scripts: ################################# package require Tk pack [text .t] .t insert end "AB" .t mark set insert 1.1 ; # "B" is not correctly displayed! it is ON TOP of A! ################################# ################################# package require Tk pack [text .t -insertofftime 0] .t insert end "AB" focus -force .t .t tag add sel 1.1 1.end ; # incorrect rendering ################################# ################################# package require Tk pack [text .t -insertofftime 0 -inactiveselectbackground red] .t insert end "ABCDEFGHIJKLMNOPQRSTUVWXYZ" focus -force .t .t tag add sel 1.10 1.end ; # incorrect rendering ################################# ################################# package require Tk pack [text .t -insertofftime 0] .t insert end [string repeat "AB" 50] .t mark set insert 1.25 ; # incorrect rendering ################################# ################################# package require Tk pack [text .t -insertofftime 0 -wrap none] -expand 1 -fill both .t insert end [string repeat "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 5] .t mark set insert 1.25 ; # incorrect rendering ################################# This problem is fixed by [42e0339e]. fvogel added on 2016-12-23 22:08:41: On Windows, independently of the original problem (negative bbox width), when both following flags are defined (add this in tkWinInt.h for testing purposes): #define TK_LAYOUT_WITH_BASE_CHUNKS 1 #define TK_DRAW_IN_CONTEXT 1 The following tests fail (and they fail as well on OS X): textDisp-18.6 textDisp-20.2 textDisp-20.3 textDisp-20.4 This is fixed by [7ed6460f]. fvogel added on 2016-12-23 19:17:08: Fix I proposed below was incorrect. Correct (hopefully) fix is [67b7d4f1]. This fix was tested on Windows with TK_LAYOUT_WITH_BASE_CHUNKS being defined. It fixes the following tests that failed on Windows when TK_LAYOUT_WITH_BASE_CHUNKS is defined: textDisp-1.2 textDisp-2.7 textDisp-2.10 textDisp-13.7 textDisp-13.8 textDisp-13.9 textDisp-22.1 textDisp-22.2 Needs testing on OS X. WILCO. fvogel added on 2016-12-11 20:39:03: The following patch fixes the test script and all the 8 test failures mentioned:
Index: generic/tkTextDisp.c
==================================================================
--- generic/tkTextDisp.c
+++ generic/tkTextDisp.c
@@ -7822,10 +7822,11 @@
xDisplacement = startX - widthUntilStart - chunkPtr->x;
}
fit = MeasureChars(tkfont, chars, charsLen, 0, bend,
ciPtr->baseChunkPtr->x + xDisplacement, maxX, flags, nextXPtr);
+ *nextXPtr -= xDisplacement;
if (fit < bstart) {
return 0;
} else {
return fit - bstart;
But it creates new failures in the test suite when both TK_LAYOUT_WITH_BASE_CHUNKS and TK_DRAW_IN_CONTEXT are defined, which is the OS X case. Stay tuned... fvogel added on 2016-12-11 20:34:37: Demonstration of this issue can be done on Windows (for instance) as well, by defining TK_LAYOUT_WITH_BASE_CHUNKS in tkWinInt.h and running the Tk test suite with the textDisp.test file. Then one gets (all these failures show the same issue: negative width in bbox output):
Tests began at Thu Dec 08 23:03:36 +0100 2016
textDisp.test
==== textDisp-1.2 GetStyle procedure, wrapmode FAILED
==== Contents of test case:
.t configure -wrap char
.t delete 1.0 end
.t insert 1.0 "abcd\nefg hijkl mnop qrstuv wxyz"
.t tag configure x -wrap word
.t tag configure y -wrap none
.t tag raise y
update
set result [list [.t bbox 2.20]]
.t tag add x 2.0 2.1
lappend result [.t bbox 2.20]
.t tag add y 1.end 2.2
lappend result [.t bbox 2.20]
---- Result was:
{5 35 7 15} {40 35 7 15} {145 20 -7 15}
---- Result should have been (exact matching):
{5 35 7 15} {40 35 7 15} {}
==== textDisp-1.2 FAILED
==== textDisp-2.7 LayoutDLine, marks and tags FAILED
==== Contents of test case:
.t configure -wrap word
.t delete 1.0 end
.t insert 1.0 "This isxxx some sample text for testing."
.t tag add foo 1.4 1.6
.t mark set insert 1.8
list [.t bbox 1.2] [.t bbox 1.5] [.t bbox 1.11]
---- Result was:
{19 5 7 15} {40 5 -21 15} {82 5 -49 15}
---- Result should have been (exact matching):
{19 5 7 15} {40 5 7 15} {82 5 7 15}
==== textDisp-2.7 FAILED
==== textDisp-2.10 LayoutDLine, marks and tags FAILED
==== Contents of test case:
.t configure -wrap word
.t delete 1.0 end
.t insert 1.0 "This is a very_very_long_word_that_wraps."
.t tag add foo 1.13
.t tag add foo 1.15
.t tag add foo 1.17
.t tag add foo 1.19
list [.t bbox 1.9] [.t bbox 1.10] [.t bbox 1.25]
---- Result was:
{68 5 77 15} {5 20 7 15} {110 20 -63 15}
---- Result should have been (exact matching):
{68 5 77 15} {5 20 7 15} {110 20 7 15}
==== textDisp-2.10 FAILED
==== textDisp-13.7 TkTextSeeCmd procedure FAILED
==== Contents of test case:
.t xview moveto 0
.t yview moveto 0
.t tag add sel 30.20
.t tag add sel 30.40
update
.t see 30.50
.t yview 25.0
.t see 30.50
set x [list [.t bbox 30.50]]
.t see 30.39
lappend x [.t bbox 30.39]
.t see 30.38
lappend x [.t bbox 30.38]
.t see 30.20
lappend x [.t bbox 30.20]
---- Result was:
{353 78 -280 15} {276 78 -140 15} {269 78 -140 15} {136 78 7 15}
---- Result should have been (exact matching):
{73 78 7 15} {3 78 7 15} {3 78 7 15} {73 78 7 15}
==== textDisp-13.7 FAILED
==== textDisp-13.8 TkTextSeeCmd procedure FAILED
==== Contents of test case:
.t xview moveto 0
.t yview moveto 0
.t tag add sel 30.20
.t tag add sel 30.50
update
.t see 30.50
set x [list [.t bbox 30.50]]
.t see 30.60
lappend x [.t bbox 30.60]
.t see 30.65
lappend x [.t bbox 30.65]
.t see 30.90
lappend x [.t bbox 30.90]
---- Result was:
{73 73 7 15} {} {} {}
---- Result should have been (exact matching):
{73 73 7 15} {136 73 7 15} {136 73 7 15} {73 73 7 15}
==== textDisp-13.8 FAILED
==== textDisp-13.9 TkTextSeeCmd procedure FAILED
==== Contents of test case:
wm geom . [expr $width-2]x$height
.t xview moveto 0
.t yview moveto 0
.t tag add sel 30.20
.t tag add sel 30.50
update
.t see 30.50
set x [list [.t bbox 30.50]]
.t see 30.60
lappend x [.t bbox 30.60]
.t see 30.65
lappend x [.t bbox 30.65]
.t see 30.90
lappend x [.t bbox 30.90]
---- Result was:
{74 75 7 15} {} {} {354 75 -350 15}
---- Result should have been (exact matching):
{74 75 7 15} {138 75 7 15} {138 75 7 15} {74 75 7 15}
==== textDisp-13.9 FAILED
==== textDisp-22.1 TkTextCharBbox FAILED
==== Contents of test case:
.t config -wrap word
.t yview 48.0
list [.t bbox 47.2] [.t bbox 48.0] [.t bbox 50.5] [.t bbox 50.40] [.t bbox 58.0]
---- Result was:
{} {3 3 7 15} {38 33 -7 15} {3 63 7 15} {}
---- Result should have been (exact matching):
{} {3 3 7 15} {38 33 7 15} {3 63 7 15} {}
==== textDisp-22.1 FAILED
==== textDisp-22.2 TkTextCharBbox FAILED
==== Contents of test case:
.t config -wrap none
.t yview 48.0
list [.t bbox 50.5] [.t bbox 50.40] [.t bbox 57.0]
---- Result was:
{38 33 -7 15} {} {3 138 7 15}
---- Result should have been (exact matching):
{38 33 7 15} {} {3 138 7 15}
==== textDisp-22.2 FAILED
Tests ended at Thu Dec 08 23:03:53 +0100 2016
all.tcl: Total 392 Passed 373 Skipped 11 Failed 8
Sourced 1 Test Files.
Files with failing tests: textDisp.test
Number of tests skipped for each constraint:
9 nonPortable
2 unix
| |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki