@@ -226,27 +226,31 @@ FT_Error tvg_svg_in_ot_preset_slot(FT_GlyphSlot p_slot, FT_Bool p_cache, FT_Poin
226226
227227 float svg_width, svg_height;
228228 picture->size (&svg_width, &svg_height);
229- double aspect = svg_width / svg_height;
229+ double aspect_x = (svg_width > svg_height) ? svg_width / svg_height : 1.0 ;
230+ double aspect_y = (svg_width < svg_height) ? svg_height / svg_width : 1.0 ;
230231
231- result = picture->size (embox_x * aspect , embox_y);
232+ result = picture->size (embox_x * aspect_x , embox_y * aspect_y );
232233 if (result != tvg::Result::Success) {
233234 ERR_FAIL_V_MSG (FT_Err_Invalid_SVG_Document, " Failed to resize SVG document." );
234235 }
235236
236- double x_svg_to_out = (double )metrics.x_ppem / embox_x;
237- double y_svg_to_out = (double )metrics.y_ppem / embox_y;
237+ double scale = double (embox_x * aspect_x) / double (svg_width);
238+ double yoff = double (document->metrics .ascender + document->metrics .descender ) / double (document->metrics .ascender );
239+
240+ double x_svg_to_out = (double )metrics.x_ppem / embox_x / scale;
241+ double y_svg_to_out = (double )metrics.y_ppem / embox_y / scale;
238242
239243 gl_state.m .e11 = (double )document->transform .xx / (1 << 16 );
240244 gl_state.m .e12 = -(double )document->transform .xy / (1 << 16 );
241245 gl_state.m .e21 = -(double )document->transform .yx / (1 << 16 );
242246 gl_state.m .e22 = (double )document->transform .yy / (1 << 16 );
243- gl_state.m .e13 = (double )document->delta .x / 64 * embox_x / metrics.x_ppem ;
244- gl_state.m .e23 = -(double )document->delta .y / 64 * embox_y / metrics.y_ppem ;
247+ gl_state.m .e13 = (double )document->delta .x / 64 * embox_x / metrics.x_ppem * scale ;
248+ gl_state.m .e23 = -(double )document->delta .y / 64 * embox_y / metrics.y_ppem * scale ;
245249 gl_state.m .e31 = 0 ;
246250 gl_state.m .e32 = 0 ;
247251 gl_state.m .e33 = 1 ;
248252
249- result = picture->size (embox_x * aspect * x_svg_to_out, embox_y * y_svg_to_out);
253+ result = picture->size (embox_x * aspect_x * x_svg_to_out, embox_y * aspect_y * y_svg_to_out);
250254 if (result != tvg::Result::Success) {
251255 ERR_FAIL_V_MSG (FT_Err_Invalid_SVG_Document, " Failed to resize SVG document." );
252256 }
@@ -257,8 +261,9 @@ FT_Error tvg_svg_in_ot_preset_slot(FT_GlyphSlot p_slot, FT_Bool p_cache, FT_Poin
257261 }
258262
259263 picture->size (&gl_state.w , &gl_state.h );
260- gl_state.x = (gl_state.h - gl_state.w ) / 2.0 ;
261- gl_state.y = -gl_state.h ;
264+
265+ gl_state.x = (double (p_slot->metrics .horiAdvance ) / 64.0 - gl_state.w ) / 2.0 ;
266+ gl_state.y = -Math::ceil (gl_state.h * yoff);
262267
263268 gl_state.ready = true ;
264269 }
0 commit comments