diff options
Diffstat (limited to 'src/libnrtype')
| -rw-r--r-- | src/libnrtype/font-lister.cpp | 76 | ||||
| -rw-r--r-- | src/libnrtype/font-lister.h | 52 |
2 files changed, 62 insertions, 66 deletions
diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp index 5e67c5991..97d3c66d4 100644 --- a/src/libnrtype/font-lister.cpp +++ b/src/libnrtype/font-lister.cpp @@ -82,7 +82,6 @@ namespace Inkscape font_list_store->thaw_notify(); style_list_store = Gtk::ListStore::create (FontStyleList); - style_list_store_trial = Gtk::ListStore::create (FontStyleList); } // Example of how to use "foreach_iter" @@ -375,6 +374,24 @@ namespace Inkscape } + // Set fontspec. If check is false, best style match will not be done. + void + FontLister::set_fontspec (Glib::ustring new_fontspec, gboolean check) { + + std::pair<Glib::ustring,Glib::ustring> ui = ui_from_fontspec( new_fontspec ); + Glib::ustring new_family = ui.first; + Glib::ustring new_style = ui.second; + +#ifdef DEBUG_FONT + std::cout << "FontLister::set_fontspec: family: " << new_family + << " style:" << new_style << std::endl; +#endif + + set_font_family( new_family, false ); + set_font_style( new_style ); + } + + // TODO: use to determine font-selector best style std::pair<Glib::ustring, Glib::ustring> FontLister::new_font_family (Glib::ustring new_family, gboolean check_style ) { @@ -419,7 +436,6 @@ namespace Inkscape } // Update style list. - // TODO: create a second "temporary" style_list_store for font_selector. style_list_store->freeze_notify(); style_list_store->clear(); @@ -524,11 +540,6 @@ namespace Inkscape } - // void - // FontLister::new_font_style (Glib::ustring new_style) { - // // Is this needed? What do we do? - // } - void FontLister::set_font_style (Glib::ustring new_style) { @@ -554,27 +565,22 @@ namespace Inkscape #endif } - // For use by font-selector where we already know that the style is valid - void - FontLister::set_font (Glib::ustring new_family, Glib::ustring new_style) { - -#ifdef DEBUG_FONT - std::cout << "FonLister::set_font: " << new_family << " " << new_style << std::endl; -#endif - set_font_family( new_family, false ); - set_font_style( new_style ); - } // We do this ourselves as we can't rely on FontFactory. void - FontLister::set_css( SPCSSAttr *css ) { + FontLister::fill_css( SPCSSAttr *css, Glib::ustring fontspec ) { + + if( fontspec.empty() ) { + fontspec = current_fontspec; + } + std::pair<Glib::ustring,Glib::ustring> ui = ui_from_fontspec( fontspec ); - //std::cout << "FontLister:set_css: " << std::endl; + Glib::ustring family = ui.first; - sp_repr_css_set_property (css, "-inkscape-font-specification", current_fontspec.c_str() ); - sp_repr_css_set_property (css, "font-family", current_family.c_str() ); //Canonized w/ spaces + sp_repr_css_set_property (css, "-inkscape-font-specification", fontspec.c_str() ); + sp_repr_css_set_property (css, "font-family", family.c_str() ); //Canonized w/ spaces - PangoFontDescription *desc = pango_font_description_from_string( current_fontspec.c_str() ); + PangoFontDescription *desc = pango_font_description_from_string( fontspec.c_str() ); PangoWeight weight = pango_font_description_get_weight( desc ); switch ( weight ) { case PANGO_WEIGHT_THIN: @@ -837,6 +843,26 @@ namespace Inkscape return font_list_store->get_path( get_row_for_font ( family ) ); } + Gtk::TreeModel::Row + FontLister::get_row_for_style (Glib::ustring style) + { + Gtk::TreePath path; + + Gtk::TreeModel::iterator iter = style_list_store->get_iter( "0" ); + while( iter != style_list_store->children().end() ) { + + Gtk::TreeModel::Row row = *iter; + + if( style.compare( row[FontStyleList.styles] ) == 0 ) { + return row; + } + + ++iter; + } + + throw STYLE_NOT_FOUND; + } + /* Returns style string */ // TODO: Remove or turn into function to be used by new_font_family. Glib::ustring @@ -905,12 +931,6 @@ namespace Inkscape { return style_list_store; } - - const Glib::RefPtr<Gtk::ListStore> - FontLister::get_style_list_trial () const - { - return style_list_store_trial; - } } // Helper functions diff --git a/src/libnrtype/font-lister.h b/src/libnrtype/font-lister.h index aaa996247..5c48bf7a8 100644 --- a/src/libnrtype/font-lister.h +++ b/src/libnrtype/font-lister.h @@ -111,7 +111,6 @@ namespace Inkscape }; FontStyleListClass FontStyleList; - FontStyleListClass FontStyleListTrial; /** Returns the ListStore with the family names * @@ -128,12 +127,6 @@ namespace Inkscape const Glib::RefPtr<Gtk::ListStore> get_style_list () const; - /** Returns the ListStore with the styles - trial - * - */ - const Glib::RefPtr<Gtk::ListStore> - get_style_list_trial () const; - /** Updates font list to include fonts in document * */ @@ -173,6 +166,19 @@ namespace Inkscape std::pair<Glib::ustring, Glib::ustring> selection_update (); + /** Sets current_fontspec, etc. If check is false, won't + * try to find best style match (assumes style in fontspec + * valid for given font-family). + */ + void + set_fontspec (Glib::ustring fontspec, gboolean check=true); + + Glib::ustring + get_fontspec () + { + return current_fontspec; + } + /** Changes font-family, updating style list and attempting to find * closest style to current_style style (if check_style is true). * New font-family and style returned. @@ -215,10 +221,6 @@ namespace Inkscape return current_family_row; } - /* Not Used */ - void - new_font_style (Glib::ustring style); - /** Sets style. Does not validate style for family. */ void @@ -230,32 +232,13 @@ namespace Inkscape return current_style; } - /** Sets both family and style. Does not attempt to find - * best match for style (assume that style is already valid - * for family). - */ - void - set_font (Glib::ustring family, Glib::ustring style); - - /** Sets both family and style. Does not attempt to find - * best match for style (assume that style is already valid - * for family). - */ - void - new_font (Glib::ustring family, Glib::ustring style); - - std::pair<Glib::ustring, Glib::ustring> - get_try_font () { - return ( std::make_pair( try_family, try_style ) ); - } - Glib::ustring fontspec_from_style (SPStyle* style); /** Fill css using current_fontspec. */ void - set_css( SPCSSAttr *css ); + fill_css( SPCSSAttr *css, Glib::ustring fontspec = "" ); Gtk::TreeModel::Row get_row_for_font (Glib::ustring family); @@ -292,7 +275,6 @@ namespace Inkscape Glib::RefPtr<Gtk::ListStore> font_list_store; Glib::RefPtr<Gtk::ListStore> style_list_store; - Glib::RefPtr<Gtk::ListStore> style_list_store_trial; /** Info for currently selected font (what is shown in the UI). * May include font-family lists and fonts not on system. @@ -307,12 +289,6 @@ namespace Inkscape */ Glib::ustring current_fontspec_system; - /** Info for proposed font (what is shown in the font-selection UI). - * May include font-family lists and fonts not on system. - */ - Glib::ustring try_family; - Glib::ustring try_style; - /** If a font-family is not on system, this list of styles is used. */ GList *default_styles; |
