From 47ee34e84745756a9aaeb964772377b6c1417ed1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 21 Jan 2017 18:10:08 -0800 Subject: [PATCH] [var] Hook up variations to FreeType face hb-view correctly renders variations with ft font-funcs now. hb-ot-font needs HVAR implementation. --- src/hb-ft.cc | 10 ++++++++++ util/helper-cairo.cc | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/hb-ft.cc b/src/hb-ft.cc index d5f8d5295..acb7bb1d0 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -736,6 +736,16 @@ hb_ft_font_set_funcs (hb_font_t *font) FT_Set_Transform (ft_face, &matrix, NULL); } + unsigned int num_coords; + int *coords = hb_font_get_var_coords_normalized (font, &num_coords); + if (num_coords) + { + FT_Fixed ft_coords[num_coords]; + for (unsigned int i = 0; i < num_coords; i++) + ft_coords[i] = coords[i] << 2; + FT_Set_Var_Blend_Coordinates (ft_face, num_coords, ft_coords); + } + ft_face->generic.data = blob; ft_face->generic.finalizer = (FT_Generic_Finalizer) _release_blob; diff --git a/util/helper-cairo.cc b/util/helper-cairo.cc index 8f30eea14..df5173b59 100644 --- a/util/helper-cairo.cc +++ b/util/helper-cairo.cc @@ -28,6 +28,7 @@ #include #include +#include FT_MULTIPLE_MASTERS_H #include "helper-cairo-ansi.hh" #ifdef CAIRO_HAS_SVG_SURFACE @@ -76,7 +77,8 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts) cairo_font_face_t *cairo_face; /* We cannot use the FT_Face from hb_font_t, as doing so will confuse hb_font_t because - * cairo will reset the face size. As such, create new face... */ + * cairo will reset the face size. As such, create new face... + * TODO Perhaps add API to hb-ft to encapsulate this code. */ FT_Face ft_face = NULL;//hb_ft_font_get_face (font); if (!ft_face) { @@ -100,7 +102,19 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts) CAIRO_FONT_WEIGHT_NORMAL); } else + { + unsigned int num_coords; + int *coords = hb_font_get_var_coords_normalized (font, &num_coords); + if (num_coords) + { + FT_Fixed ft_coords[num_coords]; + for (unsigned int i = 0; i < num_coords; i++) + ft_coords[i] = coords[i] << 2; + FT_Set_Var_Blend_Coordinates (ft_face, num_coords, ft_coords); + } + cairo_face = cairo_ft_font_face_create_for_ft_face (ft_face, 0); + } cairo_matrix_t ctm, font_matrix; cairo_font_options_t *font_options;