summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-06-02 08:17:42 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-06-02 08:17:42 +0000
commitcdbb3d3ee1e1ba05f4313d0a1298db4ffa5ff7f9 (patch)
treead6e94ae08843cf14129aeb648fc625a0a99ab23 /src/ui/dialog
parentPrevent seg fault if value is null. (diff)
downloadinkscape-cdbb3d3ee1e1ba05f4313d0a1298db4ffa5ff7f9.tar.gz
inkscape-cdbb3d3ee1e1ba05f4313d0a1298db4ffa5ff7f9.zip
Add preview to Font Features tab of Text and Font dialog.
Diffstat (limited to 'src/ui/dialog')
-rw-r--r--src/ui/dialog/text-edit.cpp65
-rw-r--r--src/ui/dialog/text-edit.h26
2 files changed, 45 insertions, 46 deletions
diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp
index ff97bb68c..1b19f6d02 100644
--- a/src/ui/dialog/text-edit.cpp
+++ b/src/ui/dialog/text-edit.cpp
@@ -65,7 +65,7 @@ TextEdit::TextEdit()
: UI::Widget::Panel("/dialogs/textandfont", SP_VERB_DIALOG_TEXT),
font_label(_("_Font"), true),
text_label(_("_Text"), true),
- vari_label(_("_Features"), true),
+ feat_label(_("_Features"), true),
setasdefault_button(_("Set as _default")),
close_button(_("_Close"), true),
apply_button(_("_Apply"), true),
@@ -96,6 +96,15 @@ TextEdit::TextEdit()
font_vbox.pack_start(font_selector, true, true);
font_vbox.pack_start(preview_label, false, false, 5);
+ /* Features tab ---------------------------- */
+
+ /* Features preview */
+ preview_label2.set_ellipsize (Pango::ELLIPSIZE_END);
+ preview_label2.set_justify (Gtk::JUSTIFY_CENTER);
+ preview_label2.set_line_wrap (false);
+
+ feat_vbox.pack_start(font_features, true, true);
+ feat_vbox.pack_start(preview_label2, false, false, 5);
/* Text tab -------------------------------- */
scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
@@ -127,7 +136,7 @@ TextEdit::TextEdit()
/* Notebook -----------------------------------*/
notebook.set_name( "TextEdit Notebook" );
notebook.append_page(font_vbox, font_label);
- notebook.append_page(vari_vbox, vari_label);
+ notebook.append_page(feat_vbox, feat_label);
notebook.append_page(text_vbox, text_label);
/* Buttons (below notebook) ------------------ */
@@ -149,7 +158,7 @@ TextEdit::TextEdit()
apply_button.signal_clicked().connect(sigc::mem_fun(*this, &TextEdit::onApply));
close_button.signal_clicked().connect(sigc::bind(_signal_response.make_slot(), GTK_RESPONSE_CLOSE));
fontChangedConn = font_selector.connectChanged (sigc::mem_fun(*this, &TextEdit::onFontChange));
- fontVariantChangedConn = vari_vbox.connectChanged(sigc::bind(sigc::ptr_fun(&onFontVariantChange), this));
+ fontFeaturesChangedConn = font_features.connectChanged(sigc::mem_fun(*this, &TextEdit::onChange));
desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &TextEdit::setTargetDesktop) );
deskTrack.connect(GTK_WIDGET(gobj()));
@@ -167,7 +176,7 @@ TextEdit::~TextEdit()
desktopChangeConn.disconnect();
deskTrack.disconnect();
fontChangedConn.disconnect();
- fontVariantChangedConn.disconnect();
+ fontFeaturesChangedConn.disconnect();
}
void TextEdit::onSelectionModified(guint flags )
@@ -260,25 +269,27 @@ void TextEdit::onReadSelection ( gboolean dostyle, gboolean /*docontent*/ )
double size = sp_style_css_size_px_to_units(query.font_size.computed, unit);
font_selector.update_size (size);
- // Update Preview
- setPreviewText (fontspec, phrase);
-
- // Update font variant widget
- //int result_variants =
+ // Update font features (variant) widget
+ //int result_features =
sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTVARIANTS);
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_features.update( &query, result_features == QUERY_STYLE_MULTIPLE_DIFFERENT, fontspec );
+ Glib::ustring features = font_features.get_markup();
+
+ // Update Preview
+ setPreviewText (fontspec, features, phrase);
}
blocked = false;
}
-void TextEdit::setPreviewText (Glib::ustring font_spec, Glib::ustring phrase)
+void TextEdit::setPreviewText (Glib::ustring font_spec, Glib::ustring font_features, Glib::ustring phrase)
{
if (font_spec.empty()) {
preview_label.set_markup("");
+ preview_label2.set_markup("");
return;
}
@@ -295,8 +306,14 @@ void TextEdit::setPreviewText (Glib::ustring font_spec, Glib::ustring phrase)
// Pango font size is in 1024ths of a point
Glib::ustring size = std::to_string( int(pt_size * PANGO_SCALE) );
Glib::ustring markup = "<span font=\'" + font_spec_escaped +
- "\' size=\'" + size + "\'>" + phrase + "</span>";
+ "\' size=\'" + size + "\'";
+ if (!font_features.empty()) {
+ markup += " font_features=\'" + font_features + "\'";
+ }
+ markup += ">" + phrase_escaped + "</span>";
+
preview_label.set_markup (markup);
+ preview_label2.set_markup (markup);
}
@@ -376,8 +393,8 @@ SPCSSAttr *TextEdit::fillTextStyle ()
sp_repr_css_set_property (css, "font-size", os.str().c_str());
}
- // Font variants (Font features)
- vari_vbox.fill_css( css );
+ // Font features
+ font_features.fill_css( css );
return css;
}
@@ -450,21 +467,22 @@ void TextEdit::onChange()
return;
}
- SPItem *text = getSelectedTextItem();
-
GtkTextIter start;
GtkTextIter end;
gtk_text_buffer_get_bounds (text_buffer, &start, &end);
gchar *str = gtk_text_buffer_get_text(text_buffer, &start, &end, TRUE);
Glib::ustring fontspec = font_selector.get_fontspec();
+ Glib::ustring features = font_features.get_markup();
const gchar *phrase = str && *str ? str : samplephrase.c_str();
- setPreviewText(fontspec, phrase);
+ setPreviewText(fontspec, features, phrase);
g_free (str);
+ SPItem *text = getSelectedTextItem();
if (text) {
apply_button.set_sensitive ( true );
}
+
setasdefault_button.set_sensitive ( true);
}
@@ -478,19 +496,6 @@ void TextEdit::onFontChange(Glib::ustring fontspec)
onChange();
}
-void TextEdit::onFontVariantChange(TextEdit *self)
-{
- if( self->blocked )
- return;
-
- SPItem *text = self->getSelectedTextItem ();
-
- if (text) {
- self->apply_button.set_sensitive ( true );
- }
- self->setasdefault_button.set_sensitive ( true );
-}
-
void TextEdit::setDesktop(SPDesktop *desktop)
{
Panel::setDesktop(desktop);
diff --git a/src/ui/dialog/text-edit.h b/src/ui/dialog/text-edit.h
index ac99b28db..b0ebfe347 100644
--- a/src/ui/dialog/text-edit.h
+++ b/src/ui/dialog/text-edit.h
@@ -108,15 +108,6 @@ protected:
void onFontChange (Glib::ustring fontspec);
/**
- * Callback invoked when the user modifies the font variant through the dialog.
- *
- * onFontChange updates the dialog UI. The subfunction setPreviewText updates the preview label.
- *
- * @param self pointer to the current instance of the dialog.
- */
- static void onFontVariantChange (TextEdit *self);
-
- /**
* Get the selected text off the main canvas.
*
* @return SPItem pointer to the selected text object
@@ -131,10 +122,11 @@ protected:
/**
* Helper function to create markup from a fontspec and display in the preview label.
*
- * @param fontspec for the text to be previewed
- * @param phrase text to be shown
+ * @param fontspec for the text to be previewed.
+ * @param font_features for text to be previewed (in CSS format).
+ * @param phrase text to be shown.
*/
- void setPreviewText (Glib::ustring font_spec, Glib::ustring phrase);
+ void setPreviewText (Glib::ustring font_spec, Glib::ustring font_features, Glib::ustring phrase);
void updateObjectText ( SPItem *text );
SPCSSAttr *fillTextStyle ();
@@ -176,9 +168,11 @@ private:
GtkWidget *text_view; // TODO - Convert this to a Gtk::TextView, but GtkSpell doesn't seem to work with it
GtkTextBuffer *text_buffer;
- // Tab 3: Variants ----------------- //
- Inkscape::UI::Widget::FontVariants vari_vbox;
- Gtk::Label vari_label;
+ // Tab 3: Features ----------------- //
+ Gtk::VBox feat_vbox;
+ Inkscape::UI::Widget::FontVariants font_features;
+ Gtk::Label feat_label;
+ Gtk::Label preview_label2; // Could reparent preview_label but having a second label is probably easier.
// Shared ------- ------------------ //
Gtk::HBox button_row;
@@ -194,7 +188,7 @@ private:
sigc::connection subselChangedConn;
sigc::connection selectModifiedConn;
sigc::connection fontChangedConn;
- sigc::connection fontVariantChangedConn;
+ sigc::connection fontFeaturesChangedConn;
// Other
bool blocked;