summaryrefslogtreecommitdiffstats
path: root/generic/tkFont.c
diff options
context:
space:
mode:
authorculler <culler>2020-11-10 13:59:25 (GMT)
committerculler <culler>2020-11-10 13:59:25 (GMT)
commitd94200fdcf927707b43670e7751208ea902b382e (patch)
treec8f724ce055955eef67c4b799866138c5389715d /generic/tkFont.c
parenta49d6e52a72b1f086503ae32cb28b0da62e5fa99 (diff)
parent6133a711414cfb8fcc3a8b52ecf25b59a09e5800 (diff)
downloadtk-d94200fdcf927707b43670e7751208ea902b382e.zip
tk-d94200fdcf927707b43670e7751208ea902b382e.tar.gz
tk-d94200fdcf927707b43670e7751208ea902b382e.tar.bz2
Merge main
Diffstat (limited to 'generic/tkFont.c')
-rw-r--r--generic/tkFont.c129
1 files changed, 103 insertions, 26 deletions
diff --git a/generic/tkFont.c b/generic/tkFont.c
index 34f8921..2788b2e 100644
--- a/generic/tkFont.c
+++ b/generic/tkFont.c
@@ -14,8 +14,9 @@
#include "tkInt.h"
#include "tkFont.h"
#if defined(MAC_OSX_TK)
-#include "tkMacOSXInt.h"
+#include "tkMacOSXInt.h" /* Defines TK_DRAW_IN_CONTEXT */
#endif
+
/*
* The following structure is used to keep track of all the fonts that exist
* in the current application. It must be stored in the TkMainInfo for the
@@ -95,7 +96,7 @@ typedef struct TextLayout {
* layout. */
int numChunks; /* Number of chunks actually used in following
* array. */
- LayoutChunk chunks[1]; /* Array of chunks. The actual size will be
+ LayoutChunk chunks[TKFLEXARRAY];/* Array of chunks. The actual size will be
* maxChunks. THIS FIELD MUST BE THE LAST IN
* THE STRUCTURE. */
} TextLayout;
@@ -555,7 +556,7 @@ Tk_FontObjCmd(
if (objc < 3 || n < objc) {
Tcl_WrongNumArgs(interp, 2, objv,
- "font ?-displayof window? ?option? ?--? ?char?");
+ "font ?-displayof window? ?-option? ?--? ?char?");
return TCL_ERROR;
}
@@ -740,7 +741,7 @@ Tk_FontObjCmd(
}
case FONT_METRICS: {
Tk_Font tkfont;
- int skip, index, i;
+ int skip, i;
const TkFontMetrics *fmPtr;
static const char *const switches[] = {
"-ascent", "-descent", "-linespace", "-fixed", NULL
@@ -752,7 +753,7 @@ Tk_FontObjCmd(
}
if ((objc < 3) || ((objc - skip) > 4)) {
Tcl_WrongNumArgs(interp, 2, objv,
- "font ?-displayof window? ?option?");
+ "font ?-displayof window? ?-option?");
return TCL_ERROR;
}
tkfont = Tk_AllocFontFromObj(interp, tkwin, objv[2]);
@@ -875,18 +876,18 @@ TheWorldHasChanged(
ClientData clientData) /* Info about application's fonts. */
{
TkFontInfo *fiPtr = (TkFontInfo *)clientData;
-#if defined(MAC_OSX_TK)
/*
* On macOS it is catastrophic to recompute all widgets while the
* [NSView drawRect] method is drawing. The best that we can do in
* that situation is to abort the recomputation and hope for the best.
+ * This is ignored on other platforms.
*/
- if (TkpAppIsDrawing()) {
+ if (TkpWillDrawWidget(NULL)) {
return;
}
-#endif
+
fiPtr->updatePending = 0;
RecomputeWidgets(fiPtr->mainPtr->winPtr);
}
@@ -1361,11 +1362,10 @@ Tk_GetFontFromObj(
static int
SetFontFromAny(
- Tcl_Interp *dummy, /* Used for error reporting if not NULL. */
+ TCL_UNUSED(Tcl_Interp *), /* Used for error reporting if not NULL. */
Tcl_Obj *objPtr) /* The object to convert. */
{
const Tcl_ObjType *typePtr;
- (void)dummy;
/*
* Free the old internalRep before setting the new one.
@@ -1968,7 +1968,7 @@ Tk_ComputeTextLayout(
int *heightPtr) /* Filled with height of string. */
{
TkFont *fontPtr = (TkFont *) tkfont;
- const char *start, *end, *special;
+ const char *start, *endp, *special;
int n, y, bytesThisChunk, maxChunks, curLine, layoutHeight;
int baseline, height, curX, newX, maxWidth, *lineLengths;
TextLayout *layoutPtr;
@@ -2001,8 +2001,8 @@ Tk_ComputeTextLayout(
maxChunks = 1;
- layoutPtr = (TextLayout *)ckalloc(sizeof(TextLayout)
- + (maxChunks-1) * sizeof(LayoutChunk));
+ layoutPtr = (TextLayout *)ckalloc(offsetof(TextLayout, chunks)
+ + maxChunks * sizeof(LayoutChunk));
layoutPtr->tkfont = tkfont;
layoutPtr->string = string;
layoutPtr->numChunks = 0;
@@ -2016,12 +2016,12 @@ Tk_ComputeTextLayout(
curX = 0;
- end = Tcl_UtfAtIndex(string, numChars);
+ endp = Tcl_UtfAtIndex(string, numChars);
special = string;
flags &= TK_IGNORE_TABS | TK_IGNORE_NEWLINES;
flags |= TK_WHOLE_WORDS | TK_AT_LEAST_ONE;
- for (start = string; start < end; ) {
+ for (start = string; start < endp; ) {
if (start >= special) {
/*
* Find the next special character in the string.
@@ -2032,7 +2032,7 @@ Tk_ComputeTextLayout(
* whitespace set.
*/
- for (special = start; special < end; special++) {
+ for (special = start; special < endp; special++) {
if (!(flags & TK_IGNORE_NEWLINES)) {
if ((*special == '\n') || (*special == '\r')) {
break;
@@ -2066,7 +2066,7 @@ Tk_ComputeTextLayout(
}
}
- if ((start == special) && (special < end)) {
+ if ((start == special) && (special < endp)) {
/*
* Handle the special character.
*
@@ -2083,7 +2083,7 @@ Tk_ComputeTextLayout(
start++;
curX = newX;
flags &= ~TK_AT_LEAST_ONE;
- if ((start < end) &&
+ if ((start < endp) &&
((wrapLength <= 0) || (newX <= wrapLength))) {
/*
* More chars can still fit on this line.
@@ -2105,7 +2105,7 @@ Tk_ComputeTextLayout(
* Consume all extra spaces at end of line.
*/
- while ((start < end) && isspace(UCHAR(*start))) { /* INTL: ISO space */
+ while ((start < endp) && isspace(UCHAR(*start))) { /* INTL: ISO space */
if (!(flags & TK_IGNORE_NEWLINES)) {
if ((*start == '\n') || (*start == '\r')) {
break;
@@ -2293,12 +2293,16 @@ Tk_DrawTextLayout(
int x, int y, /* Upper-left hand corner of rectangle in
* which to draw (pixels). */
int firstChar, /* The index of the first character to draw
- * from the given text item. 0 specfies the
+ * from the given text item. 0 specifies the
* beginning. */
int lastChar) /* The index just after the last character to
* draw from the given text item. A number < 0
* means to draw all characters. */
{
+#if 0
+ /* Use TkDrawAngledTextLayout() implementation - testing purposes at this point */
+ TkDrawAngledTextLayout(display, drawable, gc, layout, x, y, 0.0, firstChar, lastChar);
+#else
TextLayout *layoutPtr = (TextLayout *) layout;
int i, numDisplayChars, drawX;
const char *firstByte, *lastByte;
@@ -2328,8 +2332,15 @@ Tk_DrawTextLayout(
numDisplayChars = lastChar;
}
lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
+#ifdef TK_DRAW_IN_CONTEXT
+ TkpDrawCharsInContext(display, drawable, gc, layoutPtr->tkfont,
+ chunkPtr->start, chunkPtr->numBytes,
+ firstByte - chunkPtr->start, lastByte - firstByte,
+ 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;
@@ -2338,6 +2349,7 @@ Tk_DrawTextLayout(
}
chunkPtr++;
}
+#endif /* Use TkDrawAngledTextLayout() implementation */
}
void
@@ -2352,7 +2364,7 @@ TkDrawAngledTextLayout(
* which to draw (pixels). */
double angle,
int firstChar, /* The index of the first character to draw
- * from the given text item. 0 specfies the
+ * from the given text item. 0 specifies the
* beginning. */
int lastChar) /* The index just after the last character to
* draw from the given text item. A number < 0
@@ -2390,6 +2402,21 @@ TkDrawAngledTextLayout(
numDisplayChars = lastChar;
}
lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
+#ifdef 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,
+ firstByte - chunkPtr->start, lastByte - firstByte,
+ (int)(x + dx), (int)(y + dy));
+ } else {
+ TkpDrawAngledCharsInContext(display, drawable, gc,
+ layoutPtr->tkfont, chunkPtr->start, chunkPtr->numBytes,
+ firstByte - chunkPtr->start, lastByte - firstByte,
+ 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) {
@@ -2400,6 +2427,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;
@@ -2709,7 +2737,7 @@ Tk_CharBbox(
* index, if non-NULL. */
{
TextLayout *layoutPtr = (TextLayout *) layout;
- LayoutChunk *chunkPtr;
+ LayoutChunk *chunkPtr = layoutPtr->chunks;
int i, x = 0, w;
Tk_Font tkfont;
TkFont *fontPtr;
@@ -2719,7 +2747,6 @@ Tk_CharBbox(
return 0;
}
- chunkPtr = layoutPtr->chunks;
tkfont = layoutPtr->tkfont;
fontPtr = (TkFont *) tkfont;
@@ -3372,7 +3399,7 @@ noMapping: ;
static int
ConfigAttributesObj(
Tcl_Interp *interp, /* Interp for error return. */
- Tk_Window tkwin, /* 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
@@ -3382,7 +3409,6 @@ ConfigAttributesObj(
int i, n, index;
Tcl_Obj *optionPtr, *valuePtr;
const char *value;
- (void)tkwin;
for (i = 0; i < objc; i += 2) {
optionPtr = objv[i];
@@ -3548,6 +3574,57 @@ GetAttributeInfoObj(
/*
*---------------------------------------------------------------------------
*
+ * Tk_FontGetDescription --
+ *
+ * Return information about the font description as a Tcl list. One
+ * possible result is "{{DejaVu Sans} -16 bold underline}".
+ *
+ * Results:
+ * The list of descriptions.
+ *
+ * Side effects:
+ * None.
+ *
+ *---------------------------------------------------------------------------
+ */
+
+Tcl_Obj *
+Tk_FontGetDescription(
+ Tk_Font tkfont) /* Font whose description is desired. */
+{
+ const TkFontAttributes *faPtr = GetFontAttributes(tkfont);
+ Tcl_Obj *resultPtr = Tcl_NewObj();
+ const char *str;
+
+ str = faPtr->family;
+ Tcl_ListObjAppendElement(NULL, resultPtr, Tcl_NewStringObj(str, str ? -1 : 0));
+ if (faPtr->size >= 0.0) {
+ Tcl_ListObjAppendElement(NULL, resultPtr, Tcl_NewWideIntObj((int)(faPtr->size + 0.5)));
+ } else {
+ Tcl_ListObjAppendElement(NULL, resultPtr, Tcl_NewWideIntObj(-(int)(-faPtr->size + 0.5)));
+ }
+ if (faPtr->weight != TK_FW_NORMAL) {
+ str = TkFindStateString(weightMap, faPtr->weight);
+ Tcl_ListObjAppendElement(NULL, resultPtr, Tcl_NewStringObj(str, -1));
+ }
+ if (faPtr->slant != TK_FS_ROMAN) {
+ str = TkFindStateString(slantMap, faPtr->slant);
+ Tcl_ListObjAppendElement(NULL, resultPtr, Tcl_NewStringObj(str, -1));
+ }
+ if (faPtr->underline) {
+ str = TkFindStateString(underlineMap, faPtr->underline);
+ Tcl_ListObjAppendElement(NULL, resultPtr, Tcl_NewStringObj(str, -1));
+ }
+ if (faPtr->overstrike) {
+ str = TkFindStateString(overstrikeMap, faPtr->overstrike);
+ Tcl_ListObjAppendElement(NULL, resultPtr, Tcl_NewStringObj(str, -1));
+ }
+ return resultPtr;
+}
+
+/*
+ *---------------------------------------------------------------------------
+ *
* ParseFontNameObj --
*
* Converts a object into a set of font attributes that can be used to
@@ -3748,7 +3825,7 @@ NewChunk(
maxChunks = *maxPtr;
if (layoutPtr->numChunks == maxChunks) {
maxChunks *= 2;
- s = sizeof(TextLayout) + ((maxChunks - 1) * sizeof(LayoutChunk));
+ s = offsetof(TextLayout, chunks) + (maxChunks * sizeof(LayoutChunk));
layoutPtr = (TextLayout *)ckrealloc(layoutPtr, s);
*layoutPtrPtr = layoutPtr;