summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/font-variations.cpp
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/font-variations.cpp
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/font-variations.cpp')
-rw-r--r--src/ui/widget/font-variations.cpp56
1 files changed, 48 insertions, 8 deletions
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 :