Skip to content

Commit

Permalink
lstopo/fig: import the generic textsize method code
Browse files Browse the repository at this point in the history
fig was the only backend without a textsize callback.
Move the generic fallback code to the backend so that we can tune it,
and enforce the existence of that method in the core.

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed May 3, 2018
1 parent 2ad4a16 commit ce9e0f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 7 additions & 6 deletions utils/lstopo/lstopo-draw.c
Expand Up @@ -135,12 +135,13 @@ get_textwidth(void *output,
unsigned fontsize)
{
struct lstopo_output *loutput = output;
if (loutput->methods->textsize) {
unsigned width;
loutput->methods->textsize(output, text, length, fontsize, &width);
return width;
}
return (length * fontsize * 3) / 4;
unsigned width;

#ifdef HWLOC_DEBUG
assert(loutput->methods->textsize);
#endif
loutput->methods->textsize(output, text, length, fontsize, &width);
return width;
}

/* preferred width/height compromise */
Expand Down
8 changes: 7 additions & 1 deletion utils/lstopo/lstopo-fig.c
Expand Up @@ -92,12 +92,18 @@ fig_text(struct lstopo_output *loutput, const struct lstopo_color *lcolor, int s
fprintf(file, "4 0 %d %u -1 0 %d 0.0 4 %d %d %u %u %s\\001\n", color, depth, size, size * 10, len * size * 10, x, y + size * 10, text);
}

static void
fig_textsize(struct lstopo_output *loutput __hwloc_attribute_unused, const char *text __hwloc_attribute_unused, unsigned textlength, unsigned fontsize, unsigned *width)
{
*width = (textlength * fontsize * 3) / 4;
}

static struct draw_methods fig_draw_methods = {
fig_declare_color,
fig_box,
fig_line,
fig_text,
NULL, /* textsize not supported, fallback to default estimation in get_textsize() */
fig_textsize,
};

int
Expand Down

0 comments on commit ce9e0f4

Please sign in to comment.