From: NeilBrown Date: Sun, 20 Aug 2023 10:00:33 +0000 (+1000) Subject: lib-renderline: discard cached-size attribute X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=caa0b594e0907de0ff4ba30dd7180cdbd9a17d83;p=edlib.git lib-renderline: discard cached-size attribute We don't need an attribute for this, just store it in rline_data. Signed-off-by: NeilBrown --- diff --git a/DOC/Developer/06-rendering.md b/DOC/Developer/06-rendering.md index 17023d61..657099af 100644 --- a/DOC/Developer/06-rendering.md +++ b/DOC/Developer/06-rendering.md @@ -311,9 +311,6 @@ The pane also sets some attributes when handling these messages: the letter "m". - "xyattr" - when "render-line:findxy" is handled, the attributes that were in effect that the found position are made available as "xyattr". -- "cached-size" - when measuring an image with the "noupscale" attribute - this will be set to "width"x"height". This is primarily for internal - use. - "line-height" - when measuring text, this is set to the height of the line. When the line is wrapped this will be an integer submultiple of the resulting pane height. When text is not wrapped it will be diff --git a/DOC/TODO.md b/DOC/TODO.md index 54550ef5..b51d4463 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -39,7 +39,7 @@ the file. following punctuation (=) and try there. - [ ] resolve shift-left vs shift_left distinction - add a "fixed" suffix? - [ ] should zoom affect whole window, not just pane? -- [ ] ditch cached-size for images - store in pane data instead. +- [X] ditch cached-size for images - store in pane data instead. - [ ] use foreach_attr for parsing image details - [ ] mergeview command to show diff between "found" and "replacement". - [ ] mergeview command to include both found and replacement, discard diff --git a/lib-renderline.c b/lib-renderline.c index 68548a88..497695bc 100644 --- a/lib-renderline.c +++ b/lib-renderline.c @@ -133,6 +133,7 @@ struct rline_data { bool image; int curspos; + struct xy image_size; /* These used to check is measuring is needed, or to record * results of last measurement */ unsigned short measure_width, measure_height; @@ -206,8 +207,10 @@ static void parse_line(struct rline_data *rd safe) return; } rd->image = strstarts(line, SOH "image:"); - if (rd->image) + if (rd->image) { + rd->image_size.x = 0; return; + } buf_init(&attr); buf_init(&wrapattr); @@ -992,6 +995,7 @@ static int render_image(struct pane *p safe, struct pane *focus safe, int dodraw, int offset, int want_xypos, short x, short y) { + struct rline_data *rd = &p->data; char *fname = NULL; const char *orig_line = line; short width, height; @@ -1000,7 +1004,6 @@ static int render_image(struct pane *p safe, struct pane *focus safe, int ioffset; struct xy xyscale = pane_scale(focus); int scale = xyscale.x; - char *ssize = attr_find(p->attrs, "cached-size"); struct xy size= {-1, -1}; if (dodraw) @@ -1016,8 +1019,7 @@ static int render_image(struct pane *p safe, struct pane *focus safe, int len = strcspn(line, "," STX ETX); if (strstarts(line, "image:")) { fname = strndup(line+6, len-6); - if (!ssize || - sscanf(ssize, "%hdx%hd", &size.x, &size.y) != 2) { + if (rd->image_size.x <= 0) { struct call_return cr = home_call_ret(all, focus, "Draw:image-size", @@ -1025,12 +1027,10 @@ static int render_image(struct pane *p safe, struct pane *focus safe, if (cr.x > 0 && cr.y > 0) { size.x = cr.x; size.y = cr.y; - asprintf(&ssize, "%hdx%hd", - cr.x, cr.y); - attr_set_str(&p->attrs, - "cached-size", ssize); + rd->image_size = size; } - } + } else + size = rd->image_size; } else if (strstarts(line, "width:")) { width = atoi(line + 6); width = width * scale / 1000;