fix cairo font reference counting

This commit is contained in:
stefan schippers 2022-12-25 23:13:59 +01:00
parent 75fbb76543
commit aa70d90c46
8 changed files with 63 additions and 22 deletions

View File

@ -1557,7 +1557,9 @@ void calc_drawing_bbox(xRect *boundbox, int selected)
updatebbox(count,boundbox,&rect);
}
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
}
for(i=0;i<xctx->instances;i++)
@ -2391,9 +2393,9 @@ int text_bbox(const char *str, double xscale, double yscale,
/* if(size*xctx->mooz>800.) { */
/* return 0; */
/* } */
cairo_set_font_size (xctx->cairo_ctx, size*xctx->mooz);
cairo_font_extents(xctx->cairo_ctx, &fext);
ww=0.; hh=1.;
c=0;
*cairo_lines=1;
@ -2627,6 +2629,7 @@ int place_text(int draw_text, double mx, double my)
cairo_toy_font_face_create(textfont, slant, weight);
cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
cairo_set_font_face(xctx->cairo_save_ctx, xctx->cairo_font);
cairo_font_face_destroy(xctx->cairo_font);
}
#endif
save_draw=xctx->draw_window;

View File

@ -328,6 +328,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
cairo_toy_font_face_create("Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
cairo_set_font_face(xctx->cairo_save_ctx, xctx->cairo_font);
cairo_font_face_destroy(xctx->cairo_font);
#endif
gr = &xctx->graph_struct;
for(i=0; i < xctx->rects[GRIDLAYER]; i++) {

View File

@ -192,6 +192,7 @@ int set_text_custom_font(xText *txt) /* 20171122 for correct text_bbox calculati
xctx->cairo_font =
cairo_toy_font_face_create(textfont, slant, weight);
cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
cairo_font_face_destroy(xctx->cairo_font);
return 1;
}
return 0;
@ -590,6 +591,7 @@ void draw_symbol(int what,int c, int n,int layer,short tmp_flip, short rot,
cairo_toy_font_face_create(textfont, slant, weight);
cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
cairo_set_font_face(xctx->cairo_save_ctx, xctx->cairo_font);
cairo_font_face_destroy(xctx->cairo_font);
}
#endif
dbg(1, "drawing string: str=%s prop=%s\n", txtptr, text.prop_ptr);
@ -733,7 +735,9 @@ void draw_temp_symbol(int what, GC gc, int n,int layer,short tmp_flip, short rot
(text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3,
flip^text.flip, text.hcenter, text.vcenter, x0+x1, y0+y1, text.xscale, text.yscale);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
}
@ -2353,6 +2357,7 @@ static void draw_graph_variables(int wcnt, int wave_color, int n_nodes, int swee
cairo_toy_font_face_create("Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
cairo_set_font_face(xctx->cairo_save_ctx, xctx->cairo_font);
cairo_font_face_destroy(xctx->cairo_font);
}
#endif
draw_string(wave_color, NOW, tmpstr, 2, 0, 0, 0,
@ -2363,6 +2368,7 @@ static void draw_graph_variables(int wcnt, int wave_color, int n_nodes, int swee
cairo_toy_font_face_create("Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
cairo_set_font_face(xctx->cairo_save_ctx, xctx->cairo_font);
cairo_font_face_destroy(xctx->cairo_font);
}
#endif
}
@ -2373,6 +2379,7 @@ static void draw_graph_variables(int wcnt, int wave_color, int n_nodes, int swee
cairo_toy_font_face_create("Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
cairo_set_font_face(xctx->cairo_save_ctx, xctx->cairo_font);
cairo_font_face_destroy(xctx->cairo_font);
}
#endif
draw_string(wave_color, NOW, tmpstr, 0, 0, 0, 0,
@ -2383,6 +2390,7 @@ static void draw_graph_variables(int wcnt, int wave_color, int n_nodes, int swee
cairo_toy_font_face_create("Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
cairo_set_font_face(xctx->cairo_save_ctx, xctx->cairo_font);
cairo_font_face_destroy(xctx->cairo_font);
}
#endif
}
@ -3012,6 +3020,7 @@ static void draw_graph_all(int flags)
cairo_toy_font_face_create("Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
cairo_set_font_face(xctx->cairo_save_ctx, xctx->cairo_font);
cairo_font_face_destroy(xctx->cairo_font);
#endif
if(xctx->draw_single_layer==-1 || GRIDLAYER == xctx->draw_single_layer) {
if(xctx->enable_layer[GRIDLAYER]) for(i = 0; i < xctx->rects[GRIDLAYER]; i++) {
@ -3498,6 +3507,7 @@ void draw(void)
cairo_toy_font_face_create(textfont, slant, weight);
cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
cairo_set_font_face(xctx->cairo_save_ctx, xctx->cairo_font);
cairo_font_face_destroy(xctx->cairo_font);
}
#endif
draw_string(textlayer, ADD, xctx->text[i].txt_ptr,

View File

@ -999,7 +999,9 @@ static void edit_text_property(int x)
xctx->text[sel].vcenter, xctx->text[sel].x0, xctx->text[sel].y0,
&xx1,&yy1,&xx2,&yy2, &tmp, &dtmp);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
bbox(ADD, xx1, yy1, xx2, yy2 );
/* dbg(1, "edit_property(): text props=%s text=%s\n", tclgetvar("props"), tclgetvar("retval")); */
@ -1018,7 +1020,9 @@ static void edit_text_property(int x)
xctx->text[sel].vcenter, xctx->text[sel].x0, xctx->text[sel].y0,
&xx1,&yy1,&xx2,&yy2, &tmp, &dtmp);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
pcx = (xctx->rect[PINLAYER][l].x1+xctx->rect[PINLAYER][l].x2)/2.0;
pcy = (xctx->rect[PINLAYER][l].y1+xctx->rect[PINLAYER][l].y2)/2.0;
@ -1078,7 +1082,9 @@ static void edit_text_property(int x)
xctx->text[sel].vcenter, xctx->text[sel].x0, xctx->text[sel].y0,
&xx1,&yy1,&xx2,&yy2, &tmp, &dtmp);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
bbox(ADD, xx1, yy1, xx2, yy2 );

View File

@ -296,7 +296,9 @@ static void find_closest_text(double mx,double my)
xctx->text[i].x0, xctx->text[i].y0,
&xx1,&yy1, &xx2,&yy2, &tmp, &dtmp);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
if(POINTINSIDE(mx,my,xx1,yy1, xx2, yy2))
{

View File

@ -217,7 +217,9 @@ void draw_selection(GC g, int interruptable)
xctx->rx1+xctx->deltax, xctx->ry1+xctx->deltay,
xctx->text[n].xscale, xctx->text[n].yscale);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
break;
@ -939,7 +941,9 @@ void copy_objects(int what)
xctx->text[l].x0, xctx->text[l].y0,
&xctx->rx1,&xctx->ry1, &xctx->rx2,&xctx->ry2, &tmpi, &dtmp);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
bbox(ADD, xctx->rx1, xctx->ry1, xctx->rx2, xctx->ry2 );
@ -1457,7 +1461,9 @@ void move_objects(int what, int merge, double dx, double dy)
xctx->text[n].vcenter, xctx->text[n].x0, xctx->text[n].y0,
&xctx->rx1,&xctx->ry1, &xctx->rx2,&xctx->ry2, &tmpint, &dtmp);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
bbox(ADD, xctx->rx1, xctx->ry1, xctx->rx2, xctx->ry2 );
if(xctx->rotatelocal) {
@ -1481,7 +1487,9 @@ void move_objects(int what, int merge, double dx, double dy)
xctx->text[n].vcenter, xctx->text[n].x0, xctx->text[n].y0,
&xctx->rx1,&xctx->ry1, &xctx->rx2,&xctx->ry2, &tmpint, &dtmp);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
bbox(ADD, xctx->rx1, xctx->ry1, xctx->rx2, xctx->ry2 );

View File

@ -179,7 +179,9 @@ void symbol_bbox(int i, double *x1,double *y1, double *x2, double *y2)
sym_flip ^ text.flip, text.hcenter, text.vcenter,
x0+text_x0,y0+text_y0, &xx1,&yy1,&xx2,&yy2, &tmp, &dtmp);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
if(xx1<*x1) *x1=xx1;
if(yy1<*y1) *y1=yy1;
@ -214,7 +216,9 @@ static void del_rect_line_arc_poly(void)
xctx->text[n].vcenter, xctx->text[n].x0, xctx->text[n].y0,
&xx1,&yy1,&xx2,&yy2, &itmp, &dtmp);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
bbox(ADD, xx1, yy1, xx2, yy2 );
}
@ -359,7 +363,9 @@ void delete(int to_push_undo)
xctx->text[i].vcenter, xctx->text[i].x0, xctx->text[i].y0,
&xx1,&yy1, &xx2,&yy2, &tmp, &dtmp);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
bbox(ADD, xx1, yy1, xx2, yy2 );
my_free(935, &xctx->text[i].prop_ptr);
@ -641,7 +647,9 @@ void unselect_all(int dr)
xctx->text[i].x0, xctx->text[i].y0,
xctx->text[i].xscale, xctx->text[i].yscale);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
}
}
@ -822,7 +830,9 @@ void select_text(int i,unsigned short select_mode, int fast)
xctx->text[i].x0, xctx->text[i].y0,
xctx->text[i].xscale, xctx->text[i].yscale);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
xctx->need_reb_sel_arr=1;
}
@ -1046,7 +1056,9 @@ void select_inside(double x1,double y1, double x2, double y2, int sel) /*added u
xctx->text[i].x0, xctx->text[i].y0,
&xx1,&yy1, &xx2,&yy2, &tmpint, &dtmp);
#if HAS_CAIRO==1
if(customfont) cairo_restore(xctx->cairo_ctx);
if(customfont) {
cairo_restore(xctx->cairo_ctx);
}
#endif
if(RECT_INSIDE(xx1,yy1, xx2, yy2,x1,y1,x2,y2))
{

View File

@ -1775,7 +1775,7 @@ static void resetcairo(int create, int clear, int force_or_resize)
}
xctx->cairo_font =
cairo_toy_font_face_create(tclgetvar("cairo_font_name"), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
/* dbg(0, "1 refcount=%d\n", cairo_font_face_get_reference_count(xctx->cairo_font)); */
xctx->cairo_save_ctx = cairo_create(xctx->cairo_save_sfc);
/* cairo_set_antialias (xctx->cairo_save_ctx, CAIRO_ANTIALIAS_NONE); */
cairo_set_font_face(xctx->cairo_save_ctx, xctx->cairo_font);
@ -1800,11 +1800,10 @@ static void resetcairo(int create, int clear, int force_or_resize)
/* cairo_set_antialias (xctx->cairo_ctx, CAIRO_ANTIALIAS_NONE); */
cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
cairo_set_font_size(xctx->cairo_ctx, 20);
cairo_set_font_options(xctx->cairo_ctx, options);
cairo_set_line_join(xctx->cairo_ctx, CAIRO_LINE_JOIN_ROUND);
cairo_set_line_cap(xctx->cairo_ctx, CAIRO_LINE_CAP_ROUND);
cairo_font_face_destroy(xctx->cairo_font);
cairo_font_options_destroy(options);
}
#endif /* HAS_CAIRO */