summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfvogel <fvogelnew1@free.fr>2020-04-19 10:01:26 (GMT)
committerfvogel <fvogelnew1@free.fr>2020-04-19 10:01:26 (GMT)
commit981e941cbfec9cdea31b3bde6666e9a5afc6ea85 (patch)
tree5e9c99bf8f09a6d3b61c3b272d77272902a810af
parenta485a445252972c78b1296013f221f7f838c438b (diff)
downloadtk-981e941cbfec9cdea31b3bde6666e9a5afc6ea85.zip
tk-981e941cbfec9cdea31b3bde6666e9a5afc6ea85.tar.gz
tk-981e941cbfec9cdea31b3bde6666e9a5afc6ea85.tar.bz2
Apply another patch by Christopher Chavez that fixes the jerk of strings on aqua when selecting text (see the ticket). There is no functional change on Windows and Linux in this patch.
-rw-r--r--generic/tkFont.c27
-rw-r--r--generic/tkInt.h4
-rw-r--r--macosx/tkMacOSXFont.c20
-rw-r--r--macosx/tkMacOSXInt.h2
-rw-r--r--unix/tkUnixFont.c32
-rw-r--r--win/tkWinFont.c31
6 files changed, 103 insertions, 13 deletions
diff --git a/generic/tkFont.c b/generic/tkFont.c
index 0ec79a6..3a06719 100644
--- a/generic/tkFont.c
+++ b/generic/tkFont.c
@@ -2304,6 +2304,10 @@ Tk_DrawTextLayout(
* draw from the given text item. A number < 0
* means to draw all characters. */
{
+#if 0
+ /* Use TkDrawAngledTextLayout() implementation */
+ TkDrawAngledTextLayout(display, drawable, gc, layout, x, y, 0.0, firstChar, lastChar);
+#else
TextLayout *layoutPtr = (TextLayout *) layout;
int i, numDisplayChars, drawX;
const char *firstByte, *lastByte;
@@ -2333,8 +2337,14 @@ Tk_DrawTextLayout(
numDisplayChars = lastChar;
}
lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
+#if TK_DRAW_IN_CONTEXT
+ TkpDrawCharsInContext(display, drawable, gc, layoutPtr->tkfont,
+ chunkPtr->start, chunkPtr->numBytes, firstChar,
+ numDisplayChars - firstChar, x+chunkPtr->x, y+chunkPtr->y);
+#else /* !TK_DRAW_IN_CONTEXT */
Tk_DrawChars(display, drawable, gc, layoutPtr->tkfont, firstByte,
lastByte - firstByte, x+chunkPtr->x+drawX, y+chunkPtr->y);
+#endif /* TK_DRAW_IN_CONTEXT */
}
firstChar -= chunkPtr->numChars;
lastChar -= chunkPtr->numChars;
@@ -2343,6 +2353,7 @@ Tk_DrawTextLayout(
}
chunkPtr++;
}
+#endif /* Use TkDrawAngledTextLayout() implementation */
}
void
@@ -2395,6 +2406,21 @@ TkDrawAngledTextLayout(
numDisplayChars = lastChar;
}
lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
+#if TK_DRAW_IN_CONTEXT
+ dx = cosA * (chunkPtr->x) + sinA * (chunkPtr->y);
+ dy = -sinA * (chunkPtr->x) + cosA * (chunkPtr->y);
+ if (angle == 0.0) {
+ TkpDrawCharsInContext(display, drawable, gc,
+ layoutPtr->tkfont, chunkPtr->start, chunkPtr->numBytes,
+ firstChar, numDisplayChars - firstChar,
+ (int)(x + dx), (int)(y + dy));
+ } else {
+ TkpDrawAngledCharsInContext(display, drawable, gc,
+ layoutPtr->tkfont, chunkPtr->start, chunkPtr->numBytes,
+ firstChar, numDisplayChars - firstChar,
+ x+dx, y+dy, angle);
+ }
+#else /* !TK_DRAW_IN_CONTEXT */
dx = cosA * (chunkPtr->x + drawX) + sinA * (chunkPtr->y);
dy = -sinA * (chunkPtr->x + drawX) + cosA * (chunkPtr->y);
if (angle == 0.0) {
@@ -2405,6 +2431,7 @@ TkDrawAngledTextLayout(
TkDrawAngledChars(display, drawable, gc, layoutPtr->tkfont,
firstByte, lastByte - firstByte, x+dx, y+dy, angle);
}
+#endif /* TK_DRAW_IN_CONTEXT */
}
firstChar -= chunkPtr->numChars;
lastChar -= chunkPtr->numChars;
diff --git a/generic/tkInt.h b/generic/tkInt.h
index 8f958ab..2f9efe8 100644
--- a/generic/tkInt.h
+++ b/generic/tkInt.h
@@ -1231,6 +1231,10 @@ MODULE_SCOPE void TkpDrawCharsInContext(Display * display,
Drawable drawable, GC gc, Tk_Font tkfont,
const char *source, int numBytes, int rangeStart,
int rangeLength, int x, int y);
+MODULE_SCOPE void TkpDrawAngledCharsInContext(Display * display,
+ Drawable drawable, GC gc, Tk_Font tkfont,
+ const char *source, int numBytes, int rangeStart,
+ int rangeLength, double x, double y, double angle);
MODULE_SCOPE int TkpMeasureCharsInContext(Tk_Font tkfont,
const char *source, int numBytes, int rangeStart,
int rangeLength, int maxLength, int flags,
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c
index 2d8168d..01e6d98 100644
--- a/macosx/tkMacOSXFont.c
+++ b/macosx/tkMacOSXFont.c
@@ -93,10 +93,6 @@ static void InitFont(NSFont *nsFont,
static int CreateNamedSystemFont(Tcl_Interp *interp,
Tk_Window tkwin, const char *name,
TkFontAttributes *faPtr);
-static void DrawCharsInContext(Display *display, Drawable drawable,
- GC gc, Tk_Font tkfont, const char *source,
- int numBytes, int rangeStart, int rangeLength,
- int x, int y, double angle);
#pragma mark -
#pragma mark Font Helpers:
@@ -1115,7 +1111,7 @@ done:
* Draw a string of characters on the screen.
*
* With ATSUI we need the line context to do this right, so we have the
- * actual implementation in TkpDrawCharsInContext().
+ * actual implementation in TkpDrawAngledCharsInContext().
*
* Results:
* None.
@@ -1144,7 +1140,7 @@ Tk_DrawChars(
int x, int y) /* Coordinates at which to place origin of the
* string when drawing. */
{
- DrawCharsInContext(display, drawable, gc, tkfont, source, numBytes,
+ TkpDrawAngledCharsInContext(display, drawable, gc, tkfont, source, numBytes,
0, numBytes, x, y, 0.0);
}
@@ -1167,7 +1163,7 @@ TkDrawAngledChars(
* string when drawing. */
double angle) /* What angle to put text at, in degrees. */
{
- DrawCharsInContext(display, drawable, gc, tkfont, source, numBytes,
+ TkpDrawAngledCharsInContext(display, drawable, gc, tkfont, source, numBytes,
0, numBytes, x, y, angle);
}
@@ -1212,12 +1208,12 @@ TkpDrawCharsInContext(
* whole (not just the range) string when
* drawing. */
{
- DrawCharsInContext(display, drawable, gc, tkfont, source, numBytes,
+ TkpDrawAngledCharsInContext(display, drawable, gc, tkfont, source, numBytes,
rangeStart, rangeLength, x, y, 0.0);
}
-static void
-DrawCharsInContext(
+void
+TkpDrawAngledCharsInContext(
Display *display, /* Display on which to draw. */
Drawable drawable, /* Window or pixmap in which to draw. */
GC gc, /* Graphics context for drawing characters. */
@@ -1233,10 +1229,10 @@ DrawCharsInContext(
int numBytes, /* Number of bytes in string. */
int rangeStart, /* Index of first byte to draw. */
int rangeLength, /* Length of range to draw in bytes. */
- int x, int y, /* Coordinates at which to place origin of the
+ double x, double y, /* Coordinates at which to place origin of the
* whole (not just the range) string when
* drawing. */
- double angle)
+ double angle) /* What angle to put text at, in degrees. */
{
const MacFont *fontPtr = (const MacFont *) tkfont;
NSString *string;
diff --git a/macosx/tkMacOSXInt.h b/macosx/tkMacOSXInt.h
index 9cb75d2..b6b9cca 100644
--- a/macosx/tkMacOSXInt.h
+++ b/macosx/tkMacOSXInt.h
@@ -180,7 +180,7 @@ MODULE_SCOPE void TkpFreeGCCache(GC gc);
#define TK_MACOSX_HANDLE_EVENT_IMMEDIATELY 1024
/*
- * Defines for tkTextDisp.c
+ * Defines for tkTextDisp.c and tkFont.c
*/
#define TK_LAYOUT_WITH_BASE_CHUNKS 1
diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c
index 6e7b4c3..a1b969e 100644
--- a/unix/tkUnixFont.c
+++ b/unix/tkUnixFont.c
@@ -1413,6 +1413,38 @@ TkpDrawCharsInContext(
rangeLength, x+widthUntilStart, y);
}
+/* UNTESTED */
+void
+TkpDrawAngledCharsInContext(
+ Display *display, /* Display on which to draw. */
+ Drawable drawable, /* Window or pixmap in which to draw. */
+ GC gc, /* Graphics context for drawing characters. */
+ Tk_Font tkfont, /* Font in which characters will be drawn; must
+ * be the same as font used in GC. */
+ const char * source, /* UTF-8 string to be displayed. Need not be
+ * '\0' terminated. All Tk meta-characters
+ * (tabs, control characters, and newlines)
+ * should be stripped out of the string that is
+ * passed to this function. If they are not
+ * stripped out, they will be displayed as
+ * regular printing characters. */
+ int numBytes, /* Number of bytes in string. */
+ int rangeStart, /* Index of first byte to draw. */
+ int rangeLength, /* Length of range to draw in bytes. */
+ double x, double y, /* Coordinates at which to place origin of the
+ * whole (not just the range) string when
+ * drawing. */
+ double angle) /* What angle to put text at, in degrees. */
+{
+ int widthUntilStart;
+
+ (void) numBytes; /*unused*/
+
+ Tk_MeasureChars(tkfont, source, rangeStart, -1, 0, &widthUntilStart);
+ TkDrawAngledChars(display, drawable, gc, tkfont, source + rangeStart,
+ rangeLength, x+widthUntilStart, y, angle);
+}
+
/*
*-------------------------------------------------------------------------
*
diff --git a/win/tkWinFont.c b/win/tkWinFont.c
index cef505a..39abda4 100644
--- a/win/tkWinFont.c
+++ b/win/tkWinFont.c
@@ -1402,6 +1402,37 @@ TkpDrawCharsInContext(
rangeLength, x+widthUntilStart, y);
}
+/* UNTESTED */
+void
+TkpDrawAngledCharsInContext(
+ Display *display, /* Display on which to draw. */
+ Drawable drawable, /* Window or pixmap in which to draw. */
+ GC gc, /* Graphics context for drawing characters. */
+ Tk_Font tkfont, /* Font in which characters will be drawn; must
+ * be the same as font used in GC. */
+ const char * source, /* UTF-8 string to be displayed. Need not be
+ * '\0' terminated. All Tk meta-characters
+ * (tabs, control characters, and newlines)
+ * should be stripped out of the string that is
+ * passed to this function. If they are not
+ * stripped out, they will be displayed as
+ * regular printing characters. */
+ int numBytes, /* Number of bytes in string. */
+ int rangeStart, /* Index of first byte to draw. */
+ int rangeLength, /* Length of range to draw in bytes. */
+ double x, double y, /* Coordinates at which to place origin of the
+ * whole (not just the range) string when
+ * drawing. */
+ double angle) /* What angle to put text at, in degrees. */
+{
+ int widthUntilStart;
+ (void) numBytes; /*unused*/
+
+ Tk_MeasureChars(tkfont, source, rangeStart, -1, 0, &widthUntilStart);
+ TkDrawAngledChars(display, drawable, gc, tkfont, source + rangeStart,
+ rangeLength, x+widthUntilStart, y, angle);
+}
+
/*
*-------------------------------------------------------------------------
*