AmendHub

Download (as of this amendment):

jcs

/

textview

/

amendments

/

61

TVCalcLinesLocked: When a style starts on a new line, don't inherit

A big size line with a newline, followed by a line of text with a
small size font shouldn't be as tall as the big size.

jcs made amendment 61 about 1 year ago
--- textview.c Wed Dec 18 21:28:09 2024 +++ textview.c Thu Dec 19 09:56:03 2024 @@ -1458,6 +1458,7 @@ reload_chunk: TVApplyStyle(style); if (chunk->end_line == 0) { + /* working with a new text chunk */ if (chunk->prev_chunk == 0) { prev_chunk = NULL; chunk->start_left = tv->padding.left; @@ -1481,6 +1482,7 @@ reload_chunk: return false; text_slab_data = text_slab->data; + /* find our current line */ nline = chunk->end_line; line = TVGetLine(tv, nline); if (line == NULL) @@ -1502,8 +1504,13 @@ reload_chunk: } line->nline = nline; - height = style->font_info.ascent + style->font_info.descent; + height = style->font_info.ascent + style->font_info.descent + + style->font_info.leading; + /* + * Walk each character and find its width, possibly wrapping and + * starting a new line. + */ for (n = start; n < chunk->end; n++) { c = text_slab_data[n - text_slab->base]; @@ -1577,7 +1584,7 @@ reload_chunk: chunk->end_right = chunk->start_left; chunk->start_line++; } else if (height > line->rect.bottom - line->rect.top) - line->rect.bottom = line->rect.bottom + height; + line->rect.bottom = line->rect.top + height; nline++; chunk->end_line = nline; @@ -1602,25 +1609,30 @@ reload_chunk: chunk->end_right += width; - if (style->font_info.descent > line->baseline) { - if (line->baseline && line->start != line->end) - line->grew = true; + if (line->start == line->end) { + /* start of new line disregards previous line's style */ line->baseline = style->font_info.descent; - height = style->font_info.ascent + style->font_info.descent; - } - if (style->font_info.leading > line->leading && - line->start != line->end) { - if (line->leading) - line->grew = true; line->leading = style->font_info.leading; - } - if (line->rect.bottom == 0 || - (line->rect.bottom - line->rect.top < height && - line->start != line->end)) { - if (line->rect.bottom != line->rect.top && - line->rect.bottom != 0) - line->grew = true; - line->rect.bottom = line->rect.top + height; + line->rect.bottom = line->rect.top + height + line->leading; + } else { + /* but if style changes mid-line, previous chunks grow */ + if (style->font_info.descent > line->baseline) { + if (line->baseline) + line->grew = true; + line->baseline = style->font_info.descent; + } + if (style->font_info.leading > line->leading) { + if (line->leading) + line->grew = true; + line->leading = style->font_info.leading; + } + if (line->rect.bottom == 0 || + (line->rect.bottom - line->rect.top < height)) { + if (line->rect.bottom != line->rect.top && + line->rect.bottom != 0) + line->grew = true; + line->rect.bottom = line->rect.top + height; + } } }