diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2018-03-23 15:01:54 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2018-03-23 15:01:54 +0000 |
| commit | b67737116b6908dc3667778f2c16a75a8b900d5c (patch) | |
| tree | 7583e4a020fb59ed55501d20cbde4619d9209b56 /src/libnrtype | |
| parent | Move OpenType functions to separate file. (diff) | |
| download | inkscape-b67737116b6908dc3667778f2c16a75a8b900d5c.tar.gz inkscape-b67737116b6908dc3667778f2c16a75a8b900d5c.zip | |
Start of reading OpenType fvar table.
Diffstat (limited to 'src/libnrtype')
| -rw-r--r-- | src/libnrtype/FontFactory.cpp | 3 | ||||
| -rw-r--r-- | src/libnrtype/OpenTypeUtil.cpp | 54 | ||||
| -rw-r--r-- | src/libnrtype/OpenTypeUtil.h | 26 |
3 files changed, 82 insertions, 1 deletions
diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp index d17a8a310..3b8703321 100644 --- a/src/libnrtype/FontFactory.cpp +++ b/src/libnrtype/FontFactory.cpp @@ -705,6 +705,9 @@ font_instance *font_factory::Face(PangoFontDescription *descr, bool canFail) if (res) { readOpenTypeGsubTable( res->theFace, res->openTypeTables, res->openTypeSubstitutions ); + std::map<Glib::ustring, OTVarAxis> axes; + std::map<Glib::ustring, OTVarNamed> named; + readOpenTypeFvarTable( res->theFace, axes, named ); } } else { diff --git a/src/libnrtype/OpenTypeUtil.cpp b/src/libnrtype/OpenTypeUtil.cpp index d1d1dea82..7998427d9 100644 --- a/src/libnrtype/OpenTypeUtil.cpp +++ b/src/libnrtype/OpenTypeUtil.cpp @@ -194,7 +194,59 @@ 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) { + +#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; + + FT_Fixed coords[mmvar->num_axis]; + FT_Get_Var_Design_Coordinates( ft_face, mmvar->num_axis, coords ); + + for (size_t i = 0; i < mmvar->num_axis; ++i) { + FT_Var_Axis* axis = &mmvar->axis[i]; + axes[axis->name] = OTVarAxis(FTFixedToDouble(axis->minimum), + FTFixedToDouble(axis->maximum), + 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; + } + + // const FT_UInt numNames = FT_Get_Sfnt_Name_Count(ft_face); + // std::cout << " number of names: " << numNames << std::endl; + // FT_SfntName ft_name; + // for (FT_UInt i = 0; i < numNames; ++i) { + + // if (FT_Get_Sfnt_Name(ft_face, i, &ft_name) != 0) { + // continue; + // } + + // Glib::ustring name; + // for (size_t j = 0; j < ft_name.string_len; ++j) { + // name += (char)ft_name.string[j]; + // } + // std::cout << " " << i << ": " << name << std::endl; + // } + + } + +#endif +} + + /* Local Variables: mode:c++ diff --git a/src/libnrtype/OpenTypeUtil.h b/src/libnrtype/OpenTypeUtil.h index 6d9ac9b3b..424087017 100644 --- a/src/libnrtype/OpenTypeUtil.h +++ b/src/libnrtype/OpenTypeUtil.h @@ -16,11 +16,37 @@ * All three provide variable amounts of access to data. */ +// An OpenType fvar axis +class OTVarAxis { + public: + OTVarAxis() + : minimum(0) + , maximum(1000) + , set_val(500) {}; + + OTVarAxis(double _minimum, double _maximum, double _set_val) + : minimum(_minimum) + , maximum(_maximum) + , set_val(_set_val) {}; + + double minimum; + double maximum; + double set_val; +}; + +class OTVarNamed { + std::map<Glib::ustring, double> axes; +}; + void readOpenTypeGsubTable (const FT_Face ft_face, std::map<Glib::ustring, int>& tables, std::map<Glib::ustring, Glib::ustring>& substitutions); +void readOpenTypeFvarTable (const FT_Face ft_face, + std::map<Glib::ustring, OTVarAxis>& axes, + std::map<Glib::ustring, OTVarNamed>& named); + #endif /* !SEEN_OPENTYPEUTIL_H */ |
