AmendHub

Download (as of this amendment):

jcs

/

textview

/

amendments

/

50

TVAppendBitMap: Require a TVStyle passed with sizing information

This allows the caller to specify where on the baseline the bitmap
is drawn, and allows it to add spacing after it by setting
font_info.widMax.
 
Also handle lines with multiple styles growing the leading size.

jcs made amendment 50 over 2 years ago
--- textview.c Tue Nov 12 21:38:54 2024 +++ textview.c Wed Nov 13 14:40:08 2024 @@ -168,7 +168,7 @@ TVAppendLine(TVHandle tvh, struct TVStyle *style, char } Boolean -TVAppendBitMap(TVHandle tvh, BitMap *bitmap) +TVAppendBitMap(TVHandle tvh, BitMap *bitmap, struct TVStyle *bstyle) { struct TVRec *tv; struct TVStyle *style; @@ -190,6 +190,15 @@ TVAppendBitMap(TVHandle tvh, BitMap *bitmap) memcpy(style->bitmap_data, bitmap->baseAddr, bitmap_size); style->bitmap.baseAddr = (Ptr)style->bitmap_data; + if (!bstyle) + bstyle = TVGetStyle(tv, tv->cur_style); + if (bstyle) { + style->font = bstyle->font; + style->style = bstyle->style; + style->size = bstyle->size; + style->font_info = bstyle->font_info; + } + tv = TVLock(tvh); ret = TVAppendLocked(tv, style, " ", 1, 0); TVUnlock(tv); @@ -1202,6 +1211,7 @@ create_style: tstyle->style = style->style; tstyle->size = style->size; if (style->bitmap_data_size) { + tstyle->font_info = style->font_info; tstyle->bitmap_data_size = style->bitmap_data_size; tstyle->bitmap = style->bitmap; memcpy(tstyle->bitmap_data, style->bitmap.baseAddr, @@ -1217,7 +1227,8 @@ create_style: } TVApplyStyle(tstyle); - GetFontInfo(&tstyle->font_info); + if (!style->bitmap_data_size || style->font_info.widMax == 0) + GetFontInfo(&tstyle->font_info); tv->cur_style = tstyle->loc; return tstyle; @@ -1453,12 +1464,8 @@ reload_chunk: } line->nline = nline; + height = style->font_info.ascent + style->font_info.descent; - if (style->bitmap_data_size) - height = style->bitmap.bounds.bottom - style->bitmap.bounds.top; - else - height = style->font_info.ascent + style->font_info.descent; - for (n = start; n < chunk->end; n++) { c = text_slab_data[n - text_slab->base]; @@ -1467,8 +1474,7 @@ reload_chunk: width = 0; } else { if (style->bitmap_data_size) - width = style->bitmap.bounds.right - - style->bitmap.bounds.left; + width = style->font_info.widMax; else if (!(width = style->width_cache[c])) width = style->width_cache[c] = CharWidth(c); @@ -1532,8 +1538,8 @@ reload_chunk: next_line->start = n; if (c == '\r') next_line->start++; - next_line->rect.top = line->rect.bottom + - style->font_info.leading; + next_line->leading = style->font_info.leading; + next_line->rect.top = line->rect.bottom; next_line->rect.left = tv->padding.left; next_line->rect.right = chunk->end_right; next_line->rect.bottom = next_line->rect.top; @@ -1545,13 +1551,16 @@ reload_chunk: chunk->end_right += width; - if (!style->bitmap_data_size && - style->font_info.descent > line->baseline) { + if (style->font_info.descent > line->baseline) { if (line->baseline) line->grew = true; line->baseline = style->font_info.descent; height = style->font_info.ascent + style->font_info.descent; } + if (style->font_info.leading > line->leading) { + line->leading = style->font_info.leading; + line->grew = true; + } if (line->rect.bottom - line->rect.top < height) { line->grew = true; line->rect.bottom = line->rect.top + height; @@ -1608,8 +1617,7 @@ TVDrawMatch(struct TVRec *tv, struct TVFindInRectMatch r.left = match->rect.left; r.right = r.left + (match->style->bitmap.bounds.right - match->style->bitmap.bounds.left); - r.bottom = tv->scrolled.top + match->line->rect.bottom - - match->line->baseline; + r.bottom = tv->scrolled.top + match->line->rect.bottom; r.top = r.bottom - (match->style->bitmap.bounds.bottom - match->style->bitmap.bounds.top); --- textview.h Tue Nov 12 20:55:28 2024 +++ textview.h Wed Nov 13 14:33:54 2024 @@ -50,9 +50,9 @@ struct TVStyle { unsigned char font; unsigned char style; unsigned char size; - BitMap bitmap; /* these are private and ignored when fed into TVAppend() */ + BitMap bitmap; struct FontInfo font_info; unsigned char width_cache[256]; TVSlabLocator loc; @@ -80,6 +80,7 @@ struct TVLine { BigRect rect; unsigned long nline; unsigned char baseline; + unsigned short leading; Boolean grew; }; @@ -161,7 +162,8 @@ Boolean TVAppend(TVHandle tvh, struct TVStyle *style, unsigned long length); Boolean TVAppendLine(TVHandle tvh, struct TVStyle *style, char *text, unsigned long length); -Boolean TVAppendBitMap(TVHandle tvh, BitMap *bitmap); +Boolean TVAppendBitMap(TVHandle tvh, BitMap *bitmap, + struct TVStyle *bstyle); void TVAutoCalc(TVHandle tvh, Boolean calc); void TVAutoScroll(TVHandle tvh, Boolean scroll); void TVLineWrap(TVHandle tvh, Boolean wrap);