diff -u notify-osd-0.9.24/src/util.c notify-osd-0.9.24/src/util.c --- notify-osd-0.9.24/src/util.c +++ notify-osd-0.9.24/src/util.c @@ -260,81 +259,0 @@ - -gdouble -extract_point_size (const gchar* string) -{ - gdouble point_size = 0; - GRegex* regex = NULL; - GMatchInfo* match_info = NULL; - - // sanity check - if (!string) - return 0; - - // setup regular expression to extract an integer from the end of string - regex = g_regex_new ("\\d+$", 0, 0, NULL); - if (!regex) - return 0; - - // walk the string - g_regex_match (regex, string, 0, &match_info); - while (g_match_info_matches (match_info)) - { - gchar* word = NULL; - - word = g_match_info_fetch (match_info, 0); - if (word) - { - sscanf (word, "%f", &point_size); - g_free (word); - } - - g_match_info_next (match_info, NULL); - } - - // clean up - g_match_info_free (match_info); - g_regex_unref (regex); - - return point_size; -} - -GString* -extract_font_face (const gchar* string) -{ - GRegex* regex = NULL; - GMatchInfo* match_info = NULL; - GString* font_face = NULL; - - // sanity check - if (!string) - return NULL; - - // extract font-face-name/style - font_face = g_string_new (""); - if (!font_face) - return NULL; - - // setup regular expression to extract leading text before trailing int - regex = g_regex_new ("([A-Z a-z])+", 0, 0, NULL); - - // walk the string - g_regex_match (regex, string, 0, &match_info); - while (g_match_info_matches (match_info)) - { - gchar* word = NULL; - - word = g_match_info_fetch (match_info, 0); - if (word) - { - g_string_append (font_face, word); - g_free (word); - } - - g_match_info_next (match_info, NULL); - } - - // clean up - g_match_info_free (match_info); - g_regex_unref (regex); - - return font_face; -} diff -u notify-osd-0.9.24/src/defaults.c notify-osd-0.9.24/src/defaults.c --- notify-osd-0.9.24/src/defaults.c +++ notify-osd-0.9.24/src/defaults.c @@ -175,10 +175,11 @@ GString* string = NULL; GError* error = NULL; gdouble points = 0; - GString* font_face = NULL; + gchar* font_face = NULL; gdouble dpi = 0.0f; gdouble pixels_per_em = 0; gchar* font_name = NULL; + PangoFontDescription* desc = NULL; if (!IS_DEFAULTS (self)) return; @@ -200,11 +201,17 @@ } g_free ((gpointer) font_name); - // extract text point-size - points = extract_point_size (string->str); + // extract text point-size + desc = pango_font_description_from_string(string->str); + if (pango_font_description_get_size_is_absolute(desc)) + { + points = (gdouble) pango_font_description_get_size(desc); + } else { + points = (gdouble) pango_font_description_get_size(desc) / PANGO_SCALE; + } // extract font-face-name/style - font_face = extract_font_face (string->str); + font_face = pango_font_description_get_family(desc); if (string != NULL) g_string_free (string, TRUE); @@ -212,8 +219,8 @@ /* update stored font-face name and clean up */ if (font_face != NULL) { - g_object_set (self, "text-font-face", font_face->str, NULL); - g_string_free (font_face, TRUE); + g_object_set (self, "text-font-face", font_face, NULL); + g_free ((gpointer) font_face); } /* update stored system-font size (in pt!) */ diff -u notify-osd-0.9.24/src/util.h notify-osd-0.9.24/src/util.h --- notify-osd-0.9.24/src/util.h +++ notify-osd-0.9.24/src/util.h @@ -54,6 +53,0 @@ - -gdouble -extract_point_size (const gchar* string); - -GString* -extract_font_face (const gchar* string); only in patch2: unchanged: --- notify-osd-0.9.24.orig/tests/test-text-filtering.c +++ notify-osd-0.9.24/tests/test-text-filtering.c @@ -102,49 +102,6 @@ } } -static void -test_extract_point_size () -{ - static const IntegerExtraction tests[] = { - { "", 0 }, - { "foobar", 0 }, - { "Bla Fasel -12.0", 0 }, - { "Sans 10", 10 }, - { "Candara 9", 9 }, - { "Bitstream Vera Serif Italic 1", 1 }, - { "Calibri Italic 100", 100 }, - { "Century Schoolbook L Italic 42", 42 }, - { NULL, 0 } - }; - - for (int i = 0; tests[i].before != NULL; i++) - { - guint extracted = extract_point_size (tests[i].before); - g_assert_cmpuint (extracted, ==, tests[i].expected); - } -} - -static void -test_extract_font_face () -{ - static const TextComparisons tests[] = { - { "", "" }, - { "Sans 10", "Sans " }, - { "Candara 9", "Candara " }, - { "Bitstream Vera Serif Italic 1", "Bitstream Vera Serif Italic " }, - { "Calibri Italic 100", "Calibri Italic " }, - { "Century Schoolbook L Italic 10", "Century Schoolbook L Italic " }, - { NULL, NULL } - }; - - for (int i = 0; tests[i].before != NULL; i++) - { - GString* filtered = extract_font_face (tests[i].before); - g_assert_cmpstr (filtered->str, ==, tests[i].expected); - g_string_free (filtered, TRUE); - } -} - GTestSuite * test_filtering_create_test_suite (void) { @@ -156,8 +113,6 @@ g_test_suite_add(ts, TC(test_text_filter)); g_test_suite_add(ts, TC(test_newline_to_space)); - g_test_suite_add(ts, TC(test_extract_point_size)); - g_test_suite_add(ts, TC(test_extract_font_face)); return ts; }