diff options
| author | John Smith <john.smith7545@yahoo.com> | 2012-08-16 08:20:16 +0000 |
|---|---|---|
| committer | John Smith <john.smith7545@yahoo.com> | 2012-08-16 08:20:16 +0000 |
| commit | b61db3c2d4c3d2fb497d62b4ddb3364031f5fdec (patch) | |
| tree | 5fcd18179bd2d75c411027dcc19f4957b1b1ce2d /src/widgets | |
| parent | code style (use NULL for pointers instead of 0) (diff) | |
| download | inkscape-b61db3c2d4c3d2fb497d62b4ddb3364031f5fdec.tar.gz inkscape-b61db3c2d4c3d2fb497d62b4ddb3364031f5fdec.zip | |
Fix for 168164 : Font sizes in points option
(bzr r11608)
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/font-selector.cpp | 70 | ||||
| -rw-r--r-- | src/widgets/text-toolbar.cpp | 58 |
2 files changed, 93 insertions, 35 deletions
diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index a690b6948..0244621bf 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -32,6 +32,7 @@ #include "desktop.h" #include "widgets/font-selector.h" #include "preferences.h" +#include "unit-constants.h" /* SPFontSelector */ @@ -84,15 +85,7 @@ static void sp_font_selector_size_changed (GtkComboBox *combobo SPFontSelector *fsel); static void sp_font_selector_emit_set (SPFontSelector *fsel); - -namespace { - const char *sizes[] = { - "4", "6", "8", "9", "10", "11", "12", "13", "14", - "16", "18", "20", "22", "24", "28", - "32", "36", "40", "48", "56", "64", "72", "144", - NULL - }; -} +static void sp_font_selector_set_sizes( SPFontSelector *fsel ); static GtkHBoxClass *fs_parent_class = NULL; static guint fs_signals[LAST_SIGNAL] = { 0 }; @@ -136,6 +129,15 @@ static void sp_font_selector_class_init(SPFontSelectorClass *c) object_class->dispose = sp_font_selector_dispose; } +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); + 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_init(SPFontSelector *fsel) { gtk_box_set_homogeneous(GTK_BOX(fsel), TRUE); @@ -227,7 +229,7 @@ This conditional and its #else block can be deleted in the future. fsel->size = gtk_combo_box_entry_new_text (); #endif - gtk_widget_set_tooltip_text (fsel->size, _("Font size (px)")); + sp_font_selector_set_size_tooltip(fsel); gtk_widget_set_size_request(fsel->size, 90, -1); g_signal_connect (G_OBJECT(fsel->size), "changed", G_CALLBACK (sp_font_selector_size_changed), fsel); gtk_box_pack_end (GTK_BOX(hb), fsel->size, FALSE, FALSE, 0); @@ -236,14 +238,7 @@ This conditional and its #else block can be deleted in the future. gtk_widget_show_all (l); gtk_box_pack_end(GTK_BOX (hb), l, TRUE, TRUE, 0); - for (unsigned int n = 0; sizes[n]; ++n) - { -#if GTK_CHECK_VERSION(2, 24,0) - gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(fsel->size), sizes[n]); -#else - gtk_combo_box_append_text (GTK_COMBO_BOX(fsel->size), sizes[n]); -#endif - } + sp_font_selector_set_sizes(fsel); gtk_widget_show_all (fsel->size); @@ -327,6 +322,39 @@ static void sp_font_selector_style_select_row (GtkTreeSelection *selection, } } + +/* + * Set the default list of font sizes, scaled to the users preferred unit + */ +static void sp_font_selector_set_sizes( SPFontSelector *fsel ) +{ + GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model (GTK_COMBO_BOX(fsel->size))); + gtk_list_store_clear(store); + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT); + + int sizes[] = { + 4, 6, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 24, 28, + 32, 36, 40, 48, 56, 64, 72, 144 + }; + + // Array must be same length as SPCSSUnit in style.h + float ratios[] = {1, 1, 1, 10, 4, 40, 100, 16, 8, 0.16}; + + for (unsigned int n = 0; n < G_N_ELEMENTS(sizes); ++n) + { + double size = sizes[n] / ratios[unit]; + +#if GTK_CHECK_VERSION(2, 24,0) + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(fsel->size), Glib::ustring::format(size).c_str()); +#else + gtk_combo_box_append_text (GTK_COMBO_BOX(fsel->size), size); +#endif + } + +} + static void sp_font_selector_size_changed( GtkComboBox */*cbox*/, SPFontSelector *fsel ) { char *text = NULL; @@ -502,7 +530,6 @@ void sp_font_selector_set_font (SPFontSelector *fsel, font_instance *font, doubl if (font) { Gtk::TreePath path; - font_instance *tempFont = NULL; Glib::ustring family = font_factory::Default()->GetUIFamilyString(font->descr); @@ -536,6 +563,8 @@ void sp_font_selector_set_font (SPFontSelector *fsel, font_instance *font, doubl g_snprintf (s, 8, "%.5g", size); // UI, so printf is ok 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_sizes(fsel); } } @@ -550,6 +579,9 @@ font_instance* sp_font_selector_get_font(SPFontSelector *fsel) return fsel->font; } +/* + * Return the font size in pixels + */ double sp_font_selector_get_size(SPFontSelector *fsel) { return fsel->fontsize; diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 160bc22f3..b769c41f6 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -445,9 +445,10 @@ static void sp_text_fontsize_value_changed( Ink_ComboBoxEntry_Action *act, GObje size = max_size; // Set css font size. + int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT); SPCSSAttr *css = sp_repr_css_attr_new (); Inkscape::CSSOStringStream osfs; - osfs << size << "px"; // For now always use px + osfs << size << sp_style_get_css_unit_string(unit); sp_repr_css_set_property (css, "font-size", osfs.str().c_str()); // Apply font size to selected objects. @@ -900,7 +901,6 @@ static void sp_text_letterspacing_value_changed( GtkAdjustment *adj, GObject *tb SPDesktop *desktop = SP_ACTIVE_DESKTOP; sp_desktop_set_style (desktop, css, true, false); - // If no selected objects, set default. SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); int result_numbers = @@ -919,7 +919,6 @@ static void sp_text_letterspacing_value_changed( GtkAdjustment *adj, GObject *tb sp_style_unref(query); - sp_repr_css_attr_unref (css); g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); @@ -1080,6 +1079,31 @@ static void sp_text_orientation_mode_changed( EgeSelectOneAction *act, GObject * } /* + * Set the default list of font sizes, scaled to the users preferred unit + */ +void sp_text_set_sizes(GtkListStore* model_size, int unit) +{ + gtk_list_store_clear(model_size); + + // List of font sizes for drop-down menu + int sizes[] = { + 4, 6, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 24, 28, + 32, 36, 40, 48, 56, 64, 72, 144 + }; + + // Array must be same length as SPCSSUnit in style.h + float ratios[] = {1, 1, 1, 10, 4, 40, 100, 16, 8, 0.16}; + + for( unsigned int i = 0; i < G_N_ELEMENTS(sizes); ++i ) { + GtkTreeIter iter; + Glib::ustring size = Glib::ustring::format(sizes[i] / (float)ratios[unit]); + gtk_list_store_append( model_size, &iter ); + gtk_list_store_set( model_size, &iter, 0, size.c_str(), -1 ); + } +} + + +/* * 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. * It is called whenever a text selection is changed, including stepping cursor @@ -1191,16 +1215,22 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ ink_comboboxentry_action_set_active_text( fontFamilyAction, fontFamily ); } - // Size (average of text selected) - double size = query->font_size.computed; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT); + double size = sp_style_get_css_font_size_units(query->font_size.computed, unit); + gchar size_text[G_ASCII_DTOSTR_BUF_SIZE]; g_ascii_dtostr (size_text, sizeof (size_text), size); Ink_ComboBoxEntry_Action* fontSizeAction = INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontSizeAction" ) ); + sp_text_set_sizes(GTK_LIST_STORE(ink_comboboxentry_action_get_model(fontSizeAction)), unit); ink_comboboxentry_action_set_active_text( fontSizeAction, size_text ); + Glib::ustring tooltip = Glib::ustring::format("Font size (", sp_style_get_css_unit_string(unit), ")"); + ink_comboboxentry_action_set_tooltip ( fontSizeAction, tooltip.c_str()); + // Font styles font_instance *font = font_factory::Default()->FaceFromStyle(query); sp_text_fontstyle_populate(tbl, font); @@ -1451,20 +1481,16 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje { // List of font sizes for drop-down menu GtkListStore* model_size = gtk_list_store_new( 1, G_TYPE_STRING ); - gchar const *const sizes[] = { - "4", "6", "8", "9", "10", "11", "12", "13", "14", "16", - "18", "20", "22", "24", "28", "32", "36", "40", "48", "56", - "64", "72", "144" - }; - for( unsigned int i = 0; i < G_N_ELEMENTS(sizes); ++i ) { - GtkTreeIter iter; - gtk_list_store_append( model_size, &iter ); - gtk_list_store_set( model_size, &iter, 0, sizes[i], -1 ); - } + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT); + + sp_text_set_sizes(model_size, unit); + + Glib::ustring tooltip = Glib::ustring::format("Font size (", sp_style_get_css_unit_string(unit), ")"); Ink_ComboBoxEntry_Action* act = ink_comboboxentry_action_new( "TextFontSizeAction", _("Font Size"), - _("Font size (px)"), + _(tooltip.c_str()), NULL, GTK_TREE_MODEL(model_size), 4 ); // Width in characters |
