@@ -780,3 +780,73 @@ long FT2Font::get_name_index(char *name)
780780{
781781 return FT_Get_Name_Index (face, (FT_String *)name);
782782}
783+
784+ FT2Font::VariationInfo FT2Font::get_variation_descriptor ()
785+ {
786+ FT_MM_Var *master;
787+ FT_CHECK (FT_Get_MM_Var, face, &master);
788+
789+ std::vector<VariationAxis> axes;
790+ axes.reserve (master->num_axis );
791+ for (FT_UInt axis_index = 0 ; axis_index < master->num_axis ; axis_index++) {
792+ FT_UInt flags = 0 ;
793+ FT_CHECK (FT_Get_Var_Axis_Flags, master, axis_index, &flags);
794+ const auto &axis = master->axis [axis_index];
795+ axes.emplace_back (axis.name ,
796+ float (axis.minimum ) / (1 <<16 ),
797+ float (axis.def ) / (1 <<16 ),
798+ float (axis.maximum ) / (1 <<16 ),
799+ axis.tag ,
800+ axis.strid ,
801+ flags);
802+ }
803+
804+ std::vector<VariationNamedStyle> styles;
805+ styles.reserve (master->num_namedstyles );
806+ for (FT_UInt instance = 0 ; instance < master->num_namedstyles ; instance++) {
807+ const auto &style = master->namedstyle [instance];
808+ styles.emplace_back (style.strid , style.psid );
809+ }
810+
811+ FT_CHECK (FT_Done_MM_Var, _ft2Library, master);
812+
813+ return {axes, styles};
814+ }
815+
816+ FT_UInt FT2Font::get_default_variation_style () {
817+ FT_UInt result;
818+ FT_CHECK (FT_Get_Default_Named_Instance, face, &result);
819+ return result;
820+ }
821+
822+ std::vector<double > FT2Font::get_variations () {
823+ FT_MM_Var *master;
824+ FT_CHECK (FT_Get_MM_Var, face, &master);
825+ std::vector<FT_Fixed> fixed_coords (master->num_axis );
826+ FT_CHECK (FT_Done_MM_Var, _ft2Library, master);
827+
828+ FT_CHECK (FT_Get_Var_Design_Coordinates, face, fixed_coords.size (),
829+ fixed_coords.data ());
830+
831+ std::vector<double > coords;
832+ coords.reserve (fixed_coords.size ());
833+ for (auto const &c : fixed_coords) {
834+ coords.emplace_back (static_cast <double >(c) / (1 << 16 ));
835+ }
836+
837+ return coords;
838+ }
839+
840+ void FT2Font::set_variations (std::vector<double > coords) {
841+ std::vector<FT_Fixed> fixed_coords;
842+ fixed_coords.reserve (coords.size ());
843+ for (auto const &c : coords) {
844+ fixed_coords.emplace_back (static_cast <FT_Fixed>(c * (1 << 16 )));
845+ }
846+ FT_CHECK (FT_Set_Var_Design_Coordinates, face, fixed_coords.size (),
847+ fixed_coords.data ());
848+ }
849+
850+ void FT2Font::set_variations (FT_UInt instance_index) {
851+ FT_CHECK (FT_Set_Named_Instance, face, instance_index);
852+ }
0 commit comments