diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2018-06-02 08:17:42 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2018-06-02 08:17:42 +0000 |
| commit | cdbb3d3ee1e1ba05f4313d0a1298db4ffa5ff7f9 (patch) | |
| tree | ad6e94ae08843cf14129aeb648fc625a0a99ab23 /src | |
| parent | Prevent seg fault if value is null. (diff) | |
| download | inkscape-cdbb3d3ee1e1ba05f4313d0a1298db4ffa5ff7f9.tar.gz inkscape-cdbb3d3ee1e1ba05f4313d0a1298db4ffa5ff7f9.zip | |
Add preview to Font Features tab of Text and Font dialog.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/dialog/text-edit.cpp | 65 | ||||
| -rw-r--r-- | src/ui/dialog/text-edit.h | 26 | ||||
| -rw-r--r-- | src/ui/widget/font-variants.cpp | 74 | ||||
| -rw-r--r-- | src/ui/widget/font-variants.h | 7 |
4 files changed, 119 insertions, 53 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; diff --git a/src/ui/widget/font-variants.cpp b/src/ui/widget/font-variants.cpp index ad7431bd3..72e67f88b 100644 --- a/src/ui/widget/font-variants.cpp +++ b/src/ui/widget/font-variants.cpp @@ -116,9 +116,9 @@ namespace Widget { _position_super.set_group(position_group); // Add signals - _position_normal.signal_button_press_event().connect ( sigc::mem_fun(*this, &FontVariants::position_callback) ); - _position_sub.signal_button_press_event().connect ( sigc::mem_fun(*this, &FontVariants::position_callback) ); - _position_super.signal_button_press_event().connect ( sigc::mem_fun(*this, &FontVariants::position_callback) ); + _position_normal.signal_clicked().connect ( sigc::mem_fun(*this, &FontVariants::position_callback) ); + _position_sub.signal_clicked().connect ( sigc::mem_fun(*this, &FontVariants::position_callback) ); + _position_super.signal_clicked().connect ( sigc::mem_fun(*this, &FontVariants::position_callback) ); // Add to frame _position_vbox.pack_start( _position_normal); @@ -285,12 +285,11 @@ namespace Widget { // std::cout << "FontVariants::position_init()" << std::endl; } - bool - FontVariants::position_callback(GdkEventButton * /*event*/) { + void + FontVariants::position_callback() { // std::cout << "FontVariants::position_callback()" << std::endl; _position_changed = true; _changed_signal.emit(); - return true; } void @@ -828,6 +827,69 @@ namespace Widget { } } + Glib::ustring + FontVariants::get_markup() { + + Glib::ustring markup; + + // Ligatures + bool common = _ligatures_common.get_active(); + bool discretionary = _ligatures_discretionary.get_active(); + bool historical = _ligatures_historical.get_active(); + bool contextual = _ligatures_contextual.get_active(); + + if (!common) markup += "liga=0,clig=0,"; // On by default. + if (discretionary) markup += "dlig=1,"; + if (historical) markup += "hlig=1,"; + if (contextual) markup += "calt=1,"; + + // Position + if ( _position_sub.get_active() ) markup += "subs=1,"; + else if ( _position_super.get_active() ) markup += "sups=1,"; + + // Caps + if ( _caps_small.get_active() ) markup += "smcp=1,"; + else if ( _caps_all_small.get_active() ) markup += "c2sc=1,smcp=1,"; + else if ( _caps_petite.get_active() ) markup += "pcap=1,"; + else if ( _caps_all_petite.get_active() ) markup += "c2pc=1,pcap=1,"; + else if ( _caps_unicase.get_active() ) markup += "unic=1,"; + else if ( _caps_titling.get_active() ) markup += "titl=1,"; + + // Numeric + bool default_style = _numeric_default_style.get_active(); + bool lining = _numeric_lining.get_active(); + bool old_style = _numeric_old_style.get_active(); + + bool default_width = _numeric_default_width.get_active(); + bool proportional = _numeric_proportional.get_active(); + bool tabular = _numeric_tabular.get_active(); + + bool default_fractions = _numeric_default_fractions.get_active(); + bool diagonal = _numeric_diagonal.get_active(); + bool stacked = _numeric_stacked.get_active(); + + bool ordinal = _numeric_ordinal.get_active(); + bool slashed_zero = _numeric_slashed_zero.get_active(); + + if (lining) markup += "lnum=1,"; + if (old_style) markup += "onum=1,"; + if (proportional) markup += "pnum=1,"; + if (tabular) markup += "tnum=1,"; + if (diagonal) markup += "frac=1,"; + if (stacked) markup += "afrc=1,"; + if (ordinal) markup += "ordn=1,"; + if (slashed_zero) markup += "zero=1,"; + + // Feature settings + Glib::ustring feature_string = _feature_entry.get_text(); + if( !feature_string.empty() && feature_string.compare( "normal" ) != 0 ) { + markup += feature_string; + } + + // std::cout << "|" << markup << "|" << std::endl; + return markup; + } + } // namespace Widget } // namespace UI } // namespace Inkscape diff --git a/src/ui/widget/font-variants.h b/src/ui/widget/font-variants.h index 36e955890..023bc8ef2 100644 --- a/src/ui/widget/font-variants.h +++ b/src/ui/widget/font-variants.h @@ -110,7 +110,7 @@ private: void ligatures_callback(); void position_init(); - bool position_callback(GdkEventButton *event); + void position_callback(); void caps_init(); void caps_callback(); @@ -153,6 +153,11 @@ public: void fill_css( SPCSSAttr* css ); /** + * Get CSS string for markup. + */ + Glib::ustring get_markup(); + + /** * Let others know that user has changed GUI settings. * (Used to enable 'Apply' and 'Default' buttons.) */ |
