summaryrefslogtreecommitdiffstats
path: root/src/ui/widget
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-04-28 10:48:20 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-04-28 10:48:20 +0000
commit2cbcb87564d476c1729e6e60e9ae73f7d521b000 (patch)
treeda40a50373336190e736db51d9fe74c985c60510 /src/ui/widget
parentAllow FER edition on canvas (diff)
downloadinkscape-2cbcb87564d476c1729e6e60e9ae73f7d521b000.tar.gz
inkscape-2cbcb87564d476c1729e6e60e9ae73f7d521b000.zip
More progress on variable fonts support.
Diffstat (limited to 'src/ui/widget')
-rw-r--r--src/ui/widget/font-selector.cpp30
-rw-r--r--src/ui/widget/font-selector.h10
-rw-r--r--src/ui/widget/font-variations.cpp56
-rw-r--r--src/ui/widget/font-variations.h36
4 files changed, 111 insertions, 21 deletions
diff --git a/src/ui/widget/font-selector.cpp b/src/ui/widget/font-selector.cpp
index fcc51ddd1..69777f528 100644
--- a/src/ui/widget/font-selector.cpp
+++ b/src/ui/widget/font-selector.cpp
@@ -80,6 +80,9 @@ FontSelector::FontSelector (bool with_size)
set_sizes();
size_combobox.set_active_text( "18" );
+ // Font Variations
+ // Do nothing.
+
// Grid
set_name ("FontSelector: Grid");
attach (family_frame, 0, 0, 1, 2);
@@ -88,12 +91,14 @@ FontSelector::FontSelector (bool with_size)
attach (size_label, 1, 1, 1, 1);
attach (size_combobox, 2, 1, 1, 1);
}
+ attach (font_variations, 0, 2, 3, 1);
// Add signals
family_treeview.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &FontSelector::on_family_changed));
style_treeview.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &FontSelector::on_style_changed));
size_combobox.signal_changed().connect(sigc::mem_fun(*this, &FontSelector::on_size_changed));
-
+ font_variations.connectChanged(sigc::mem_fun(*this, &FontSelector::on_variations_changed));
+
show_all_children();
// Initialize font family lists. (May already be done.) Should be done on document change.
@@ -186,6 +191,9 @@ FontSelector::update_font ()
style_treeview.get_selection()->select (match);
}
+ Glib::ustring fontspec = font_lister->get_fontspec();
+ font_variations.update( fontspec );
+
signal_block = false;
}
@@ -229,7 +237,14 @@ FontSelector::get_fontspec() {
std::cerr << "FontSelector::get_fontspec: empty style!" << std::endl;
}
- Glib::ustring fontspec = family + ", " + style;
+ // Clip any font_variation data in 'style' as we'll replace it.
+ if (auto pos = style.find('@') != Glib::ustring::npos) {
+ style.erase (pos, style.length()-1);
+ }
+
+ Glib::ustring variations = font_variations.get_pango_string();
+
+ Glib::ustring fontspec = family + ", " + style + " " + variations;
return fontspec;
}
@@ -364,9 +379,18 @@ FontSelector::on_size_changed() {
}
void
+FontSelector::on_variations_changed() {
+
+ if (signal_block) return;
+
+ // Let world know
+ changed_emit();
+}
+
+void
FontSelector::changed_emit() {
signal_block = true;
- changed_signal.emit (get_fontspec());
+ signal_changed.emit (get_fontspec());
signal_block = false;
}
diff --git a/src/ui/widget/font-selector.h b/src/ui/widget/font-selector.h
index 7578dc693..956d2e83b 100644
--- a/src/ui/widget/font-selector.h
+++ b/src/ui/widget/font-selector.h
@@ -35,6 +35,8 @@
#include <gtkmm/label.h>
#include <gtkmm/comboboxtext.h>
+#include "ui/widget/font-variations.h"
+
namespace Inkscape {
namespace UI {
namespace Widget {
@@ -84,6 +86,9 @@ protected:
Gtk::Label size_label;
Gtk::ComboBoxText size_combobox;
+ // Font variations
+ FontVariations font_variations;
+
private:
// Set sizes in font size combobox.
@@ -97,9 +102,10 @@ private:
void on_family_changed();
void on_style_changed();
void on_size_changed();
+ void on_variations_changed();
// Signals
- sigc::signal<void, Glib::ustring> changed_signal;
+ sigc::signal<void, Glib::ustring> signal_changed;
void changed_emit();
bool signal_block;
@@ -137,7 +143,7 @@ public:
* (Used to enable 'Apply' and 'Default' buttons.)
*/
sigc::connection connectChanged(sigc::slot<void, Glib::ustring> slot) {
- return changed_signal.connect(slot);
+ return signal_changed.connect(slot);
}
};
diff --git a/src/ui/widget/font-variations.cpp b/src/ui/widget/font-variations.cpp
index 84c8e97d9..d0464e080 100644
--- a/src/ui/widget/font-variations.cpp
+++ b/src/ui/widget/font-variations.cpp
@@ -45,10 +45,9 @@ FontVariationAxis::FontVariationAxis (Glib::ustring name, OTVarAxis& axis)
scale->set_digits (precision);
scale->set_hexpand(true);
add( *scale );
-
- show_all_children();
}
+
// ------------------------------------------------------------- //
FontVariations::FontVariations () :
@@ -64,7 +63,7 @@ FontVariations::FontVariations () :
// Update GUI based on query.
void
-FontVariations::update( const SPStyle& query, bool different_features, Glib::ustring& font_spec ) {
+FontVariations::update (Glib::ustring& font_spec) {
font_instance* res = font_factory::Default()->FaceFromFontSpecification (font_spec.c_str());
@@ -80,6 +79,9 @@ FontVariations::update( const SPStyle& query, bool different_features, Glib::ust
axes.push_back( axis );
add( *axis );
size_group->add_widget( *(axis->get_label()) ); // Keep labels the same width
+ axis->get_scale()->signal_value_changed().connect(
+ sigc::mem_fun(*this, &FontVariations::on_variations_change)
+ );
}
show_all_children();
@@ -110,12 +112,50 @@ FontVariations::get_css_string() {
if (name == "Italic") name = "ital"; // 'font-style' Toggles from Roman to Italic.
std::stringstream value;
- value << std::setprecision(axis->get_precision()) << axis->get_value();
+ value << std::fixed << std::setprecision(axis->get_precision()) << axis->get_value();
css_string += "'" + name + "' " + value.str() + "', ";
}
- std::cout << " css_string: |" << css_string << "|" << std::endl;
+
+ return css_string;
+}
+
+Glib::ustring
+FontVariations::get_pango_string() {
+
+ Glib::ustring pango_string;
+
+ if (!axes.empty()) {
+
+ pango_string += "@";
+
+ for (auto axis: axes) {
+ if (axis->get_value() == 0) continue; // TEMP *************
+ 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::fixed << std::setprecision(axis->get_precision()) << axis->get_value();
+ pango_string += name + "=" + value.str() + ",";
+ }
+
+ pango_string.erase (pango_string.size() - 1); // Erase last ','
+ }
+
+ return pango_string;
}
-
+
+void
+FontVariations::on_variations_change() {
+ // std::cout << "FontVariations::on_variations_change: " << get_css_string() << std::endl;;
+ signal_changed.emit ();
+}
+
} // namespace Widget
} // namespace UI
} // namespace Inkscape
@@ -124,9 +164,9 @@ FontVariations::get_css_string() {
Local Variables:
mode:c++
c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0))
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 :
diff --git a/src/ui/widget/font-variations.h b/src/ui/widget/font-variations.h
index f91c47ce5..594df217d 100644
--- a/src/ui/widget/font-variations.h
+++ b/src/ui/widget/font-variations.h
@@ -18,13 +18,15 @@
#include "libnrtype/OpenTypeUtil.h"
+#include "style.h"
+
namespace Inkscape {
namespace UI {
namespace Widget {
/**
- * A widget for a single axis.
+ * A widget for a single axis: Label and Slider
*/
class FontVariationAxis : public Gtk::Grid
{
@@ -34,16 +36,19 @@ public:
Gtk::Label* get_label() { return label; }
double get_value() { return scale->get_value(); }
int get_precision() { return precision; }
+ Gtk::Scale* get_scale() { return scale; }
private:
+ // Widgets
Glib::ustring name;
Gtk::Label* label;
Gtk::Scale* scale;
- int precision;
- sigc::connection _changed_connection;
+ int precision;
+ // Signals
+ sigc::signal<void> signal_changed;
};
/**
@@ -64,9 +69,9 @@ protected:
public:
/**
- * Update GUI based on query results.
+ * Update GUI.
*/
- void update( const SPStyle& query, bool different_features, Glib::ustring& font_spec );
+ void update( Glib::ustring& font_spec );
/**
* Fill SPCSSAttr based on settings of buttons.
@@ -78,9 +83,24 @@ public:
*/
Glib::ustring get_css_string();
+ Glib::ustring get_pango_string();
+
+ void on_variations_change();
+
+ /**
+ * Let others know that user has changed GUI settings.
+ * (Used to enable 'Apply' and 'Default' buttons.)
+ */
+ sigc::connection connectChanged(sigc::slot<void> slot) {
+ return signal_changed.connect(slot);
+ }
+
private:
+
std::vector<FontVariationAxis*> axes;
Glib::RefPtr<Gtk::SizeGroup> size_group;
+
+ sigc::signal<void> signal_changed;
};
@@ -90,13 +110,13 @@ private:
#endif // INKSCAPE_UI_WIDGET_FONT_VARIATIONS_H
-/*
+/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0))
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 :