diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2018-04-29 16:49:03 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2018-04-29 16:49:03 +0000 |
| commit | e393169c252e4e9fb87b87ffc1d32671e3d5c3f2 (patch) | |
| tree | 82dd36438ba161dae60dd041637150f9c7942c33 /src | |
| parent | Update style.css to improve margin and padding in #InkSpinScale (diff) | |
| download | inkscape-e393169c252e4e9fb87b87ffc1d32671e3d5c3f2.tar.gz inkscape-e393169c252e4e9fb87b87ffc1d32671e3d5c3f2.zip | |
Bug fixes for variable fonts, especially to support the Decovar font.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libnrtype/FontFactory.cpp | 9 | ||||
| -rw-r--r-- | src/libnrtype/FontInstance.cpp | 56 | ||||
| -rw-r--r-- | src/libnrtype/OpenTypeUtil.cpp | 6 | ||||
| -rw-r--r-- | src/libnrtype/OpenTypeUtil.h | 31 | ||||
| -rw-r--r-- | src/ui/widget/font-selector.cpp | 9 | ||||
| -rw-r--r-- | src/ui/widget/font-variations.cpp | 13 |
6 files changed, 61 insertions, 63 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. diff --git a/src/ui/widget/font-selector.cpp b/src/ui/widget/font-selector.cpp index 69777f528..ae2707353 100644 --- a/src/ui/widget/font-selector.cpp +++ b/src/ui/widget/font-selector.cpp @@ -244,7 +244,12 @@ FontSelector::get_fontspec() { Glib::ustring variations = font_variations.get_pango_string(); - Glib::ustring fontspec = family + ", " + style + " " + variations; + Glib::ustring fontspec = family + " "; + if (variations.empty()) { + fontspec += style; + } else { + fontspec += variations; + } return fontspec; } @@ -262,7 +267,7 @@ FontSelector::style_cell_data_func (Gtk::CellRenderer *renderer, Gtk::TreeIter c (*iter).get_value(1, style); Glib::ustring style_escaped = Glib::strescape( style ); - Glib::ustring font_desc = family + ", " + style; + Glib::ustring font_desc = family + " " + style; Glib::ustring markup; markup = "<span font='" + font_desc + "'>" + style_escaped + "</span>"; diff --git a/src/ui/widget/font-variations.cpp b/src/ui/widget/font-variations.cpp index d0464e080..9a8317a79 100644 --- a/src/ui/widget/font-variations.cpp +++ b/src/ui/widget/font-variations.cpp @@ -33,11 +33,18 @@ namespace Widget { FontVariationAxis::FontVariationAxis (Glib::ustring name, OTVarAxis& axis) : name (name) { - // std::cout << "FontVariationAxis::FontVariationAxis:: name: " << name << std::endl; + + // std::cout << "FontVariationAxis::FontVariationAxis:: " + // << " name: " << name + // << " min: " << axis.minimum + // << " max: " << axis.maximum + // << " val: " << axis.set_val << std::endl; + label = Gtk::manage( new Gtk::Label( name ) ); add( *label ); - precision = 2 - int( log10(axis.maximum - axis.minimum)); + precision = 2 - int( log10(axis.maximum - axis.minimum)); + if (precision < 0) precision = 0; scale = Gtk::manage( new Gtk::Scale() ); scale->set_range (axis.minimum, axis.maximum); @@ -129,7 +136,7 @@ FontVariations::get_pango_string() { pango_string += "@"; for (auto axis: axes) { - if (axis->get_value() == 0) continue; // TEMP ************* + if (axis->get_value() == 0) continue; // TEMP: Should check against default value. Glib::ustring name = axis->get_name(); // Translate the "named" axes. (Additional names in 'stat' table, may need to handle them.) |
