summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-04-26 08:42:21 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-04-26 08:42:21 +0000
commit8d6e6db37f2fb58d4f3cfe8ca2827c0c4ae6c006 (patch)
tree5d1b0110905cef04cc1078378d05011558c72389 /src
parentCMake: put policies at the top before running any other code (diff)
downloadinkscape-8d6e6db37f2fb58d4f3cfe8ca2827c0c4ae6c006.tar.gz
inkscape-8d6e6db37f2fb58d4f3cfe8ca2827c0c4ae6c006.zip
Add start of 'font-variations' widget.
Some code cleanup.
Diffstat (limited to 'src')
-rw-r--r--src/libnrtype/FontFactory.cpp4
-rw-r--r--src/libnrtype/OpenTypeUtil.cpp42
-rw-r--r--src/libnrtype/OpenTypeUtil.h14
-rw-r--r--src/libnrtype/font-instance.h11
-rw-r--r--src/ui/CMakeLists.txt2
-rw-r--r--src/ui/dialog/text-edit.cpp3
-rw-r--r--src/ui/dialog/text-edit.h2
-rw-r--r--src/ui/widget/font-variations.cpp132
-rw-r--r--src/ui/widget/font-variations.h102
9 files changed, 291 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);
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index 75f84e429..42ecab427 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -140,6 +140,7 @@ set(ui_SRC
widget/font-selector.cpp
widget/font-selector-toolbar.cpp
widget/font-variants.cpp
+ widget/font-variations.cpp
widget/frame.cpp
widget/highlight-picker.cpp
widget/imageicon.cpp
@@ -336,6 +337,7 @@ set(ui_SRC
widget/font-selector.h
widget/font-selector-toolbar.h
widget/font-variants.h
+ widget/font-variations.h
widget/frame.h
widget/highlight-picker.h
widget/insertordericon.h
diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp
index d283e6549..430d2c114 100644
--- a/src/ui/dialog/text-edit.cpp
+++ b/src/ui/dialog/text-edit.cpp
@@ -94,8 +94,10 @@ TextEdit::TextEdit()
preview_label.set_line_wrap (false);
font_vbox.pack_start(font_selector, true, true);
+ font_vbox.pack_start(font_variations, false, false);
font_vbox.pack_start(preview_label, false, false, 5);
+
/* Text tab -------------------------------- */
scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
scroller.set_shadow_type(Gtk::SHADOW_IN);
@@ -268,6 +270,7 @@ void TextEdit::onReadSelection ( gboolean dostyle, gboolean /*docontent*/ )
int result_features =
sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTFEATURESETTINGS);
vari_vbox.update( &query, result_features == QUERY_STYLE_MULTIPLE_DIFFERENT, fontspec );
+ font_variations.update ( query, result_features == QUERY_STYLE_MULTIPLE_DIFFERENT, fontspec );
}
blocked = false;
diff --git a/src/ui/dialog/text-edit.h b/src/ui/dialog/text-edit.h
index e891c8e42..43b3b281d 100644
--- a/src/ui/dialog/text-edit.h
+++ b/src/ui/dialog/text-edit.h
@@ -33,6 +33,7 @@
#include "ui/widget/font-selector.h"
#include "ui/widget/font-variants.h"
+#include "ui/widget/font-variations.h"
class SPItem;
struct SPFontSelector;
@@ -165,6 +166,7 @@ private:
Gtk::Label font_label;
Inkscape::UI::Widget::FontSelector font_selector;
+ Inkscape::UI::Widget::FontVariations font_variations;
Gtk::Label preview_label; // Share with variants tab?
// Tab 2: Text ---------------------- //
diff --git a/src/ui/widget/font-variations.cpp b/src/ui/widget/font-variations.cpp
new file mode 100644
index 000000000..84c8e97d9
--- /dev/null
+++ b/src/ui/widget/font-variations.cpp
@@ -0,0 +1,132 @@
+/*
+ * Author:
+ * Felipe Corrêa da Silva Sanches <juca@members.fsf.org>
+ * Tavmjong Bah <tavmjong@free.fr>
+ *
+ * Copyright (C) 2018 Felipe Corrêa da Silva Sanches, Tavmong Bah
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <iostream>
+#include <iomanip>
+
+#include <gtkmm.h>
+#include <glibmm/i18n.h>
+
+#include <libnrtype/font-instance.h>
+
+#include "font-variations.h"
+
+// For updating from selection
+#include "desktop.h"
+#include "object/sp-text.h"
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+FontVariationAxis::FontVariationAxis (Glib::ustring name, OTVarAxis& axis)
+ : name (name)
+{
+ // std::cout << "FontVariationAxis::FontVariationAxis:: name: " << name << std::endl;
+ label = Gtk::manage( new Gtk::Label( name ) );
+ add( *label );
+
+ precision = 2 - int( log10(axis.maximum - axis.minimum));
+
+ scale = Gtk::manage( new Gtk::Scale() );
+ scale->set_range (axis.minimum, axis.maximum);
+ scale->set_value (axis.set_val);
+ scale->set_digits (precision);
+ scale->set_hexpand(true);
+ add( *scale );
+
+ show_all_children();
+}
+
+// ------------------------------------------------------------- //
+
+FontVariations::FontVariations () :
+ Gtk::Grid ()
+{
+ // std::cout << "FontVariations::FontVariations" << std::endl;
+ set_orientation( Gtk::ORIENTATION_VERTICAL );
+ set_name ("FontVariations");
+ size_group = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_HORIZONTAL);
+ show_all_children();
+}
+
+
+// Update GUI based on query.
+void
+FontVariations::update( const SPStyle& query, bool different_features, Glib::ustring& font_spec ) {
+
+ font_instance* res = font_factory::Default()->FaceFromFontSpecification (font_spec.c_str());
+
+ auto children = get_children();
+ for (auto child: children) {
+ remove ( *child );
+ }
+ axes.clear();
+
+ for (auto a: res->openTypeVarAxes) {
+ // std::cout << "Creating axis: " << a.first << std::endl;
+ FontVariationAxis* axis = Gtk::manage( new FontVariationAxis( a.first, a.second ));
+ axes.push_back( axis );
+ add( *axis );
+ size_group->add_widget( *(axis->get_label()) ); // Keep labels the same width
+ }
+
+ show_all_children();
+}
+
+void
+FontVariations::fill_css( SPCSSAttr *css ) {
+ std::cout << "FontVariations::fill_css" << std::endl;
+
+ // Eventually will want to favor using 'font-weight', etc. but at the moment these
+ // can't handle "fractional" values. See CSS Fonts Module Level 4.
+ sp_repr_css_set_property(css, "font-variation-settings", get_css_string().c_str());
+}
+
+Glib::ustring
+FontVariations::get_css_string() {
+
+ Glib::ustring css_string;
+
+ for (auto axis: axes) {
+ Glib::ustring name = axis->get_name();
+
+ // Translate the "named" axes. (Additional names in 'stat' table, may need to handle them.)
+ if (name == "Width") name = "wdth"; // 'font-stretch'
+ if (name == "Weight") name = "wght"; // 'font-weight'
+ if (name == "Optical size") name = "opsz"; // 'font-optical-sizing' Can trigger glyph substition.
+ if (name == "Slant") name = "slnt"; // 'font-style'
+ if (name == "Italic") name = "ital"; // 'font-style' Toggles from Roman to Italic.
+
+ std::stringstream value;
+ value << std::setprecision(axis->get_precision()) << axis->get_value();
+ css_string += "'" + name + "' " + value.str() + "', ";
+ }
+ std::cout << " css_string: |" << css_string << "|" << std::endl;
+}
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/ui/widget/font-variations.h b/src/ui/widget/font-variations.h
new file mode 100644
index 000000000..f91c47ce5
--- /dev/null
+++ b/src/ui/widget/font-variations.h
@@ -0,0 +1,102 @@
+/*
+ * Author:
+ * Felipe Corrêa da Silva Sanches <juca@members.fsf.org>
+ * Tavmjong Bah <tavmjong@free.fr>
+ *
+ * Copyright (C) 2018 Felipe Corrêa da Silva Sanches, Tavmong Bah
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifndef INKSCAPE_UI_WIDGET_FONT_VARIATIONS_H
+#define INKSCAPE_UI_WIDGET_FONT_VARIATIONS_H
+
+#include <gtkmm/grid.h>
+#include <gtkmm/sizegroup.h>
+#include <gtkmm/label.h>
+#include <gtkmm/scale.h>
+
+#include "libnrtype/OpenTypeUtil.h"
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+
+/**
+ * A widget for a single axis.
+ */
+class FontVariationAxis : public Gtk::Grid
+{
+public:
+ FontVariationAxis(Glib::ustring name, OTVarAxis& axis);
+ Glib::ustring get_name() { return name; }
+ Gtk::Label* get_label() { return label; }
+ double get_value() { return scale->get_value(); }
+ int get_precision() { return precision; }
+
+private:
+
+ Glib::ustring name;
+ Gtk::Label* label;
+ Gtk::Scale* scale;
+ int precision;
+ sigc::connection _changed_connection;
+
+
+};
+
+/**
+ * A widget for selecting font variations (OpenType Variations).
+ */
+class FontVariations : public Gtk::Grid
+{
+
+public:
+
+ /**
+ * Constructor
+ */
+ FontVariations();
+
+protected:
+
+public:
+
+ /**
+ * Update GUI based on query results.
+ */
+ void update( const SPStyle& query, bool different_features, Glib::ustring& font_spec );
+
+ /**
+ * Fill SPCSSAttr based on settings of buttons.
+ */
+ void fill_css( SPCSSAttr* css );
+
+ /**
+ * Get CSS String
+ */
+ Glib::ustring get_css_string();
+
+private:
+ std::vector<FontVariationAxis*> axes;
+ Glib::RefPtr<Gtk::SizeGroup> size_group;
+};
+
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+#endif // INKSCAPE_UI_WIDGET_FONT_VARIATIONS_H
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :