Fix display of link hint

The link hint was truncated when the link rectangle was too small to
contain in. With this commit the link hint area is also redrawn.
This commit is contained in:
Jeremie Knuesel 2018-01-26 14:05:19 +01:00
parent bab38fc636
commit 76e5f7dc7a

View file

@ -340,12 +340,47 @@ set_font_from_property(cairo_t* cairo, zathura_t* zathura, cairo_font_weight_t w
g_free(font); g_free(font);
} }
static cairo_text_extents_t
get_text_extents(const char* string, zathura_t* zathura, cairo_font_weight_t weight) {
cairo_text_extents_t text = {0,};
if (zathura == NULL) {
return text;
}
/* make dummy surface to satisfy API requirements */
cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, 0, 0);
if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
return text;
}
cairo_t* cairo = cairo_create(surface);
if (cairo_status(cairo) != CAIRO_STATUS_SUCCESS) {
cairo_surface_destroy(surface);
return text;
}
set_font_from_property(cairo, zathura, weight);
cairo_text_extents(cairo, string, &text);
/* add some margin (for some reason the reported extents can be a bit short) */
text.width += 6;
text.height += 2;
cairo_destroy(cairo);
cairo_surface_destroy(surface);
return text;
}
static void static void
zathura_page_widget_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec) zathura_page_widget_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
{ {
ZathuraPage* pageview = ZATHURA_PAGE(object); ZathuraPage* pageview = ZATHURA_PAGE(object);
zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(pageview); zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(pageview);
cairo_text_extents_t text;
switch (prop_id) { switch (prop_id) {
case PROP_PAGE: case PROP_PAGE:
priv->page = g_value_get_pointer(value); priv->page = g_value_get_pointer(value);
@ -363,10 +398,19 @@ zathura_page_widget_set_property(GObject* object, guint prop_id, const GValue* v
} }
if (priv->links.retrieved == TRUE && priv->links.list != NULL) { if (priv->links.retrieved == TRUE && priv->links.list != NULL) {
/* get size of text that should be large enough for every link hint */
text = get_text_extents("888", priv->zathura, CAIRO_FONT_WEIGHT_BOLD);
GIRARA_LIST_FOREACH(priv->links.list, zathura_link_t*, iter, link) GIRARA_LIST_FOREACH(priv->links.list, zathura_link_t*, iter, link)
if (link != NULL) { if (link != NULL) {
/* redraw link area */
zathura_rectangle_t rectangle = recalc_rectangle(priv->page, zathura_link_get_position(link)); zathura_rectangle_t rectangle = recalc_rectangle(priv->page, zathura_link_get_position(link));
redraw_rect(pageview, &rectangle); redraw_rect(pageview, &rectangle);
/* also redraw area for link hint */
rectangle.x2 = rectangle.x1 + text.width;
rectangle.y1 = rectangle.y2 - text.height;
redraw_rect(pageview, &rectangle);
} }
GIRARA_LIST_FOREACH_END(priv->links.list, zathura_link_t*, iter, link); GIRARA_LIST_FOREACH_END(priv->links.list, zathura_link_t*, iter, link);
} }