popup: no fallbacks for work areas no desktop has; text setup cannot fail
popuplayout had two refit stages for a work area shorter than one padded row — 40 pixels — and popupdraw re-checked the layout it had just been handed, against an Imgh that bounded no buffer any more. Pango and Cairo abort rather than return nil, so textinit is void and the layout is never nil; the stride Cairo computes for RGB24 is w*4 by definition; and textdraw set the layout's width and ellipsis twice.
This commit is contained in:
40
font.c
40
font.c
@@ -7,13 +7,6 @@ static PangoFontMap *fontmap;
|
||||
static PangoContext *context;
|
||||
static PangoLayout *layout;
|
||||
|
||||
static void
|
||||
resetlayout(void)
|
||||
{
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
}
|
||||
|
||||
void
|
||||
textclose(void)
|
||||
{
|
||||
@@ -50,28 +43,16 @@ setfont(void)
|
||||
pango_font_description_free(font);
|
||||
}
|
||||
|
||||
int
|
||||
void
|
||||
textinit(void)
|
||||
{
|
||||
textclose();
|
||||
FcInit();
|
||||
fontmap = pango_cairo_font_map_new();
|
||||
if(fontmap == nil){
|
||||
fprint(2, "strans: popup: can't initialize PangoCairo\n");
|
||||
return 0;
|
||||
}
|
||||
pango_cairo_font_map_set_resolution(PANGO_CAIRO_FONT_MAP(fontmap), 96);
|
||||
context = pango_font_map_create_context(fontmap);
|
||||
if(context != nil)
|
||||
layout = pango_layout_new(context);
|
||||
if(context == nil || layout == nil){
|
||||
fprint(2, "strans: popup: can't create text layout\n");
|
||||
textclose();
|
||||
return 0;
|
||||
}
|
||||
layout = pango_layout_new(context);
|
||||
pango_layout_set_single_paragraph_mode(layout, TRUE);
|
||||
setfont();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -80,8 +61,6 @@ settext(Str *s)
|
||||
char utf[Maxutf];
|
||||
int n;
|
||||
|
||||
if(layout == nil || s == nil || s->n <= 0)
|
||||
return 0;
|
||||
n = stoutf(s, utf, sizeof utf);
|
||||
pango_layout_set_text(layout, utf, n);
|
||||
return n > 0;
|
||||
@@ -109,9 +88,8 @@ textwidth(Str *s)
|
||||
{
|
||||
PangoRectangle r;
|
||||
|
||||
if(layout == nil)
|
||||
return 0;
|
||||
resetlayout();
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
if(!settext(s))
|
||||
return 0;
|
||||
textextents(&r);
|
||||
@@ -130,20 +108,16 @@ textdraw(u32int *buf, int w, int h, int x, int y, int fit, u32int color,
|
||||
PangoRectangle r;
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
int b, g, red, stride;
|
||||
int b, g, red;
|
||||
|
||||
if(layout == nil || fit <= 0)
|
||||
if(fit <= 0)
|
||||
return;
|
||||
resetlayout();
|
||||
pango_layout_set_width(layout, fit * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
if(w <= 0 || h <= 0 || !settext(s))
|
||||
return;
|
||||
stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, w);
|
||||
if(stride < 0 || (vlong)stride != (vlong)w * sizeof buf[0])
|
||||
return;
|
||||
surface = cairo_image_surface_create_for_data((uchar*)buf,
|
||||
CAIRO_FORMAT_RGB24, w, h, stride);
|
||||
CAIRO_FORMAT_RGB24, w, h, w * sizeof buf[0]);
|
||||
if(cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS){
|
||||
cairo_surface_destroy(surface);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user