diff options
-rw-r--r-- | src/bltGrText.C | 316 | ||||
-rw-r--r-- | src/bltGrText.h | 3 |
2 files changed, 0 insertions, 319 deletions
diff --git a/src/bltGrText.C b/src/bltGrText.C index 271e83b..0b7582c 100644 --- a/src/bltGrText.C +++ b/src/bltGrText.C @@ -1347,322 +1347,6 @@ NewChunk(TkTextLayout **layoutPtrPtr, int *maxPtr, const char *start, return chunkPtr; } -/* - *--------------------------------------------------------------------------- - * - * Blt_ComputeTextLayout -- - * - * Computes the amount of screen space needed to display a multi-line, - * justified string of text. Records all the measurements that were done - * to determine to size and positioning of the individual lines of text; - * this information can be used by the Tk_DrawTextLayout() procedure to - * display the text quickly (without remeasuring it). - * - * This procedure is useful for simple widgets that want to display - * single-font, multi-line text and want Tk to handle the details. - * - * Results: - * The return value is a Tk_TextLayout token that holds the measurement - * information for the given string. The token is only valid for the - * given string. If the string is freed, the token is no longer valid - * and must also be freed. To free the token, call Tk_FreeTextLayout(). - * - * The dimensions of the screen area needed to display the text are - * stored in *widthPtr and *heightPtr. - * - * Side effects: - * Memory is allocated to hold the measurement information. - * - *--------------------------------------------------------------------------- - */ - -Tk_TextLayout -Blt_ComputeTextLayout( - Blt_Font font, /* Font that will be used to display text. */ - const char *string, /* String whose dimensions are to be - * computed. */ - int numChars, /* Number of characters to consider from - * string, or < 0 for strlen(). */ - int wrapLength, /* Longest permissible line length, in - * pixels. <= 0 means no automatic wrapping: - * just let lines get as long as needed. */ - Tk_Justify justify, /* How to justify lines. */ - int flags, /* Flag bits OR-ed together. - * TK_IGNORE_TABS means that tab characters - * should not be expanded. TK_IGNORE_NEWLINES - * means that newline characters should not - * cause a line break. */ - int *widthPtr, /* Filled with width of string. */ - int *heightPtr) /* Filled with height of string. */ -{ - const char *start, *end, *special; - int n, y, bytesThisChunk, maxChunks; - int baseline, height, curX, newX, maxWidth; - TkTextLayout *layoutPtr; - LayoutChunk *chunkPtr; - Blt_FontMetrics fm; - Tcl_DString lineBuffer; - int *lineLengths; - int curLine, layoutHeight; - - Tcl_DStringInit(&lineBuffer); - - if ((font == NULL) || (string == NULL)) { - if (widthPtr != NULL) { - *widthPtr = 0; - } - if (heightPtr != NULL) { - *heightPtr = 0; - } - return NULL; - } - - Blt_GetFontMetrics(font, &fm); - height = fm.ascent + fm.descent; - - if (numChars < 0) { - numChars = Tcl_NumUtfChars(string, -1); - } - if (wrapLength == 0) { - wrapLength = -1; - } - - maxChunks = 1; - - layoutPtr = malloc(sizeof(TkTextLayout) + (maxChunks - 1) * - sizeof(LayoutChunk)); - layoutPtr->font = font; - layoutPtr->string = string; - layoutPtr->numChunks = 0; - - baseline = fm.ascent; - maxWidth = 0; - - /* - * Divide the string up into simple strings and measure each string. - */ - - curX = 0; - - end = 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; ) { - if (start >= special) { - /* - * Find the next special character in the string. - * - * INTL: Note that it is safe to increment by byte, because we are - * looking for 7-bit characters that will appear unchanged in - * UTF-8. At some point we may need to support the full Unicode - * whitespace set. - */ - - for (special = start; special < end; special++) { - if (!(flags & TK_IGNORE_NEWLINES)) { - if ((*special == '\n') || (*special == '\r')) { - break; - } - } - if (!(flags & TK_IGNORE_TABS)) { - if (*special == '\t') { - break; - } - } - } - } - - /* - * Special points at the next special character (or the end of the - * string). Process characters between start and special. - */ - - chunkPtr = NULL; - if (start < special) { - bytesThisChunk = Blt_MeasureChars(font, start, special - start, - wrapLength - curX, flags, &newX); - newX += curX; - flags &= ~TK_AT_LEAST_ONE; - if (bytesThisChunk > 0) { - chunkPtr = NewChunk(&layoutPtr, &maxChunks, start, - bytesThisChunk, curX, newX, baseline); - - start += bytesThisChunk; - curX = newX; - } - } - - if ((start == special) && (special < end)) { - /* - * Handle the special character. - * - * INTL: Special will be pointing at a 7-bit character so we - * can safely treat it as a single byte. - */ - - chunkPtr = NULL; - if (*special == '\t') { - newX = curX + fm.tabWidth; - newX -= newX % fm.tabWidth; - NewChunk(&layoutPtr, &maxChunks, start, 1, curX, newX, - baseline)->numDisplayChars = -1; - start++; - if ((start < end) && - ((wrapLength <= 0) || (newX <= wrapLength))) { - /* - * More chars can still fit on this line. - */ - - curX = newX; - flags &= ~TK_AT_LEAST_ONE; - continue; - } - } else { - NewChunk(&layoutPtr, &maxChunks, start, 1, curX, curX, - baseline)->numDisplayChars = -1; - start++; - goto wrapLine; - } - } - - /* - * No more characters are going to go on this line, either because - * no more characters can fit or there are no more characters left. - * Consume all extra spaces at end of line. - */ - - while ((start < end) && isspace((unsigned char)(*start))) { /* INTL: ISO space */ - if (!(flags & TK_IGNORE_NEWLINES)) { - if ((*start == '\n') || (*start == '\r')) { - break; - } - } - if (!(flags & TK_IGNORE_TABS)) { - if (*start == '\t') { - break; - } - } - start++; - } - if (chunkPtr != NULL) { - const char *end; - - /* - * Append all the extra spaces on this line to the end of the - * last text chunk. This is a little tricky because we are - * switching back and forth between characters and bytes. - */ - - end = chunkPtr->start + chunkPtr->numBytes; - bytesThisChunk = start - end; - if (bytesThisChunk > 0) { - bytesThisChunk = Blt_MeasureChars(font, end, bytesThisChunk, - -1, 0, &chunkPtr->totalWidth); - chunkPtr->numBytes += bytesThisChunk; - chunkPtr->numChars += Tcl_NumUtfChars(end, bytesThisChunk); - chunkPtr->totalWidth += curX; - } - } - - wrapLine: - flags |= TK_AT_LEAST_ONE; - - /* - * Save current line length, then move current position to start of - * next line. - */ - - if (curX > maxWidth) { - maxWidth = curX; - } - - /* - * Remember width of this line, so that all chunks on this line - * can be centered or right justified, if necessary. - */ - - Tcl_DStringAppend(&lineBuffer, (char *) &curX, sizeof(curX)); - - curX = 0; - baseline += height; - } - - /* - * If last line ends with a newline, then we need to make a 0 width - * chunk on the next line. Otherwise "Hello" and "Hello\n" are the - * same height. - */ - - if ((layoutPtr->numChunks > 0) && ((flags & TK_IGNORE_NEWLINES) == 0)) { - if (layoutPtr->chunks[layoutPtr->numChunks - 1].start[0] == '\n') { - chunkPtr = NewChunk(&layoutPtr, &maxChunks, start, 0, curX, - curX, baseline); - chunkPtr->numDisplayChars = -1; - Tcl_DStringAppend(&lineBuffer, (char *) &curX, sizeof(curX)); - baseline += height; - } - } - - layoutPtr->width = maxWidth; - layoutHeight = baseline - fm.ascent; - if (layoutPtr->numChunks == 0) { - layoutHeight = height; - - /* - * This fake chunk is used by the other procedures so that they can - * pretend that there is a chunk with no chars in it, which makes - * the coding simpler. - */ - - layoutPtr->numChunks = 1; - layoutPtr->chunks[0].start = string; - layoutPtr->chunks[0].numBytes = 0; - layoutPtr->chunks[0].numChars = 0; - layoutPtr->chunks[0].numDisplayChars = -1; - layoutPtr->chunks[0].x = 0; - layoutPtr->chunks[0].y = fm.ascent; - layoutPtr->chunks[0].totalWidth = 0; - layoutPtr->chunks[0].displayWidth = 0; - } else { - /* - * Using maximum line length, shift all the chunks so that the lines - * are all justified correctly. - */ - - curLine = 0; - chunkPtr = layoutPtr->chunks; - y = chunkPtr->y; - lineLengths = (int *) Tcl_DStringValue(&lineBuffer); - for (n = 0; n < layoutPtr->numChunks; n++) { - int extra; - - if (chunkPtr->y != y) { - curLine++; - y = chunkPtr->y; - } - extra = maxWidth - lineLengths[curLine]; - if (justify == TK_JUSTIFY_CENTER) { - chunkPtr->x += extra / 2; - } else if (justify == TK_JUSTIFY_RIGHT) { - chunkPtr->x += extra; - } - chunkPtr++; - } - } - - if (widthPtr != NULL) { - *widthPtr = layoutPtr->width; - } - if (heightPtr != NULL) { - *heightPtr = layoutHeight; - } - Tcl_DStringFree(&lineBuffer); - - return (Tk_TextLayout) layoutPtr; -} - void Blt_DrawTextLayout( Display *display, /* Display on which to draw. */ diff --git a/src/bltGrText.h b/src/bltGrText.h index 935b5e0..dbf2516 100644 --- a/src/bltGrText.h +++ b/src/bltGrText.h @@ -208,9 +208,6 @@ extern int Blt_CharBbox(Tk_TextLayout layout, int index, int *xPtr, extern void Blt_UnderlineTextLayout(Display *display, Drawable drawable, GC gc, Tk_TextLayout layout, int x, int y, int underline); -extern void Blt_Ts_UnderlineLayout(Tk_Window tkwin, Drawable drawable, - TextLayout *layoutPtr, TextStyle *tsPtr, int x, int y); - extern void Blt_Ts_DrawText(Tk_Window tkwin, Drawable drawable, const char *text, int textLen, TextStyle *tsPtr, int x, int y); |