summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-06-01 19:22:51 +0300
committerTom Rini <trini@konsulko.com>2023-07-14 19:54:51 +0300
commit50f02037594563dbc8da67f65959499bc1f5a46a (patch)
treead16c168054c42f31b5b8f03fd7ca8e173a74a82
parentce72c9ec260d18cc127c275daf3ec1d18c230e2a (diff)
downloadu-boot-50f02037594563dbc8da67f65959499bc1f5a46a.tar.xz
expo: Calculate text bounding-box correctly
Rather than estimating, measure the text accurately, using the new vidconsole feature. This allows accurate placement of objects. Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--boot/scene.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/boot/scene.c b/boot/scene.c
index dd1472d4f9..981a18b3ba 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -257,16 +257,30 @@ int scene_obj_get_hw(struct scene *scn, uint id, int *widthp)
case SCENEOBJT_TEXT: {
struct scene_obj_txt *txt = (struct scene_obj_txt *)obj;
struct expo *exp = scn->expo;
+ struct vidconsole_bbox bbox;
+ const char *str;
+ int len, ret;
+ str = expo_get_str(exp, txt->str_id);
+ if (!str)
+ return log_msg_ret("str", -ENOENT);
+ len = strlen(str);
+
+ /* if there is no console, make it up */
+ if (!exp->cons) {
+ if (widthp)
+ *widthp = 8 * len;
+ return 16;
+ }
+
+ ret = vidconsole_measure(scn->expo->cons, txt->font_name,
+ txt->font_size, str, &bbox);
+ if (ret)
+ return log_msg_ret("mea", ret);
if (widthp)
- *widthp = 16; /* fake value for now */
- if (txt->font_size)
- return txt->font_size;
- if (exp->display)
- return video_default_font_height(exp->display);
-
- /* use a sensible default */
- return 16;
+ *widthp = bbox.x1;
+
+ return bbox.y1;
}
}