diff options
| author | John Smith <john.smith7545@yahoo.com> | 2012-08-04 01:43:12 +0000 |
|---|---|---|
| committer | John Smith <john.smith7545@yahoo.com> | 2012-08-04 01:43:12 +0000 |
| commit | fc86236d39a64a24e7483698fc205f2fa0e01330 (patch) | |
| tree | 9faca291d1d9ec0c823c46df7f251ea78aa94732 /src/widgets/font-selector.cpp | |
| parent | Build. Activating xslt extensions on Windows (not used yet). (diff) | |
| download | inkscape-fc86236d39a64a24e7483698fc205f2fa0e01330.tar.gz inkscape-fc86236d39a64a24e7483698fc205f2fa0e01330.zip | |
Fix for 575831 : Add font variant drop-down box to new text toolbar
(bzr r11586)
Diffstat (limited to 'src/widgets/font-selector.cpp')
| -rw-r--r-- | src/widgets/font-selector.cpp | 132 |
1 files changed, 73 insertions, 59 deletions
diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index 03d29a753..a690b6948 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -425,6 +425,78 @@ GtkWidget *sp_font_selector_new() return (GtkWidget *) fsel; } +/* + * Returns the index of the fonts closest style match from the provided list of styles + * Used in both the Text dialog and the Text toolbar to set the style combo on selection change + */ +unsigned int sp_font_selector_get_best_style (font_instance *font, GList *list) +{ + font_instance *tempFont = NULL; + unsigned int currentStyleNumber = 0; + unsigned int bestStyleNumber = 0; + + Glib::ustring family = font_factory::Default()->GetUIFamilyString(font->descr); + + 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; + } + + 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; + } + + 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); + + return bestStyleNumber; +} + void sp_font_selector_set_font (SPFontSelector *fsel, font_instance *font, double size) { if (font) @@ -451,65 +523,7 @@ void sp_font_selector_set_font (SPFontSelector *fsel, font_instance *font, doubl 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; - } - - 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; - } - - 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); + unsigned int bestStyleNumber = sp_font_selector_get_best_style(font, list); GtkTreePath *path_c = gtk_tree_path_new (); gtk_tree_path_append_index (path_c, bestStyleNumber); |
