Skip to content

Commit

Permalink
Make a start with [442208915d]: text widget breaks graphemes with com…
Browse files Browse the repository at this point in the history
…bining diacritical marks
  • Loading branch information
jan.nijtmans committed Nov 14, 2024
1 parent f01cc2b commit 51e418c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
7 changes: 2 additions & 5 deletions generic/tkFont.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

#include "tkInt.h"
#include "tkFont.h"
#if defined(MAC_OSX_TK)
#include "tkMacOSXInt.h" /* Defines TK_DRAW_IN_CONTEXT */
#endif

#ifdef _WIN32
#include "tkWinInt.h"
Expand Down Expand Up @@ -2341,7 +2338,7 @@ Tk_DrawTextLayout(
numDisplayChars = lastChar;
}
lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
#ifdef TK_DRAW_IN_CONTEXT
#if 1 /* TK_DRAW_IN_CONTEXT */
TkpDrawCharsInContext(display, drawable, gc, layoutPtr->tkfont,
chunkPtr->start, chunkPtr->numBytes,
firstByte - chunkPtr->start, lastByte - firstByte,
Expand Down Expand Up @@ -2411,7 +2408,7 @@ TkDrawAngledTextLayout(
numDisplayChars = lastChar;
}
lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
#ifdef TK_DRAW_IN_CONTEXT
#if 1 /* TK_DRAW_IN_CONTEXT */
dx = cosA * (chunkPtr->x) + sinA * (chunkPtr->y);
dy = -sinA * (chunkPtr->x) + cosA * (chunkPtr->y);
if (angle == 0.0) {
Expand Down
48 changes: 24 additions & 24 deletions generic/tkTextDisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ typedef struct TextDInfo {
* points to one of the following structures:
*/

#ifndef TK_LAYOUT_WITH_BASE_CHUNKS
#if 0 /* TK_LAYOUT_WITH_BASE_CHUNKS */

typedef struct CharInfo {
Tcl_Size numBytes; /* Number of bytes to display. */
Expand Down Expand Up @@ -541,7 +541,7 @@ static void CharDisplayProc(TkText *textPtr,
static Tcl_Size CharMeasureProc(TkTextDispChunk *chunkPtr, int x);
static void CharUndisplayProc(TkText *textPtr,
TkTextDispChunk *chunkPtr);
#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if 1 /* TK_LAYOUT_WITH_BASE_CHUNKS */
static void FinalizeBaseChunk(TkTextDispChunk *additionalChunkPtr);
static void FreeBaseChunk(TkTextDispChunk *baseChunkPtr);
static int IsSameFGStyle(TextStyle *style1, TextStyle *style2);
Expand Down Expand Up @@ -1500,7 +1500,7 @@ LayoutDLine(
}
}

#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if 1 /* TK_LAYOUT_WITH_BASE_CHUNKS */
if (baseCharChunkPtr != NULL) {
int expectedX =
((BaseCharInfo *) baseCharChunkPtr->clientData)->width
Expand Down Expand Up @@ -1642,7 +1642,7 @@ LayoutDLine(

chunkPtr = NULL;
}
#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if 1 /* TK_LAYOUT_WITH_BASE_CHUNKS */
FinalizeBaseChunk(NULL);
#endif /* TK_LAYOUT_WITH_BASE_CHUNKS */
if (noCharsYet) {
Expand Down Expand Up @@ -1701,7 +1701,7 @@ LayoutDLine(
segPtr->typePtr->layoutProc(textPtr, &breakIndex, segPtr,
byteOffset, maxX, breakByteOffset, 0, wrapMode,
breakChunkPtr);
#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if 1 /* TK_LAYOUT_WITH_BASE_CHUNKS */
FinalizeBaseChunk(NULL);
#endif /* TK_LAYOUT_WITH_BASE_CHUNKS */
}
Expand Down Expand Up @@ -7638,7 +7638,7 @@ TkTextCharLayoutProc(
char *p;
TkTextSegment *nextPtr;
Tk_FontMetrics fm;
#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if 1 /* TK_LAYOUT_WITH_BASE_CHUNKS */
const char *line;
int lineOffset;
BaseCharInfo *bciPtr;
Expand All @@ -7663,7 +7663,7 @@ TkTextCharLayoutProc(
p = segPtr->body.chars + byteOffset;
tkfont = chunkPtr->stylePtr->sValuePtr->tkfont;

#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if 1 /* TK_LAYOUT_WITH_BASE_CHUNKS */
if (baseCharChunkPtr == NULL) {
baseCharChunkPtr = chunkPtr;
bciPtr = (BaseCharInfo *)ckalloc(sizeof(BaseCharInfo));
Expand Down Expand Up @@ -7700,7 +7700,7 @@ TkTextCharLayoutProc(
int ch;
int chLen = Tcl_UtfToUniChar(p, &ch);

#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if 1 /* TK_LAYOUT_WITH_BASE_CHUNKS */
bytesThatFit = CharChunkMeasureChars(chunkPtr, line,
lineOffset+chLen, lineOffset, -1, chunkPtr->x, -1, 0,
&nextX);
Expand Down Expand Up @@ -7744,7 +7744,7 @@ TkTextCharLayoutProc(
bytesThatFit++;
}
if (bytesThatFit == 0) {
#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if 1 /* TK_LAYOUT_WITH_BASE_CHUNKS */
chunkPtr->clientData = NULL;
if (chunkPtr == baseCharChunkPtr) {
baseCharChunkPtr = NULL;
Expand Down Expand Up @@ -7777,7 +7777,7 @@ TkTextCharLayoutProc(
chunkPtr->width = nextX - chunkPtr->x;
chunkPtr->breakIndex = -1;

#ifndef TK_LAYOUT_WITH_BASE_CHUNKS
#if 0 /* TK_LAYOUT_WITH_BASE_CHUNKS */
ciPtr = (CharInfo *)ckalloc(offsetof(CharInfo, chars) + 1 + bytesThatFit);
chunkPtr->clientData = ciPtr;
memcpy(ciPtr->chars, p, bytesThatFit);
Expand All @@ -7788,7 +7788,7 @@ TkTextCharLayoutProc(
ciPtr->numBytes--;
}

#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if 1 /* TK_LAYOUT_WITH_BASE_CHUNKS */
/*
* Final update for the current base chunk data.
*/
Expand Down Expand Up @@ -7893,7 +7893,7 @@ CharChunkMeasureChars(
Tk_Font tkfont = chunkPtr->stylePtr->sValuePtr->tkfont;
CharInfo *ciPtr = (CharInfo *)chunkPtr->clientData;

#ifndef TK_LAYOUT_WITH_BASE_CHUNKS
#if 0 /* TK_LAYOUT_WITH_BASE_CHUNKS */
if (chars == NULL) {
chars = ciPtr->chars;
charsLen = ciPtr->numBytes;
Expand Down Expand Up @@ -7986,7 +7986,7 @@ CharDisplayProc(
StyleValues *sValuePtr;
Tcl_Size numBytes, offsetBytes;
int offsetX;
#ifdef TK_DRAW_IN_CONTEXT
#if 1 /* TK_DRAW_IN_CONTEXT */
BaseCharInfo *bciPtr;
#endif /* TK_DRAW_IN_CONTEXT */

Expand All @@ -7998,7 +7998,7 @@ CharDisplayProc(
return;
}

#ifdef TK_DRAW_IN_CONTEXT
#if 1 /* TK_DRAW_IN_CONTEXT */
bciPtr = (BaseCharInfo *)ciPtr->baseChunkPtr->clientData;
numBytes = Tcl_DStringLength(&bciPtr->baseChars);
string = Tcl_DStringValue(&bciPtr->baseChars);
Expand Down Expand Up @@ -8044,7 +8044,7 @@ CharDisplayProc(

if (!sValuePtr->elide && (numBytes > offsetBytes)
&& (stylePtr->fgGC != NULL)) {
#ifdef TK_DRAW_IN_CONTEXT
#if 1 /* TK_DRAW_IN_CONTEXT */
int start = ciPtr->baseOffset + offsetBytes;
int len = ciPtr->numBytes - offsetBytes;
int xDisplacement = x - chunkPtr->x;
Expand Down Expand Up @@ -8135,7 +8135,7 @@ CharUndisplayProc(
CharInfo *ciPtr = (CharInfo *)chunkPtr->clientData;

if (ciPtr) {
#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if 1 /* TK_LAYOUT_WITH_BASE_CHUNKS */
if (chunkPtr == ciPtr->baseChunkPtr) {
/*
* Basechunks are undisplayed first, when DLines are freed or
Expand Down Expand Up @@ -8717,7 +8717,7 @@ MeasureChars(
if ((maxX >= 0) && (curX >= maxX)) {
break;
}
#ifdef TK_DRAW_IN_CONTEXT
#if 1 /* TK_DRAW_IN_CONTEXT */
start += TkpMeasureCharsInContext(tkfont, source, maxBytes,
start - source, special - start,
maxX >= 0 ? maxX - curX : -1, flags, &width);
Expand Down Expand Up @@ -8858,7 +8858,7 @@ TextGetScrollInfoObj(
return TKTEXT_SCROLL_ERROR;
}

#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if 1 /* TK_LAYOUT_WITH_BASE_CHUNKS */
/*
*----------------------------------------------------------------------
*
Expand Down Expand Up @@ -8889,7 +8889,7 @@ FinalizeBaseChunk(
const char *baseChars;
TkTextDispChunk *chunkPtr;
CharInfo *ciPtr;
#ifdef TK_DRAW_IN_CONTEXT
#if 1 /* TK_DRAW_IN_CONTEXT */
int widthAdjust = 0;
int newwidth;
#endif /* TK_DRAW_IN_CONTEXT */
Expand All @@ -8903,7 +8903,7 @@ FinalizeBaseChunk(

for (chunkPtr = baseCharChunkPtr; chunkPtr != NULL;
chunkPtr = chunkPtr->nextPtr) {
#ifdef TK_DRAW_IN_CONTEXT
#if 1 /* TK_DRAW_IN_CONTEXT */
chunkPtr->x += widthAdjust;
#endif /* TK_DRAW_IN_CONTEXT */

Expand All @@ -8916,7 +8916,7 @@ FinalizeBaseChunk(
}
ciPtr->chars = baseChars + ciPtr->baseOffset;

#ifdef TK_DRAW_IN_CONTEXT
#if 1 /* TK_DRAW_IN_CONTEXT */
newwidth = 0;
CharChunkMeasureChars(chunkPtr, NULL, 0, 0, -1, 0, -1, 0, &newwidth);
if (newwidth < chunkPtr->width) {
Expand All @@ -8930,7 +8930,7 @@ FinalizeBaseChunk(
ciPtr = (CharInfo *)addChunkPtr->clientData;
ciPtr->chars = baseChars + ciPtr->baseOffset;

#ifdef TK_DRAW_IN_CONTEXT
#if 1 /* TK_DRAW_IN_CONTEXT */
addChunkPtr->x += widthAdjust;
CharChunkMeasureChars(addChunkPtr, NULL, 0, 0, -1, 0, -1, 0,
&addChunkPtr->width);
Expand Down Expand Up @@ -9028,7 +9028,7 @@ IsSameFGStyle(
return 1;
}

#ifndef TK_DRAW_IN_CONTEXT
#if 0 /* TK_DRAW_IN_CONTEXT */
if (
#ifdef MAC_OSX_TK
!TkMacOSXCompareColors(style1->fgGC->foreground,
Expand All @@ -9044,7 +9044,7 @@ IsSameFGStyle(
sv1 = style1->sValuePtr;
sv2 = style2->sValuePtr;

#ifdef TK_DRAW_IN_CONTEXT
#if 1 /* TK_DRAW_IN_CONTEXT */
return sv1->tkfont == sv2->tkfont && sv1->offset == sv2->offset;
#else
return sv1->tkfont == sv2->tkfont
Expand Down

0 comments on commit 51e418c

Please sign in to comment.