diff options
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/font-selector.cpp | 156 | ||||
| -rw-r--r-- | src/widgets/toolbox.cpp | 98 |
2 files changed, 175 insertions, 79 deletions
diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index c9e5d0bbb..9da48d0e6 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -353,7 +353,7 @@ static void sp_font_selector_emit_set (SPFontSelector *fsel) if ((!family) || (!style)) return; - font = (font_factory::Default())->FaceFromDescr (family, style); + font = (font_factory::Default())->FaceFromUIStrings (family, style); // FIXME: when a text object uses non-available font, font==NULL and we can't set size // (and the size shown in the widget is invalid). To fix, here we must always get some @@ -386,73 +386,103 @@ GtkWidget *sp_font_selector_new() void sp_font_selector_set_font (SPFontSelector *fsel, font_instance *font, double size) { if (font) - { - gchar family[256]; - font->Family (family, 256); - - Gtk::TreePath path; + { + Gtk::TreePath path; + font_instance *tempFont = NULL; + + Glib::ustring family = font_factory::Default()->GetUIFamilyString(font->descr); + + try { + path = Inkscape::FontLister::get_instance()->get_row_for_font (family); + } catch (...) { + return; + } - try { - path = Inkscape::FontLister::get_instance()->get_row_for_font (family); - } catch (...) { - return; + fsel->block_emit = TRUE; + gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (fsel->family_treeview)), path.gobj()); + gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (fsel->family_treeview), path.gobj(), NULL, TRUE, 0.5, 0.5); + fsel->block_emit = FALSE; + + GList *list = 0; + GtkTreeIter iter; + GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(fsel->family_treeview)); + gtk_tree_model_get_iter (model, &iter, path.gobj()); + gtk_tree_model_get (model, &iter, 1, &list, -1); + + unsigned int currentStyleNumber = 0; + unsigned int bestStyleNumber = 0; + + PangoFontDescription *incomingFont = pango_font_description_copy(font->descr); + pango_font_description_unset_fields(incomingFont, PANGO_FONT_MASK_SIZE); + + char *incomingFontString = pango_font_description_to_string(incomingFont); + + tempFont = (font_factory::Default())->FaceFromUIStrings(family.c_str(), (char*)list->data); + + PangoFontDescription *bestMatchForFont = NULL; + if (tempFont) { + bestMatchForFont = pango_font_description_copy(tempFont->descr); + tempFont->Unref(); + tempFont = NULL; + } + + pango_font_description_unset_fields(bestMatchForFont, PANGO_FONT_MASK_SIZE); + + list = list->next; + + while (list) { + currentStyleNumber++; + + tempFont = font_factory::Default()->FaceFromUIStrings(family.c_str(), (char*)list->data); + + PangoFontDescription *currentMatchForFont = NULL; + if (tempFont) { + currentMatchForFont = pango_font_description_copy(tempFont->descr); + tempFont->Unref(); + tempFont = NULL; } - - fsel->block_emit = TRUE; - gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (fsel->family_treeview)), path.gobj()); - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (fsel->family_treeview), path.gobj(), NULL, TRUE, 0.5, 0.5); - fsel->block_emit = FALSE; - - GList *list = 0; - GtkTreeIter iter; - GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(fsel->family_treeview)); - gtk_tree_model_get_iter (model, &iter, path.gobj()); - gtk_tree_model_get (model, &iter, 1, &list, -1); - - gchar descr[256]; - font->Name(descr, 256); - std::string descr_best (family); - descr_best += " "; - descr_best += ((char*)list->data); - - PangoFontDescription *descr_ = pango_font_description_from_string(descr); - PangoFontDescription *best_ = pango_font_description_from_string(descr_best.c_str()); - - unsigned int i = 0; - unsigned int best_i = 0; - - // try to find best match with style description (i.e. bold, italic ?) - for (list = list->next ; list ; list = list->next) - { - i++; - std::string descr_try (family); - descr_try += " "; - descr_try += ((char*)list->data); - PangoFontDescription *try_ = pango_font_description_from_string(descr_try.c_str()); - if (pango_font_description_better_match (descr_, best_, try_)) - { - pango_font_description_free (best_); - best_ = pango_font_description_from_string (descr_try.c_str ()); - best_i = i; + + if (currentMatchForFont) { + pango_font_description_unset_fields(currentMatchForFont, PANGO_FONT_MASK_SIZE); + + char *currentMatchString = pango_font_description_to_string(currentMatchForFont); + + if (!strcmp(incomingFontString, currentMatchString) + || pango_font_description_better_match(incomingFont, bestMatchForFont, currentMatchForFont)) { + // Found a better match for the font we are looking for + pango_font_description_free(bestMatchForFont); + bestMatchForFont = pango_font_description_copy(currentMatchForFont); + bestStyleNumber = currentStyleNumber; } - pango_font_description_free(try_); - } - pango_font_description_free(descr_); - pango_font_description_free(best_); - - GtkTreePath *path_c = gtk_tree_path_new (); - gtk_tree_path_append_index (path_c, best_i); - gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (fsel->style_treeview)), path_c); - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (fsel->style_treeview), path_c, NULL, TRUE, 0.5, 0.5); - - if (size != fsel->fontsize) - { - gchar s[8]; - g_snprintf (s, 8, "%.5g", size); // UI, so printf is ok - gtk_entry_set_text (GTK_ENTRY (GTK_BIN(fsel->size)->child), s); - fsel->fontsize = size; + + g_free(currentMatchString); + + pango_font_description_free(currentMatchForFont); } + + list = list->next; + } + + if (bestMatchForFont) + pango_font_description_free(bestMatchForFont); + if (incomingFont) + pango_font_description_free(incomingFont); + g_free(incomingFontString); + + GtkTreePath *path_c = gtk_tree_path_new (); + gtk_tree_path_append_index (path_c, bestStyleNumber); + gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (fsel->style_treeview)), path_c); + gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (fsel->style_treeview), path_c, NULL, TRUE, 0.5, 0.5); + + if (size != fsel->fontsize) + { + gchar s[8]; + g_snprintf (s, 8, "%.5g", size); // UI, so printf is ok + gtk_entry_set_text (GTK_ENTRY (GTK_BIN(fsel->size)->child), s); + fsel->fontsize = size; + } } + } font_instance* sp_font_selector_get_font(SPFontSelector *fsel) diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 9e9686e77..81eedaeb8 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -76,6 +76,7 @@ #include "document-private.h" #include "desktop-style.h" #include "../libnrtype/font-lister.h" +#include "../libnrtype/font-instance.h" #include "../connection-pool.h" #include "../prefs-utils.h" #include "../inkscape-stock.h" @@ -2360,7 +2361,7 @@ static void box3d_toggle_vp_changed (GtkToggleAction *act, GObject *dataKludge, // in turn, prevent listener from responding g_object_set_data(dataKludge, "freeze", GINT_TO_POINTER(TRUE)); - persp3d_set_VP_state(persp, axis, gtk_toggle_action_get_active(act) ? Proj::INFINITE : Proj::FINITE); + persp3d_set_VP_state(persp, axis, (gtk_toggle_action_get_active(act) ? Proj::VP_INFINITE : Proj::VP_FINITE)); // FIXME: Can we merge this functionality with the one in box3d_persp_tb_event_attr_changed()? gchar *str; @@ -3948,6 +3949,9 @@ sp_text_toolbox_selection_changed (Inkscape::Selection */*selection*/, GObject * { SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); + + int result_fontspec = + sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY); @@ -3981,15 +3985,27 @@ sp_text_toolbox_selection_changed (Inkscape::Selection */*selection*/, GObject * GtkWidget *entry = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "family-entry")); gtk_entry_set_text (GTK_ENTRY (entry), ""); - } else if (query->text->font_family.value) { + } else if (query->text->font_specification.value || query->text->font_family.value) { GtkWidget *entry = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "family-entry")); - gtk_entry_set_text (GTK_ENTRY (entry), query->text->font_family.value); + + // Get the font that corresponds + Glib::ustring familyName; + + font_instance * font = font_factory::Default()->FaceFromStyle(query); + if (font) { + familyName = font_factory::Default()->GetUIFamilyString(font->descr); + font->Unref(); + font = NULL; + } + + gtk_entry_set_text (GTK_ENTRY (entry), familyName.c_str()); Gtk::TreePath path; try { - path = Inkscape::FontLister::get_instance()->get_row_for_font (query->text->font_family.value); + path = Inkscape::FontLister::get_instance()->get_row_for_font (familyName); } catch (...) { + g_warning("Family name %s does not have an entry in the font lister.", familyName.c_str()); return; } @@ -4142,14 +4158,46 @@ sp_text_toolbox_family_changed (GtkTreeSelection *selection, SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); - int result_numbers = - sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); - + int result_fontspec = + sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); + SPCSSAttr *css = sp_repr_css_attr_new (); - sp_repr_css_set_property (css, "font-family", family); + + std::string fontSpec = query->text->font_specification.value; + if (!fontSpec.empty()) { + Glib::ustring newFontSpec = font_factory::Default()->ReplaceFontSpecificationFamily(fontSpec, family); + if (!newFontSpec.empty() && fontSpec != newFontSpec) { + font_instance *font = font_factory::Default()->FaceFromFontSpecification(newFontSpec.c_str()); + if (font) { + sp_repr_css_set_property (css, "-inkscape-font-specification", newFontSpec.c_str()); + + // Set all the these just in case they were altered when finding the best + // match for the new family and old style... + + gchar c[256]; + + font->Family(c, 256); + sp_repr_css_set_property (css, "font-family", c); + + font->Attribute( "weight", c, 256); + sp_repr_css_set_property (css, "font-weight", c); + + font->Attribute("style", c, 256); + sp_repr_css_set_property (css, "font-style", c); + + font->Attribute("stretch", c, 256); + sp_repr_css_set_property (css, "font-stretch", c); + + font->Attribute("variant", c, 256); + sp_repr_css_set_property (css, "font-variant", c); + + font->Unref(); + } + } + } // If querying returned nothing, read the style from the text tool prefs (default style for new texts) - if (result_numbers == QUERY_STYLE_NOTHING) + if (result_fontspec == QUERY_STYLE_NOTHING) { sp_repr_css_change (inkscape_get_repr (INKSCAPE, "tools.text"), css, "style"); sp_text_edit_dialog_default_set_insensitive (); //FIXME: Replace trough a verb @@ -4264,29 +4312,45 @@ sp_text_toolbox_style_toggled (GtkToggleButton *button, int prop = GPOINTER_TO_INT(data); bool active = gtk_toggle_button_get_active (button); + SPStyle *query = + sp_style_new (SP_ACTIVE_DOCUMENT); + int result_fontspec = + sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); + + Glib::ustring fontSpec = query->text->font_specification.value; + Glib::ustring newFontSpec; switch (prop) { case 0: { - sp_repr_css_set_property (css, "font-weight", active ? "bold" : "normal" ); + if (!fontSpec.empty()) { + newFontSpec = font_factory::Default()->FontSpecificationSetBold(fontSpec, active); + } + if (fontSpec != newFontSpec) { + sp_repr_css_set_property (css, "font-weight", active ? "bold" : "normal" ); + } break; } case 1: { - sp_repr_css_set_property (css, "font-style", active ? "italic" : "normal"); + if (!fontSpec.empty()) { + newFontSpec = font_factory::Default()->FontSpecificationSetItalic(fontSpec, active); + } + if (fontSpec != newFontSpec) { + sp_repr_css_set_property (css, "font-style", active ? "italic" : "normal"); + } break; } } - SPStyle *query = - sp_style_new (SP_ACTIVE_DOCUMENT); - int result_numbers = - sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + if (!fontSpec.empty()) { + sp_repr_css_set_property (css, "-inkscape-font-specification", fontSpec.c_str()); + } // If querying returned nothing, read the style from the text tool prefs (default style for new texts) - if (result_numbers == QUERY_STYLE_NOTHING) + if (result_fontspec == QUERY_STYLE_NOTHING) { sp_repr_css_change (inkscape_get_repr (INKSCAPE, "tools.text"), css, "style"); } @@ -5200,3 +5264,5 @@ static void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main */ // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : + + |
