From 8d6e6db37f2fb58d4f3cfe8ca2827c0c4ae6c006 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 26 Apr 2018 10:42:21 +0200 Subject: Add start of 'font-variations' widget. Some code cleanup. --- src/libnrtype/FontFactory.cpp | 4 ++-- src/libnrtype/OpenTypeUtil.cpp | 42 ++++++++++++++++++++++++++++++------------ src/libnrtype/OpenTypeUtil.h | 14 +++++++++----- src/libnrtype/font-instance.h | 11 +++++++++-- 4 files changed, 50 insertions(+), 21 deletions(-) (limited to 'src/libnrtype') diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp index 98c9fa69f..a354d8915 100644 --- a/src/libnrtype/FontFactory.cpp +++ b/src/libnrtype/FontFactory.cpp @@ -707,8 +707,8 @@ font_instance *font_factory::Face(PangoFontDescription *descr, bool canFail) if (res) { readOpenTypeGsubTable( res->theFace, res->openTypeTables, res->openTypeStylistic, res->openTypeLigatures ); std::map axes; - std::map named; - readOpenTypeFvarTable( res->theFace, axes, named ); + std::map named; + readOpenTypeFvarAxes( res->theFace, res->openTypeVarAxes ); } #endif diff --git a/src/libnrtype/OpenTypeUtil.cpp b/src/libnrtype/OpenTypeUtil.cpp index 38b60c212..5324392d9 100644 --- a/src/libnrtype/OpenTypeUtil.cpp +++ b/src/libnrtype/OpenTypeUtil.cpp @@ -222,9 +222,10 @@ void readOpenTypeGsubTable (const FT_Face ft_face, hb_face_destroy (hb_face); } -void readOpenTypeFvarTable(const FT_Face ft_face, - std::map& axes, - std::map& named) { +// Make a list of all Variaration axes with ranges. +// Make a list of all Named instances with axis values. +void readOpenTypeFvarAxes(const FT_Face ft_face, + std::map& axes) { #if FREETYPE_MAJOR *10000 + FREETYPE_MINOR*100 + FREETYPE_MICRO >= 20701 FT_MM_Var* mmvar = NULL; @@ -233,9 +234,6 @@ void readOpenTypeFvarTable(const FT_Face ft_face, FT_Get_MM_Var( ft_face, &mmvar) == 0 && // We found the data FT_Get_Multi_Master( ft_face, &mmtype) !=0) { // It's not an Adobe MM font - std::cout << " Multiple Masters: variables: " << mmvar->num_axis - << " named styles: " << mmvar->num_namedstyles << std::endl; - FT_Fixed coords[mmvar->num_axis]; FT_Get_Var_Design_Coordinates( ft_face, mmvar->num_axis, coords ); @@ -246,12 +244,32 @@ void readOpenTypeFvarTable(const FT_Face ft_face, FTFixedToDouble(coords[i])); } - for (auto a: axes) { - std::cout << " " << a.first - << " min: " << a.second.minimum - << " max: " << a.second.maximum - << " set: " << a.second.set_val << std::endl; - } + // for (auto a: axes) { + // std::cout << " " << a.first + // << " min: " << a.second.minimum + // << " max: " << a.second.maximum + // << " set: " << a.second.set_val << std::endl; + // } + + } + +#endif /* FREETYPE Version */ +} + + +// Make a list of all Named instances with axis values. +void readOpenTypeFvarNamed(const FT_Face ft_face, + std::map& named) { + +#if FREETYPE_MAJOR *10000 + FREETYPE_MINOR*100 + FREETYPE_MICRO >= 20701 + FT_MM_Var* mmvar = NULL; + FT_Multi_Master mmtype; + if (FT_HAS_MULTIPLE_MASTERS( ft_face ) && // Font has variables + FT_Get_MM_Var( ft_face, &mmvar) == 0 && // We found the data + FT_Get_Multi_Master( ft_face, &mmtype) !=0) { // It's not an Adobe MM font + + std::cout << " Multiple Masters: variables: " << mmvar->num_axis + << " named styles: " << mmvar->num_namedstyles << std::endl; // const FT_UInt numNames = FT_Get_Sfnt_Name_Count(ft_face); // std::cout << " number of names: " << numNames << std::endl; diff --git a/src/libnrtype/OpenTypeUtil.h b/src/libnrtype/OpenTypeUtil.h index b4f7593dd..59ffe0045 100644 --- a/src/libnrtype/OpenTypeUtil.h +++ b/src/libnrtype/OpenTypeUtil.h @@ -18,7 +18,7 @@ * All three provide variable amounts of access to data. */ -// An OpenType fvar axis +// An OpenType fvar axis. class OTVarAxis { public: OTVarAxis() @@ -36,7 +36,9 @@ class OTVarAxis { double set_val; }; -class OTVarNamed { +// A particular instance of a variable font. +// A map indexed by axis name with value. +class OTVarInstance { std::map axes; }; @@ -53,9 +55,11 @@ void readOpenTypeGsubTable (const FT_Face ft_face, std::map& stylistic, std::map& ligatures); -void readOpenTypeFvarTable (const FT_Face ft_face, - std::map& axes, - std::map& named); +void readOpenTypeFvarAxes (const FT_Face ft_face, + std::map& axes); + +void readOpenTypeFvarNamed (const FT_Face ft_face, + std::map& named); #endif /* !USE_PANGO_WIND32 */ #endif /* !SEEN_OPENTYPEUTIL_H */ diff --git a/src/libnrtype/font-instance.h b/src/libnrtype/font-instance.h index f6408eccb..d70bf4f6a 100644 --- a/src/libnrtype/font-instance.h +++ b/src/libnrtype/font-instance.h @@ -2,13 +2,17 @@ #define SEEN_LIBNRTYPE_FONT_INSTANCE_H #include + #include #include -#include "FontFactory.h" -#include #include <2geom/d2.h> +#include "FontFactory.h" +#include "font-style.h" +#include "OpenTypeUtil.h" + + class font_factory; struct font_glyph; @@ -42,6 +46,9 @@ public: std::map openTypeStylistic; std::map openTypeLigatures; + // Maps for font variations. + std::map openTypeVarAxes; // Axes with ranges + font_instance(void); virtual ~font_instance(void); -- cgit v1.2.3