Attachment "7655f65ae7-drawtextincontext.diff" to
ticket [7655f65a]
added by
chrstphrchvz
2020-04-16 03:22:52.
diff --git generic/tkFont.c generic/tkFont.c
index 0ec79a67a..3a067197f 100644
--- generic/tkFont.c
+++ 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 generic/tkInt.h generic/tkInt.h
index 8f958abad..2f9efe896 100644
--- generic/tkInt.h
+++ 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 macosx/tkMacOSXFont.c macosx/tkMacOSXFont.c
index a91cbe44c..28b1c1bba 100644
--- macosx/tkMacOSXFont.c
+++ 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 macosx/tkMacOSXInt.h macosx/tkMacOSXInt.h
index 9cb75d2ba..b6b9ccaee 100644
--- macosx/tkMacOSXInt.h
+++ 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 unix/tkUnixFont.c unix/tkUnixFont.c
index 6e7b4c325..a1b969e9a 100644
--- unix/tkUnixFont.c
+++ 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 win/tkWinFont.c win/tkWinFont.c
index cef505a91..39abda412 100644
--- win/tkWinFont.c
+++ 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);
+}
+
/*
*-------------------------------------------------------------------------
*