Refactored text size computation
This commit is contained in:
@@ -321,41 +321,29 @@ gulong *get_best_icon (gulong *data, int icon_count, int num, int *iw, int *ih,
|
||||
}
|
||||
|
||||
|
||||
void get_text_size(PangoFontDescription *font, int *height_ink, int *height, int panel_height, char *text, int len)
|
||||
void get_text_size2(PangoFontDescription *font,
|
||||
int *height_ink,
|
||||
int *height,
|
||||
int *width,
|
||||
int panel_height,
|
||||
int panel_width,
|
||||
char *text,
|
||||
int len,
|
||||
PangoWrapMode wrap,
|
||||
PangoEllipsizeMode ellipsis)
|
||||
{
|
||||
PangoRectangle rect_ink, rect;
|
||||
|
||||
Pixmap pmap = XCreatePixmap (server.dsp, server.root_win, panel_height, panel_height, server.depth);
|
||||
Pixmap pmap = XCreatePixmap (server.dsp, server.root_win, panel_height, panel_width, server.depth);
|
||||
|
||||
cairo_surface_t *cs = cairo_xlib_surface_create (server.dsp, pmap, server.visual, panel_height, panel_height);
|
||||
cairo_t *c = cairo_create (cs);
|
||||
|
||||
PangoLayout *layout = pango_cairo_create_layout (c);
|
||||
pango_layout_set_font_description (layout, font);
|
||||
pango_layout_set_text (layout, text, len);
|
||||
|
||||
pango_layout_get_pixel_extents(layout, &rect_ink, &rect);
|
||||
*height_ink = rect_ink.height;
|
||||
*height = rect.height;
|
||||
//printf("dimension : %d - %d\n", rect_ink.height, rect.height);
|
||||
|
||||
g_object_unref (layout);
|
||||
cairo_destroy (c);
|
||||
cairo_surface_destroy (cs);
|
||||
XFreePixmap (server.dsp, pmap);
|
||||
}
|
||||
|
||||
|
||||
void get_text_size2(PangoFontDescription *font, int *height_ink, int *height, int *width, int panel_height, int panel_with, char *text, int len)
|
||||
{
|
||||
PangoRectangle rect_ink, rect;
|
||||
|
||||
Pixmap pmap = XCreatePixmap (server.dsp, server.root_win, panel_height, panel_height, server.depth);
|
||||
|
||||
cairo_surface_t *cs = cairo_xlib_surface_create (server.dsp, pmap, server.visual, panel_height, panel_with);
|
||||
cairo_surface_t *cs = cairo_xlib_surface_create (server.dsp, pmap, server.visual, panel_height, panel_width);
|
||||
cairo_t *c = cairo_create (cs);
|
||||
|
||||
PangoLayout *layout = pango_cairo_create_layout (c);
|
||||
pango_layout_set_width(layout, panel_width * PANGO_SCALE);
|
||||
pango_layout_set_height(layout, panel_height * PANGO_SCALE);
|
||||
pango_layout_set_wrap(layout, wrap);
|
||||
pango_layout_set_ellipsize(layout, ellipsis);
|
||||
pango_layout_set_font_description (layout, font);
|
||||
pango_layout_set_text (layout, text, len);
|
||||
|
||||
|
||||
@@ -33,8 +33,16 @@ void windows_set_desktop (Window win, int desktop);
|
||||
int window_get_monitor (Window win);
|
||||
Window window_get_active ();
|
||||
|
||||
void get_text_size(PangoFontDescription *font, int *height_ink, int *height, int panel_height, char *text, int len);
|
||||
void get_text_size2(PangoFontDescription *font, int *height_ink, int *height, int *width, int panel_height, int panel_with, char *text, int len);
|
||||
void get_text_size2(PangoFontDescription *font,
|
||||
int *height_ink,
|
||||
int *height,
|
||||
int *width,
|
||||
int panel_height,
|
||||
int panel_with,
|
||||
char *text,
|
||||
int len,
|
||||
PangoWrapMode wrap,
|
||||
PangoEllipsizeMode ellipsis);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user