diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2018-04-26 08:42:21 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2018-04-26 08:42:21 +0000 |
| commit | 8d6e6db37f2fb58d4f3cfe8ca2827c0c4ae6c006 (patch) | |
| tree | 5d1b0110905cef04cc1078378d05011558c72389 /src/libnrtype | |
| parent | CMake: put policies at the top before running any other code (diff) | |
| download | inkscape-8d6e6db37f2fb58d4f3cfe8ca2827c0c4ae6c006.tar.gz inkscape-8d6e6db37f2fb58d4f3cfe8ca2827c0c4ae6c006.zip | |
Add start of 'font-variations' widget.
Some code cleanup.
Diffstat (limited to 'src/libnrtype')
| -rw-r--r-- | src/libnrtype/FontFactory.cpp | 4 | ||||
| -rw-r--r-- | src/libnrtype/OpenTypeUtil.cpp | 42 | ||||
| -rw-r--r-- | src/libnrtype/OpenTypeUtil.h | 14 | ||||
| -rw-r--r-- | src/libnrtype/font-instance.h | 11 |
4 files changed, 50 insertions, 21 deletions
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<Glib::ustring, OTVarAxis> axes; - std::map<Glib::ustring, OTVarNamed> named; - readOpenTypeFvarTable( res->theFace, axes, named ); + std::map<Glib::ustring, OTVarInstance> 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<Glib::ustring, OTVarAxis>& axes, - std::map<Glib::ustring, OTVarNamed>& 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<Glib::ustring, OTVarAxis>& 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<Glib::ustring, OTVarInstance>& 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<Glib::ustring, double> axes; }; @@ -53,9 +55,11 @@ void readOpenTypeGsubTable (const FT_Face ft_face, std::map<Glib::ustring, Glib::ustring>& stylistic, std::map<Glib::ustring, Glib::ustring>& ligatures); -void readOpenTypeFvarTable (const FT_Face ft_face, - std::map<Glib::ustring, OTVarAxis>& axes, - std::map<Glib::ustring, OTVarNamed>& named); +void readOpenTypeFvarAxes (const FT_Face ft_face, + std::map<Glib::ustring, OTVarAxis>& axes); + +void readOpenTypeFvarNamed (const FT_Face ft_face, + std::map<Glib::ustring, OTVarInstance>& 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 <map> + #include <pango/pango-types.h> #include <pango/pango-font.h> -#include "FontFactory.h" -#include <libnrtype/font-style.h> #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<Glib::ustring, Glib::ustring> openTypeStylistic; std::map<Glib::ustring, Glib::ustring> openTypeLigatures; + // Maps for font variations. + std::map<Glib::ustring, OTVarAxis> openTypeVarAxes; // Axes with ranges + font_instance(void); virtual ~font_instance(void); |
