=== modified file 'src/ui/dialog/inkscape-preferences.cpp' --- src/ui/dialog/inkscape-preferences.cpp 2015-11-01 12:50:42 +0000 +++ src/ui/dialog/inkscape-preferences.cpp 2015-11-01 22:28:09 +0000 @@ -2112,6 +2112,11 @@ _page_title.set_markup("" + col_name_escaped + ""); _page_frame.add(*_current_page); _current_page->show(); + if(row[_page_list_columns._col_id] == PREFS_PAGE_TOOLS_TEXT){ + Glib::ustring sizeLabels[] = {_("Pixel"), _("Point"), _("Pica"), _("Millimeter"), _("Centimeter"), _("Inch"), _("Em square")/*, _("Ex square"), _("Percent")*/}; + int sizeValues[] = {SP_CSS_UNIT_PX, SP_CSS_UNIT_PT, SP_CSS_UNIT_PC, SP_CSS_UNIT_MM, SP_CSS_UNIT_CM, SP_CSS_UNIT_IN, SP_CSS_UNIT_EM/*, SP_CSS_UNIT_EX, SP_CSS_UNIT_PERCENT*/}; + _font_unit_type.init( "/options/font/unitType", sizeLabels, sizeValues, G_N_ELEMENTS(sizeLabels), SP_CSS_UNIT_PT ); + } while (Gtk::Main::events_pending()) { Gtk::Main::iteration(); === modified file 'src/widgets/font-selector.cpp' --- src/widgets/font-selector.cpp 2014-10-17 20:03:14 +0000 +++ src/widgets/font-selector.cpp 2015-11-03 00:22:59 +0000 @@ -27,7 +27,7 @@ #include #include - +#include "util/units.h" #include "desktop.h" #include "widgets/font-selector.h" #include "preferences.h" @@ -47,6 +47,7 @@ GtkWidget *family; GtkWidget *style; GtkWidget *size; + GtkWidget *fontunit; GtkWidget *family_treeview; GtkWidget *style_treeview; @@ -86,6 +87,9 @@ static void sp_font_selector_size_changed (GtkComboBox *combobox, SPFontSelector *fsel); +static void sp_font_selector_unit_changed (GtkComboBox *combobox, + SPFontSelector *fsel); + static void sp_font_selector_emit_set (SPFontSelector *fsel); static void sp_font_selector_set_sizes( SPFontSelector *fsel ); @@ -116,11 +120,19 @@ static void sp_font_selector_set_size_tooltip(SPFontSelector *fsel) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT); + int unit = prefs->getInt("/options/font/unitTypeWidget", prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT)); Glib::ustring tooltip = Glib::ustring::format(_("Font size"), " (", sp_style_get_css_unit_string(unit), ")"); gtk_widget_set_tooltip_text (fsel->size, _(tooltip.c_str())); } +static void sp_font_selector_set_unit_tooltip(SPFontSelector *fsel) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + int unit = prefs->getInt("/options/font/unitTypeWidget", prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT)); + Glib::ustring tooltip = Glib::ustring::format(_("Units"), " (", sp_style_get_css_unit_string(unit), ")"); + gtk_widget_set_tooltip_text (fsel->size, _(tooltip.c_str())); +} + /* * Create a widget with children for selecting font-family, font-style, and font-size. @@ -229,6 +241,33 @@ gtk_widget_show(hb); gtk_box_pack_start(GTK_BOX(vb), hb, FALSE, FALSE, 0); + //Font-units + // List of font sizes for drop-down menu + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT); + prefs->setInt("/options/font/unitTypeWidget", unit); + // List of font sizes for drop-down menu + int units[] = {SP_CSS_UNIT_PX, SP_CSS_UNIT_PT, SP_CSS_UNIT_PC, SP_CSS_UNIT_MM, SP_CSS_UNIT_CM, SP_CSS_UNIT_IN/*, SP_CSS_UNIT_EM, SP_CSS_UNIT_EX, SP_CSS_UNIT_PERCENT*/}; + + GtkTreeIter iter; + GtkListStore *storeunits = gtk_list_store_new(1,G_TYPE_STRING); + for( unsigned int i = 0; i < G_N_ELEMENTS(units); ++i ) { + gtk_list_store_append(storeunits,&iter); + gtk_list_store_set(storeunits,&iter,0,sp_style_get_css_unit_string(units[i]),-1); + } + fsel->fontunit = gtk_combo_box_new_with_model(GTK_TREE_MODEL(storeunits)); + sp_font_selector_set_unit_tooltip(fsel); + g_object_unref(storeunits); + GtkCellRenderer *combocell = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start( GTK_CELL_LAYOUT(fsel->fontunit), combocell, TRUE ); + gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT(fsel->fontunit), combocell, "text", 0, NULL ); + g_signal_connect (G_OBJECT(fsel->fontunit), "changed", G_CALLBACK (sp_font_selector_unit_changed), fsel); + gtk_box_pack_end (GTK_BOX(hb), fsel->fontunit, FALSE, FALSE, 0); + + gtk_combo_box_set_active(GTK_COMBO_BOX(fsel->fontunit), (gint)unit - 1); + + gtk_widget_show_all (fsel->fontunit); + // Font-size fsel->size = gtk_combo_box_text_new_with_entry (); @@ -251,6 +290,7 @@ fsel->fontsize_dirty = false; fsel->fontspec = new Glib::ustring; + } static void sp_font_selector_dispose(GObject *object) @@ -407,6 +447,33 @@ sp_font_selector_emit_set (fsel); } +// Callback when unit changed +static void sp_font_selector_unit_changed( GtkComboBox */*cbox*/, SPFontSelector *fsel ) +{ + SPCSSUnit unit = (SPCSSUnit)gtk_combo_box_get_active(GTK_COMBO_BOX (fsel->fontunit)); + int units[] = {SP_CSS_UNIT_PX, SP_CSS_UNIT_PT, SP_CSS_UNIT_PC, SP_CSS_UNIT_MM, SP_CSS_UNIT_CM, SP_CSS_UNIT_IN/*, SP_CSS_UNIT_EM, SP_CSS_UNIT_EX, SP_CSS_UNIT_PERCENT*/}; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + SPCSSUnit previousUnitCss = (SPCSSUnit)prefs->getInt("/options/font/unitTypeWidget", SP_CSS_UNIT_PT); + Inkscape::Util::Unit const *previousUnit = Inkscape::Util::unit_table.getUnit(sp_style_get_css_unit_string(previousUnitCss)); + Inkscape::Util::Unit const *finalUnit = Inkscape::Util::unit_table.getUnit(sp_style_get_css_unit_string(units[unit])); + prefs->setInt("/options/font/unitType", units[unit]); + prefs->setInt("/options/font/unitTypeWidget", units[unit]); + gdouble value = fsel->fontsize; + double new_font_value = Inkscape::Util::Quantity::convert(value, previousUnit, finalUnit); + std::stringstream new_font_num; + new_font_num.imbue(std::locale::classic()); + new_font_num << new_font_value; + int max_size = prefs->getInt("/dialogs/textandfont/maxFontSize", 10000); // somewhat arbitrary, but text&font preview freezes with too huge fontsizes + if (value > max_size){ + value = max_size; + } + fsel->fontsize = value; + gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child (GTK_BIN (fsel->size))), new_font_num.str().c_str()); + sp_font_selector_set_sizes( fsel ); + sp_font_selector_set_size_tooltip( fsel); + sp_font_selector_set_unit_tooltip(fsel); +} + // Called from sp_font_selector_style_select_row // Called from sp_font_selector_size_changed @@ -434,13 +501,21 @@ selection_family = gtk_tree_view_get_selection (GTK_TREE_VIEW (fsel->family_treeview)); selection_style = gtk_tree_view_get_selection (GTK_TREE_VIEW (fsel->style_treeview )); - if (!gtk_tree_selection_get_selected (selection_family, NULL, &iter_family)) return; - if (!gtk_tree_selection_get_selected (selection_style, NULL, &iter_style )) return; - + if (!gtk_tree_selection_get_selected (selection_family, NULL, &iter_family)) { + g_signal_emit(fsel, fs_signals[FONT_SET], 0, ""); + return; + } + if (!gtk_tree_selection_get_selected (selection_style, NULL, &iter_style )) { + g_signal_emit(fsel, fs_signals[FONT_SET], 0, ""); + return; + } gtk_tree_model_get (model_family, &iter_family, 0, &family, -1); gtk_tree_model_get (model_style, &iter_style, 0, &style, -1); - if ((!family) || (!style)) return; + if ((!family) || (!style)) { + g_signal_emit(fsel, fs_signals[FONT_SET], 0, ""); + return; + } Glib::ustring fontspec = family; fontspec += ", "; @@ -512,6 +587,7 @@ gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(fsel->size))), s); fsel->fontsize = size; sp_font_selector_set_size_tooltip(fsel); + sp_font_selector_set_unit_tooltip(fsel); sp_font_selector_set_sizes(fsel); } } === modified file 'src/widgets/text-toolbar.cpp' --- src/widgets/text-toolbar.cpp 2015-04-29 20:51:23 +0000 +++ src/widgets/text-toolbar.cpp 2015-11-03 00:22:58 +0000 @@ -51,6 +51,7 @@ #include "svg/css-ostringstream.h" #include "text-editing.h" #include "toolbox.h" +#include "util/units.h" #include "ui/icon-names.h" #include "ui/tools/text-tool.h" #include "ui/tools/tool-base.h" @@ -69,7 +70,6 @@ // Functions for debugging: #ifdef DEBUG_TEXT - static void sp_print_font( SPStyle *query ) { bool family_set = query->font_family.set; @@ -113,7 +113,7 @@ } #endif - +static void sp_text_set_sizes(GtkListStore* model_size, int unit); // Font family static void sp_text_fontfamily_value_changed( Ink_ComboBoxEntry_Action *act, GObject *tbl ) { @@ -193,7 +193,6 @@ return; } g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); - gchar *text = ink_comboboxentry_action_get_active_text( act ); gchar *endptr; gdouble size = g_strtod( text, &endptr ); @@ -243,6 +242,40 @@ g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); } +static void sp_text_fontunit_value_changed( EgeSelectOneAction *eact, GObject *tbl ){ + // quit if run by the _changed callbacks + if (g_object_get_data(G_OBJECT(tbl), "freeze")) { + return; + } + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); + SPCSSUnit unit = (SPCSSUnit)ege_select_one_action_get_active(eact); + int units[] = {SP_CSS_UNIT_PX, SP_CSS_UNIT_PT, SP_CSS_UNIT_PC, SP_CSS_UNIT_MM, SP_CSS_UNIT_CM, SP_CSS_UNIT_IN/*, SP_CSS_UNIT_EM, SP_CSS_UNIT_EX, SP_CSS_UNIT_PERCENT*/}; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + SPCSSUnit previousUnitCss = (SPCSSUnit)prefs->getInt("/options/font/unitTypeToolbar", SP_CSS_UNIT_PT); + Inkscape::Util::Unit const *previousUnit = Inkscape::Util::unit_table.getUnit(sp_style_get_css_unit_string(previousUnitCss)); + Inkscape::Util::Unit const *finalUnit = Inkscape::Util::unit_table.getUnit(sp_style_get_css_unit_string(units[unit])); + prefs->setInt("/options/font/unitType", units[unit]); + prefs->setInt("/options/font/unitTypeToolbar", units[unit]); + Ink_ComboBoxEntry_Action* fontsize = INK_COMBOBOXENTRY_ACTION( g_object_get_data(tbl, "TextFontSizeAction") ); + gchar *text = ink_comboboxentry_action_get_active_text( fontsize ); + gchar *endptr; + gdouble size = g_strtod( text, &endptr ); + if (endptr == text) { // Conversion failed, non-numeric input. + g_warning( "Conversion of size text to double failed, input: %s\n", text ); + g_free( text ); + return; + } + g_free( text ); + double new_font_number = Inkscape::Util::Quantity::convert(size, previousUnit, finalUnit); + std::stringstream new_font_num; + new_font_num.imbue(std::locale::classic()); + new_font_num << new_font_number; + ink_comboboxentry_action_set_active_text( fontsize , new_font_num.str().c_str()); + Glib::ustring tooltip = Glib::ustring::format(_("Font size"), " (", sp_style_get_css_unit_string(units[unit]), ")"); + ink_comboboxentry_action_set_tooltip ( fontsize, tooltip.c_str()); + sp_text_set_sizes(GTK_LIST_STORE(ink_comboboxentry_action_get_model(fontsize)), unit); + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); +} /* * Font style @@ -809,7 +842,6 @@ } } - /* * This function sets up the text-tool tool-controls, setting the entry boxes * etc. to the values from the current selection or the default if no selection. @@ -1262,8 +1294,7 @@ sp_text_set_sizes(model_size, unit); - Glib::ustring tooltip = Glib::ustring::format(_("Font size"), " (", sp_style_get_css_unit_string(unit), ")"); - + Glib::ustring tooltip = Glib::ustring(_("Font size")); Ink_ComboBoxEntry_Action* act = ink_comboboxentry_action_new( "TextFontSizeAction", _("Font Size"), _(tooltip.c_str()), @@ -1280,6 +1311,34 @@ g_object_set_data( holder, "TextFontSizeAction", act ); } + /* Font unit */ + { + // List of font sizes for drop-down menu + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT); + prefs->setInt("/options/font/unitTypeToolbar", unit); + // List of font sizes for drop-down menu + int units[] = {SP_CSS_UNIT_PX, SP_CSS_UNIT_PT, SP_CSS_UNIT_PC, SP_CSS_UNIT_MM, SP_CSS_UNIT_CM, SP_CSS_UNIT_IN/*, SP_CSS_UNIT_EM, SP_CSS_UNIT_EX, SP_CSS_UNIT_PERCENT*/}; + + GtkTreeIter iter; + GtkListStore *store = gtk_list_store_new(1,G_TYPE_STRING); + for( unsigned int i = 0; i < G_N_ELEMENTS(units); ++i ) { + gtk_list_store_append(store,&iter); + gtk_list_store_set(store,&iter,0,sp_style_get_css_unit_string(units[i]),-1); + } + Glib::ustring tooltip = Glib::ustring(_("Font Unit")); + EgeSelectOneAction* eact = ege_select_one_action_new( "TextFontUnitAction", + _("Font unit"), + _(tooltip.c_str()), + NULL, + GTK_TREE_MODEL(store)); + //-1 to handle SP_CSS_UNIT_NONE + ege_select_one_action_set_active(eact,(gint)unit - 1); + g_signal_connect( G_OBJECT(eact), "changed", G_CALLBACK(sp_text_fontunit_value_changed), holder ); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact)); + g_object_set_data( holder, "TextFontUnitAction", eact ); + } + /* Font styles */ { Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance(); === modified file 'src/widgets/toolbox.cpp' --- src/widgets/toolbox.cpp 2015-10-08 10:25:06 +0000 +++ src/widgets/toolbox.cpp 2015-11-01 19:39:18 +0000 @@ -462,6 +462,7 @@ " " " " " " + " " " " // " " // " "