@@ -871,11 +871,33 @@ pt_to_px(double pt, double dpi) {
871871 return ((long )round ((pt * (dpi / 72.0 ))));
872872}
873873
874+ static void
875+ apply_cairo_font_size (Face * self , unsigned sz_px ) {
876+ // The cairo path uses self->face_for_cairo (a second FT_Face opened in
877+ // ensure_cairo_resources), which never receives the FT_Set_Transform set
878+ // on self->face in face_from_descriptor. cairo owns FT_Set_Transform on
879+ // its face and derives it from the font matrix on every render
880+ // (_cairo_ft_unscaled_font_set_scale in cairo-ft-font.c), so the only
881+ // channel that reaches glyph rasterization is the cairo font matrix
882+ // itself. Encode FC_MATRIX there.
883+ // FT_Matrix is xx,xy,yx,yy (row-major); cairo_matrix_init takes
884+ // xx,yx,xy,yy. Same matrix, transposed argument order.
885+ if (!self -> has_matrix ) { cairo_set_font_size (self -> cairo .cr , sz_px ); return ; }
886+ double s = (double )sz_px ;
887+ double xx = self -> matrix .xx / 65536.0 ;
888+ double xy = self -> matrix .xy / 65536.0 ;
889+ double yx = self -> matrix .yx / 65536.0 ;
890+ double yy = self -> matrix .yy / 65536.0 ;
891+ cairo_matrix_t m ;
892+ cairo_matrix_init (& m , xx * s , yx * s , xy * s , yy * s , 0 , 0 );
893+ cairo_set_font_matrix (self -> cairo .cr , & m );
894+ }
895+
874896static void
875897set_cairo_font_size (Face * self , double size_in_pts ) {
876898 unsigned sz_px = pt_to_px (size_in_pts , (self -> xdpi + self -> ydpi ) / 2.0 );
877899 if (self -> cairo .size_in_px == sz_px ) return ;
878- cairo_set_font_size (self -> cairo . cr , sz_px );
900+ apply_cairo_font_size (self , sz_px );
879901 self -> cairo .size_in_px = sz_px ;
880902}
881903
@@ -885,7 +907,7 @@ fit_cairo_glyph(Face *self, cairo_glyph_t *g, cairo_text_extents_t *bb, cairo_sc
885907 double ratio = MIN (width / bb -> width , height / bb -> height );
886908 unsigned sz = (unsigned )(ratio * self -> cairo .size_in_px );
887909 if (sz >= self -> cairo .size_in_px ) sz = self -> cairo .size_in_px - 2 ;
888- cairo_set_font_size (self -> cairo . cr , sz );
910+ apply_cairo_font_size (self , sz );
889911 sf = cairo_get_scaled_font (self -> cairo .cr );
890912 cairo_scaled_font_glyph_extents (sf , g , 1 , bb );
891913 self -> cairo .size_in_px = sz ;
0 commit comments