Skip to content

Commit 49ee213

Browse files
committed
faster fill/strokeText by avoiding cairo_set_font_size
I noticed that cairo_show_glyphs was _still_ slower vs when Pango calls it. Suspecting another instance had caching info attached, I read the Cairo source code to confirm it.
1 parent 1cd2728 commit 49ee213

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎src/CanvasRenderingContext2d.cc‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,14 @@ Context2d::paintText(const Napi::CallbackInfo& info, bool stroke) {
24592459

24602460
cairo_font_face_t* crface = cairo_ft_font_face_create_for_ft_face(run.face->ftface.get(), 0);
24612461
cairo_set_font_face(context(), crface);
2462-
cairo_set_font_size(context(), fontSize);
2462+
2463+
// Be shy about cairo_set_font_size. This always recreates a scaled font,
2464+
// which destroys lots of caching. Scaled fonts are associated with the
2465+
// font's matrix, which is both for scaling from em to Cairo space and for
2466+
// fake italics. Just checking xx should therefore be reliable.
2467+
cairo_matrix_t m;
2468+
cairo_get_font_matrix(context(), &m);
2469+
if (m.xx != fontSize) cairo_set_font_size(context(), fontSize);
24632470

24642471
size_t hbGlyphIndex = 0;
24652472
while (hbGlyphIndex < run.glyphs.size()) {

0 commit comments

Comments
 (0)