optimization: split cairo font creation into create + set

This commit is contained in:
stefan schippers 2022-12-25 10:42:07 +01:00
parent 383dc03696
commit 75fbb76543
5 changed files with 45 additions and 23 deletions

View File

@ -2623,8 +2623,10 @@ int place_text(int draw_text, double mx, double my)
if(t->flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE; if(t->flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE;
cairo_save(xctx->cairo_ctx); cairo_save(xctx->cairo_ctx);
cairo_save(xctx->cairo_save_ctx); cairo_save(xctx->cairo_save_ctx);
cairo_select_font_face (xctx->cairo_ctx, textfont, slant, weight); xctx->cairo_font =
cairo_select_font_face (xctx->cairo_save_ctx, textfont, slant, weight); 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);
} }
#endif #endif
save_draw=xctx->draw_window; save_draw=xctx->draw_window;

View File

@ -324,8 +324,10 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
#if HAS_CAIRO==1 #if HAS_CAIRO==1
cairo_save(xctx->cairo_ctx); cairo_save(xctx->cairo_ctx);
cairo_save(xctx->cairo_save_ctx); cairo_save(xctx->cairo_save_ctx);
cairo_select_font_face(xctx->cairo_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); xctx->cairo_font =
cairo_select_font_face(xctx->cairo_save_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); 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);
#endif #endif
gr = &xctx->graph_struct; gr = &xctx->graph_struct;
for(i=0; i < xctx->rects[GRIDLAYER]; i++) { for(i=0; i < xctx->rects[GRIDLAYER]; i++) {

View File

@ -189,7 +189,9 @@ int set_text_custom_font(xText *txt) /* 20171122 for correct text_bbox calculati
if(txt->flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC; if(txt->flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC;
if(txt->flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE; if(txt->flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE;
cairo_save(xctx->cairo_ctx); cairo_save(xctx->cairo_ctx);
cairo_select_font_face (xctx->cairo_ctx, textfont, slant, weight); xctx->cairo_font =
cairo_toy_font_face_create(textfont, slant, weight);
cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
return 1; return 1;
} }
return 0; return 0;
@ -584,8 +586,10 @@ void draw_symbol(int what,int c, int n,int layer,short tmp_flip, short rot,
if(symptr->text[j].flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE; if(symptr->text[j].flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE;
cairo_save(xctx->cairo_ctx); cairo_save(xctx->cairo_ctx);
cairo_save(xctx->cairo_save_ctx); cairo_save(xctx->cairo_save_ctx);
cairo_select_font_face (xctx->cairo_ctx, textfont, slant, weight); xctx->cairo_font =
cairo_select_font_face (xctx->cairo_save_ctx, textfont, slant, weight); 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);
} }
#endif #endif
dbg(1, "drawing string: str=%s prop=%s\n", txtptr, text.prop_ptr); dbg(1, "drawing string: str=%s prop=%s\n", txtptr, text.prop_ptr);
@ -2345,32 +2349,40 @@ static void draw_graph_variables(int wcnt, int wave_color, int n_nodes, int swee
if(yt <= gr->ypos2 && yt >= gr->ypos1) { if(yt <= gr->ypos2 && yt >= gr->ypos1) {
#if HAS_CAIRO == 1 #if HAS_CAIRO == 1
if(gr->hilight_wave == wcnt) { if(gr->hilight_wave == wcnt) {
cairo_select_font_face(xctx->cairo_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); xctx->cairo_font =
cairo_select_font_face(xctx->cairo_save_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); 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);
} }
#endif #endif
draw_string(wave_color, NOW, tmpstr, 2, 0, 0, 0, draw_string(wave_color, NOW, tmpstr, 2, 0, 0, 0,
xt, DW_Y(yt), gr->digtxtsizelab, gr->digtxtsizelab); xt, DW_Y(yt), gr->digtxtsizelab, gr->digtxtsizelab);
#if HAS_CAIRO == 1 #if HAS_CAIRO == 1
if(gr->hilight_wave == wcnt) { if(gr->hilight_wave == wcnt) {
cairo_select_font_face(xctx->cairo_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); xctx->cairo_font =
cairo_select_font_face(xctx->cairo_save_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); 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);
} }
#endif #endif
} }
} else { } else {
#if HAS_CAIRO == 1 #if HAS_CAIRO == 1
if(gr->hilight_wave == wcnt) { if(gr->hilight_wave == wcnt) {
cairo_select_font_face(xctx->cairo_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); xctx->cairo_font =
cairo_select_font_face(xctx->cairo_save_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); 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);
} }
#endif #endif
draw_string(wave_color, NOW, tmpstr, 0, 0, 0, 0, draw_string(wave_color, NOW, tmpstr, 0, 0, 0, 0,
gr->rx1 + 2 + gr->rw / n_nodes * wcnt, gr->ry1, gr->txtsizelab, gr->txtsizelab); gr->rx1 + 2 + gr->rw / n_nodes * wcnt, gr->ry1, gr->txtsizelab, gr->txtsizelab);
#if HAS_CAIRO == 1 #if HAS_CAIRO == 1
if(gr->hilight_wave == wcnt) { if(gr->hilight_wave == wcnt) {
cairo_select_font_face(xctx->cairo_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); xctx->cairo_font =
cairo_select_font_face(xctx->cairo_save_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); 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);
} }
#endif #endif
} }
@ -2996,8 +3008,10 @@ static void draw_graph_all(int flags)
#if HAS_CAIRO==1 #if HAS_CAIRO==1
cairo_save(xctx->cairo_ctx); cairo_save(xctx->cairo_ctx);
cairo_save(xctx->cairo_save_ctx); cairo_save(xctx->cairo_save_ctx);
cairo_select_font_face(xctx->cairo_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); xctx->cairo_font =
cairo_select_font_face(xctx->cairo_save_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); 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);
#endif #endif
if(xctx->draw_single_layer==-1 || GRIDLAYER == xctx->draw_single_layer) { if(xctx->draw_single_layer==-1 || GRIDLAYER == xctx->draw_single_layer) {
if(xctx->enable_layer[GRIDLAYER]) for(i = 0; i < xctx->rects[GRIDLAYER]; i++) { if(xctx->enable_layer[GRIDLAYER]) for(i = 0; i < xctx->rects[GRIDLAYER]; i++) {
@ -3480,8 +3494,10 @@ void draw(void)
cairo_save(xctx->cairo_ctx); cairo_save(xctx->cairo_ctx);
cairo_save(xctx->cairo_save_ctx); cairo_save(xctx->cairo_save_ctx);
cairo_select_font_face (xctx->cairo_ctx, textfont, slant, weight); xctx->cairo_font =
cairo_select_font_face (xctx->cairo_save_ctx, textfont, slant, weight); 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);
} }
#endif #endif
draw_string(textlayer, ADD, xctx->text[i].txt_ptr, draw_string(textlayer, ADD, xctx->text[i].txt_ptr,

View File

@ -508,6 +508,7 @@ static void alloc_xschem_data(const char *top_path, const char *win_path)
#if HAS_CAIRO==1 #if HAS_CAIRO==1
xctx->cairo_ctx = xctx->cairo_save_ctx = NULL; xctx->cairo_ctx = xctx->cairo_save_ctx = NULL;
xctx->cairo_sfc = xctx->cairo_save_sfc = NULL; xctx->cairo_sfc = xctx->cairo_save_sfc = NULL;
xctx->cairo_font = NULL;
#endif #endif
xctx->gctiled = 0; xctx->gctiled = 0;
/* get_unnamed_node() */ /* get_unnamed_node() */
@ -1772,11 +1773,12 @@ static void resetcairo(int create, int clear, int force_or_resize)
if(cairo_surface_status(xctx->cairo_save_sfc)!=CAIRO_STATUS_SUCCESS) { if(cairo_surface_status(xctx->cairo_save_sfc)!=CAIRO_STATUS_SUCCESS) {
fprintf(errfp, "ERROR: invalid cairo xcb surface\n"); fprintf(errfp, "ERROR: invalid cairo xcb surface\n");
} }
xctx->cairo_font =
cairo_toy_font_face_create(tclgetvar("cairo_font_name"), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
xctx->cairo_save_ctx = cairo_create(xctx->cairo_save_sfc); xctx->cairo_save_ctx = cairo_create(xctx->cairo_save_sfc);
/* cairo_set_antialias (xctx->cairo_save_ctx, CAIRO_ANTIALIAS_NONE); */ /* cairo_set_antialias (xctx->cairo_save_ctx, CAIRO_ANTIALIAS_NONE); */
cairo_select_font_face(xctx->cairo_save_ctx, tclgetvar("cairo_font_name"), cairo_set_font_face(xctx->cairo_save_ctx, xctx->cairo_font);
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(xctx->cairo_save_ctx, 20); cairo_set_font_size(xctx->cairo_save_ctx, 20);
cairo_set_font_options(xctx->cairo_save_ctx, options); cairo_set_font_options(xctx->cairo_save_ctx, options);
@ -1796,8 +1798,7 @@ static void resetcairo(int create, int clear, int force_or_resize)
} }
xctx->cairo_ctx = cairo_create(xctx->cairo_sfc); xctx->cairo_ctx = cairo_create(xctx->cairo_sfc);
/* cairo_set_antialias (xctx->cairo_ctx, CAIRO_ANTIALIAS_NONE); */ /* cairo_set_antialias (xctx->cairo_ctx, CAIRO_ANTIALIAS_NONE); */
cairo_select_font_face(xctx->cairo_ctx, tclgetvar("cairo_font_name"), cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(xctx->cairo_ctx, 20); cairo_set_font_size(xctx->cairo_ctx, 20);
cairo_set_font_options(xctx->cairo_ctx, options); cairo_set_font_options(xctx->cairo_ctx, options);

View File

@ -830,6 +830,7 @@ typedef struct {
#if HAS_CAIRO==1 #if HAS_CAIRO==1
cairo_surface_t *cairo_sfc, *cairo_save_sfc; cairo_surface_t *cairo_sfc, *cairo_save_sfc;
cairo_t *cairo_ctx, *cairo_save_ctx; cairo_t *cairo_ctx, *cairo_save_ctx;
cairo_font_face_t *cairo_font;
#endif #endif
GC gctiled; GC gctiled;
GC *gc; GC *gc;