summaryrefslogtreecommitdiffstats
path: root/src/libnrtype
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-04-29 16:49:03 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-04-29 16:49:03 +0000
commite393169c252e4e9fb87b87ffc1d32671e3d5c3f2 (patch)
tree82dd36438ba161dae60dd041637150f9c7942c33 /src/libnrtype
parentUpdate style.css to improve margin and padding in #InkSpinScale (diff)
downloadinkscape-e393169c252e4e9fb87b87ffc1d32671e3d5c3f2.tar.gz
inkscape-e393169c252e4e9fb87b87ffc1d32671e3d5c3f2.zip
Bug fixes for variable fonts, especially to support the Decovar font.
Diffstat (limited to 'src/libnrtype')
-rw-r--r--src/libnrtype/FontFactory.cpp9
-rw-r--r--src/libnrtype/FontInstance.cpp56
-rw-r--r--src/libnrtype/OpenTypeUtil.cpp6
-rw-r--r--src/libnrtype/OpenTypeUtil.h31
4 files changed, 44 insertions, 58 deletions
diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp
index a354d8915..f09bd3df3 100644
--- a/src/libnrtype/FontFactory.cpp
+++ b/src/libnrtype/FontFactory.cpp
@@ -703,15 +703,6 @@ font_instance *font_factory::Face(PangoFontDescription *descr, bool canFail)
}
}
-#ifndef USE_PANGO_WIN32
- if (res) {
- readOpenTypeGsubTable( res->theFace, res->openTypeTables, res->openTypeStylistic, res->openTypeLigatures );
- std::map<Glib::ustring, OTVarAxis> axes;
- std::map<Glib::ustring, OTVarInstance> named;
- readOpenTypeFvarAxes( res->theFace, res->openTypeVarAxes );
- }
-#endif
-
} else {
// already here
res = loadedFaces[descr];
diff --git a/src/libnrtype/FontInstance.cpp b/src/libnrtype/FontInstance.cpp
index d55f919f1..47d4baa51 100644
--- a/src/libnrtype/FontInstance.cpp
+++ b/src/libnrtype/FontInstance.cpp
@@ -210,6 +210,10 @@ void font_instance::InitTheFace()
#endif
#ifndef USE_PANGO_WIN32
+
+ readOpenTypeGsubTable( theFace, openTypeTables, openTypeStylistic, openTypeLigatures );
+ readOpenTypeFvarAxes( theFace, openTypeVarAxes );
+
#if PANGO_VERSION_CHECK(1,41,1)
#if FREETYPE_MAJOR == 2 && FREETYPE_MINOR >= 8 // 2.8 does not seem to work even though it has some support.
@@ -217,9 +221,8 @@ void font_instance::InitTheFace()
// The font returned from pango_fc_font_lock_face does not include variation settings. We must set them.
// We need to:
- // Get a list of axes supported in the font with the range of allowed values.
// Extract axes with values from Pango font description.
- // Fill an array indexed by FT axis with values from Pango.
+ // Replace default axis values with extracted values.
char const *var = pango_font_description_get_variations( descr );
if (var) {
@@ -235,55 +238,44 @@ void font_instance::InitTheFace()
// std::cout << " Multiple Masters: variables: " << mmvar->num_axis
// << " named styles: " << mmvar->num_namedstyles << std::endl;
- // Get a list of axis and their default values from the font.
- std::map<Glib::ustring, int> axis_map;
- std::vector<int> axis_value;
- for (FT_UInt axisIndex = 0; axisIndex < mmvar->num_axis; ++axisIndex) {
-
- const FT_Var_Axis& ftAxis = mmvar->axis[axisIndex];
- const FT_Tag axisTag = ftAxis.tag;
-
- Glib::ustring axis_name;
- axis_name += (char)(axisTag>>24 & 0xff);
- axis_name += (char)(axisTag>>16 & 0xff);
- axis_name += (char)(axisTag>> 8 & 0xff);
- axis_name += (char)(axisTag & 0xff);
-
- axis_map.insert(std::pair<Glib::ustring, int>(axis_name, axisIndex));
- axis_value.push_back(static_cast<FT_Int32>(ftAxis.def/65536.0));
- }
-
// Get the required values from Pango Font Description
// Need to check format of values from Pango, for the moment accept any format.
Glib::RefPtr<Glib::Regex> regex = Glib::Regex::create("(\\w{4})=([-+]?\\d*\\.?\\d+([eE][-+]?\\d+)?)");
Glib::MatchInfo matchInfo;
+ const FT_UInt num_axis = openTypeVarAxes.size();
+ FT_Fixed w[num_axis];
+ for (int i = 0; i < num_axis; ++i) w[i] = 0;
+
std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(",", variations);
for (auto token: tokens) {
regex->match(token, matchInfo);
if (matchInfo.matches()) {
+
float value = std::stod(matchInfo.fetch(2)); // Should clamp value
- auto it = axis_map.find(matchInfo.fetch(1));
- if (it != axis_map.end()) {
- axis_value[it->second] = value;
+ // Translate the "named" axes.
+ Glib::ustring name = matchInfo.fetch(1);
+ if (name == "wdth") name = "Width" ; // 'font-stretch'
+ if (name == "wght") name = "Weight" ; // 'font-weight'
+ if (name == "opsz") name = "Optical size"; // 'font-optical-sizing'
+ if (name == "slnt") name = "Slant" ; // 'font-style'
+ if (name == "ital") name = "Italic" ; // 'font-style'
+
+ auto it = openTypeVarAxes.find(name);
+ if (it != openTypeVarAxes.end()) {
+ it->second.set_val = value;
+ w[it->second.index] = value * 65536;
}
}
}
- // Fill coordinate array
- const FT_UInt num_axis = axis_map.size();
- FT_Fixed w[num_axis];
- for (FT_UInt axisIndex = 0; axisIndex < num_axis; ++axisIndex) {
- w[axisIndex] = axis_value[axisIndex] * 65536;
- }
-
// Set design coordinates
FT_Error err;
- err = FT_Set_Var_Design_Coordinates (theFace, 2, w);
+ err = FT_Set_Var_Design_Coordinates (theFace, num_axis, w);
if (err) {
- std::cout << "font_instance::InitTheFace(): Error in call to FT_Set_Var_Design_Coordinates(): " << err << std::endl;
+ std::cerr << "font_instance::InitTheFace(): Error in call to FT_Set_Var_Design_Coordinates(): " << err << std::endl;
}
// FT_Done_MM_Var(mmlib, mmvar);
diff --git a/src/libnrtype/OpenTypeUtil.cpp b/src/libnrtype/OpenTypeUtil.cpp
index 5324392d9..a2506e1d7 100644
--- a/src/libnrtype/OpenTypeUtil.cpp
+++ b/src/libnrtype/OpenTypeUtil.cpp
@@ -222,8 +222,7 @@ void readOpenTypeGsubTable (const FT_Face ft_face,
hb_face_destroy (hb_face);
}
-// Make a list of all Variaration axes with ranges.
-// Make a list of all Named instances with axis values.
+// Make a list of all Variation axes with ranges.
void readOpenTypeFvarAxes(const FT_Face ft_face,
std::map<Glib::ustring, OTVarAxis>& axes) {
@@ -241,7 +240,8 @@ void readOpenTypeFvarAxes(const FT_Face ft_face,
FT_Var_Axis* axis = &mmvar->axis[i];
axes[axis->name] = OTVarAxis(FTFixedToDouble(axis->minimum),
FTFixedToDouble(axis->maximum),
- FTFixedToDouble(coords[i]));
+ FTFixedToDouble(coords[i]),
+ i);
}
// for (auto a: axes) {
diff --git a/src/libnrtype/OpenTypeUtil.h b/src/libnrtype/OpenTypeUtil.h
index 59ffe0045..48d97b0f7 100644
--- a/src/libnrtype/OpenTypeUtil.h
+++ b/src/libnrtype/OpenTypeUtil.h
@@ -20,20 +20,23 @@
// 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;
+public:
+ OTVarAxis()
+ : minimum(0)
+ , maximum(1000)
+ , set_val(500)
+ , index(-1) {};
+
+ OTVarAxis(double _minimum, double _maximum, double _set_val, int _index)
+ : minimum(_minimum)
+ , maximum(_maximum)
+ , set_val(_set_val)
+ , index (_index) {};
+
+ double minimum;
+ double maximum;
+ double set_val;
+ int index; // Index in OpenType file (since we use a map).
};
// A particular instance of a variable font.