From 367aec82f9a1bf9919b5e8d29da7c00bb61f17fc Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sat, 16 Mar 2024 19:55:23 +0000 Subject: [PATCH 1/2] eliminate end-of-line spacing in send.test. Code cleanup in tkFont.c --- generic/tkFont.c | 38 +++++++++++++++++++++----------------- tests/send.test | 13 ++----------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/generic/tkFont.c b/generic/tkFont.c index cef6f862a..51c4c18cb 100644 --- a/generic/tkFont.c +++ b/generic/tkFont.c @@ -526,7 +526,7 @@ Tk_FontObjCmd( * Next parameter may be an option. */ - n = skip + 3; + n = 3 + skip; optPtr = NULL; charPtr = NULL; if (n < objc) { @@ -713,7 +713,7 @@ Tk_FontObjCmd( if (skip < 0) { return TCL_ERROR; } - if (objc - skip != 2) { + if (objc != 2 + skip) { Tcl_WrongNumArgs(interp, 2, objv, "?-displayof window?"); return TCL_ERROR; } @@ -723,7 +723,8 @@ Tk_FontObjCmd( case FONT_MEASURE: { const char *string; Tk_Font tkfont; - int length = 0, skip = 0; + int length = 0; + int skip = 0; if (objc > 4) { skip = TkGetDisplayOf(interp, objc - 3, objv + 3, &tkwin); @@ -731,7 +732,7 @@ Tk_FontObjCmd( return TCL_ERROR; } } - if (objc - skip != 4) { + if (objc != 4 + skip) { Tcl_WrongNumArgs(interp, 2, objv, "font ?-displayof window? text"); return TCL_ERROR; @@ -758,7 +759,7 @@ Tk_FontObjCmd( if (skip < 0) { return TCL_ERROR; } - if ((objc < 3) || ((objc - skip) > 4)) { + if ((objc < 3) || (objc > 4 + skip)) { Tcl_WrongNumArgs(interp, 2, objv, "font ?-displayof window? ?option?"); return TCL_ERROR; @@ -1464,8 +1465,7 @@ Tk_FreeFont( */ nfPtr = (NamedFont *)Tcl_GetHashValue(fontPtr->namedHashPtr); - nfPtr->refCount--; - if ((nfPtr->refCount == 0) && nfPtr->deletePending) { + if ((nfPtr->refCount-- <= 1) && nfPtr->deletePending) { Tcl_DeleteHashEntry(fontPtr->namedHashPtr); ckfree(nfPtr); } @@ -1552,8 +1552,7 @@ FreeFontObj( TkFont *fontPtr = (TkFont *)objPtr->internalRep.twoPtrValue.ptr1; if (fontPtr != NULL) { - fontPtr->objRefCount--; - if ((fontPtr->resourceRefCount == 0) && (fontPtr->objRefCount == 0)) { + if ((fontPtr->objRefCount-- <= 1) && (fontPtr->resourceRefCount == 0)) { ckfree(fontPtr); } objPtr->internalRep.twoPtrValue.ptr1 = NULL; @@ -1991,7 +1990,8 @@ Tk_ComputeTextLayout( { TkFont *fontPtr = (TkFont *) tkfont; const char *start, *endp, *special; - int n, y, bytesThisChunk, maxChunks, curLine, layoutHeight; + int n; + int y, bytesThisChunk, maxChunks, curLine, layoutHeight; int baseline, height, curX, newX, maxWidth, *lineLengths; TextLayout *layoutPtr; LayoutChunk *chunkPtr; @@ -2326,7 +2326,8 @@ Tk_DrawTextLayout( TkDrawAngledTextLayout(display, drawable, gc, layout, x, y, 0.0, firstChar, lastChar); #else TextLayout *layoutPtr = (TextLayout *) layout; - int i, numDisplayChars, drawX; + int i, drawX; + int numDisplayChars; const char *firstByte, *lastByte; LayoutChunk *chunkPtr; @@ -2354,7 +2355,7 @@ Tk_DrawTextLayout( numDisplayChars = lastChar; } lastByte = TkUtfAtIndex(chunkPtr->start, numDisplayChars); -#if TK_DRAW_IN_CONTEXT +#ifdef TK_DRAW_IN_CONTEXT TkpDrawCharsInContext(display, drawable, gc, layoutPtr->tkfont, chunkPtr->start, chunkPtr->numBytes, firstByte - chunkPtr->start, lastByte - firstByte, @@ -2424,7 +2425,7 @@ TkDrawAngledTextLayout( numDisplayChars = lastChar; } lastByte = TkUtfAtIndex(chunkPtr->start, numDisplayChars); -#if TK_DRAW_IN_CONTEXT +#ifdef TK_DRAW_IN_CONTEXT dx = cosA * (chunkPtr->x) + sinA * (chunkPtr->y); dy = -sinA * (chunkPtr->x) + cosA * (chunkPtr->y); if (angle == 0.0) { @@ -3308,7 +3309,8 @@ Tk_TextLayoutToPostscript( LayoutChunk *chunkPtr = layoutPtr->chunks; int baseline = chunkPtr->y; Tcl_Obj *psObj = Tcl_NewObj(); - int i, j, len; + int i, j; + int len; const char *p, *glyphname; char uindex[5], c, *ps; int ch; @@ -3421,14 +3423,15 @@ noMapping: ; static int ConfigAttributesObj( Tcl_Interp *interp, /* Interp for error return. */ - TCL_UNUSED(Tk_Window), /* For display on which font will be used. */ + TCL_UNUSED(Tk_Window), /* For display on which font will be used. */ int objc, /* Number of elements in argv. */ Tcl_Obj *const objv[], /* Command line options. */ TkFontAttributes *faPtr) /* Font attributes structure whose fields are * to be modified. Structure must already be * properly initialized. */ { - int i, n, index; + int i; + int n, index; Tcl_Obj *optionPtr, *valuePtr; const char *value; @@ -3629,7 +3632,8 @@ ParseFontNameObj( * default values. */ { const char *dash; - int objc, result, i, n; + int result, n; + int objc, i; Tcl_Obj **objv; const char *string; diff --git a/tests/send.test b/tests/send.test index 7828713a0..722005bf1 100644 --- a/tests/send.test +++ b/tests/send.test @@ -442,23 +442,14 @@ test send-10.8 {SendEventProc procedure, exceptional return} {secureserver tests "c\n-n tktest\n-r $id 62\n-s break\n" update testsend prop [winfo id .f] Comm -} { -r --s 62 --r --c 3 -} +} "\nr\n-s 62\n-r \n-c 3\n" test send-10.9 {SendEventProc procedure, empty return} {secureserver testsend} { testsend prop [winfo id .f] Comm {} testsend prop comm Comm \ "c\n-n tktest\n-r $id 62\n-s concat\n" update testsend prop [winfo id .f] Comm -} { -r --s 62 --r -} +} "\nr\n-s 62\n-r \n" test send-10.10 {SendEventProc procedure, asynchronous calls} {secureserver testsend} { testsend prop [winfo id .f] Comm {} testsend prop comm Comm \ From b0966ec52b2a3554f8285dd944844c78a4e6348f Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sat, 16 Mar 2024 19:57:32 +0000 Subject: [PATCH 2/2] Fix [8912083dc]: Error with property TKNSString.UTF8String. Fix indenting --- macosx/tkMacOSXFont.c | 66 +++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index d413f0b14..88e359386 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -171,10 +171,8 @@ static int CreateNamedSystemFont(Tcl_Interp *interp, return _ds; } -#ifndef __clang__ @synthesize UTF8String = _UTF8String; @synthesize DString = _ds; -#endif @end #define GetNSFontTraitsFromTkFontAttributes(faPtr) \ @@ -771,7 +769,7 @@ void TkpGetFontAttrsForChar( TCL_UNUSED(Tk_Window), /* Window on the font's display */ Tk_Font tkfont, /* Font to query */ - int c, /* Character of interest */ + int c, /* Character of interest */ TkFontAttributes* faPtr) /* Output: Font attributes */ { MacFont *fontPtr = (MacFont *) tkfont; @@ -948,9 +946,9 @@ TkpMeasureCharsInContext( double maxWidth = maxLength + offset; NSCharacterSet *cs; - /* - * Get a line breakpoint in the source string. - */ + /* + * Get a line breakpoint in the source string. + */ index = start; if (flags & TK_WHOLE_WORDS) { @@ -963,9 +961,9 @@ TkpMeasureCharsInContext( index = CTTypesetterSuggestClusterBreak(typesetter, start, maxWidth); } - /* - * Trim right whitespace/lineending characters. - */ + /* + * Trim right whitespace/lineending characters. + */ cs = (index <= len && (flags & TK_WHOLE_WORDS)) ? whitespaceCharacterSet : lineendingCharacterSet; @@ -974,29 +972,29 @@ TkpMeasureCharsInContext( index--; } - /* - * If there is no line breakpoint in the source string between its - * start and the index position that fits in maxWidth, then - * CTTypesetterSuggestLineBreak() returns that very last index. - * However if the TK_WHOLE_WORDS flag is set, we want to break at a - * word boundary. In this situation, unless TK_AT_LEAST_ONE is set, we - * must report that zero chars actually fit (in other words the - * smallest word of the source string is still larger than maxWidth). - */ - - if ((index >= start) && (index < len) && - (flags & TK_WHOLE_WORDS) && !(flags & TK_AT_LEAST_ONE) && - ![cs characterIsMember:[string characterAtIndex:index]]) { - index = start; - } + /* + * If there is no line breakpoint in the source string between its + * start and the index position that fits in maxWidth, then + * CTTypesetterSuggestLineBreak() returns that very last index. + * However if the TK_WHOLE_WORDS flag is set, we want to break at a + * word boundary. In this situation, unless TK_AT_LEAST_ONE is set, we + * must report that zero chars actually fit (in other words the + * smallest word of the source string is still larger than maxWidth). + */ + + if ((index >= start) && (index < len) && + (flags & TK_WHOLE_WORDS) && !(flags & TK_AT_LEAST_ONE) && + ![cs characterIsMember:[string characterAtIndex:index]]) { + index = start; + } if (index <= start && (flags & TK_AT_LEAST_ONE)) { index = start + 1; } - /* - * Now measure the string width in pixels. - */ + /* + * Now measure the string width in pixels. + */ if (index > 0) { range.length = index; @@ -1013,7 +1011,7 @@ TkpMeasureCharsInContext( CFRelease(line); } - /* + /* * The call to CTTypesetterSuggestClusterBreak above will always return * at least one character regardless of whether it exceeded it or not. * Clean that up now. @@ -1194,9 +1192,9 @@ TkpDrawAngledCharsInContext( CGAffineTransform t; CGFloat width, height, textX = (CGFloat) x, textY = (CGFloat) y; - if (rangeStart < 0 || rangeLength <= 0 || - rangeStart + rangeLength > numBytes || - !TkMacOSXSetupDrawingContext(drawable, gc, &drawingContext)) { + if (rangeStart < 0 || rangeLength <= 0 + || rangeStart + rangeLength > numBytes + || !TkMacOSXSetupDrawingContext(drawable, gc, &drawingContext)) { return; } string = [[TKNSString alloc] initWithTclUtfBytes:source length:numBytes]; @@ -1226,9 +1224,9 @@ TkpDrawAngledCharsInContext( t = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, height); if (angle != 0.0) { t = CGAffineTransformTranslate( - CGAffineTransformRotate( - CGAffineTransformTranslate(t, textX, textY), angle*PI/180.0), - -textX, -textY); + CGAffineTransformRotate( + CGAffineTransformTranslate(t, textX, textY), angle*PI/180.0), + -textX, -textY); } CGContextConcatCTM(context, t); start = Tcl_NumUtfChars(source, rangeStart);