]> git.neil.brown.name Git - edlib.git/commitdiff
lib-renderline: discard cached-size attribute
authorNeilBrown <neil@brown.name>
Sun, 20 Aug 2023 10:00:33 +0000 (20:00 +1000)
committerNeilBrown <neil@brown.name>
Mon, 21 Aug 2023 12:27:41 +0000 (22:27 +1000)
We don't need an attribute for this, just store it in rline_data.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/Developer/06-rendering.md
DOC/TODO.md
lib-renderline.c

index 17023d613c99cf74468714af69daaf472bf70b0a..657099afbbae8536448cd2b89cffdffa7d65d722 100644 (file)
@@ -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
index 54550ef56040db60f985216ecfe489576bbce02c..b51d4463020e307601152cff76c276cb9ecd389c 100644 (file)
@@ -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
index 68548a883cb97a924c5a0a7736e49ed9fc2cbe9f..497695bcfc0c700d4c60ee77ccd298dda5d585b8 100644 (file)
@@ -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;