1092PangoFontDescription *
1093pango_font_description_from_string (const char *str)
1094{
1095 PangoFontDescription *desc;
1096 const char *p, *last;
1097 size_t len, wordlen;
1098
1099 g_return_val_if_fail (str != NULL, NULL);
1100
1101 desc = pango_font_description_new ();
1102
1103 desc->mask = PANGO_FONT_MASK_STYLE |
1104 PANGO_FONT_MASK_WEIGHT |
1105 PANGO_FONT_MASK_VARIANT |
1106 PANGO_FONT_MASK_STRETCH;
1107
1108 len = strlen (str);
1109 last = str + len;
1110 p = getword (str, last, &wordlen);
1111
1112 /* Look for a size at the end of the string
1113 */
1114 if (wordlen != 0)
1115 {
1116 gboolean size_is_absolute;
1117 if (parse_size (p, wordlen, &desc->size, &size_is_absolute))
1118 {
1119 desc->size_is_absolute = size_is_absolute;
1120 desc->mask |= PANGO_FONT_MASK_SIZE;
1121 last = p;
1122 }
1123 }
1124
1125 /* Now parse style words
1126 */
1127 p = getword (str, last, &wordlen);
1128 while (wordlen != 0)
1129 {
1130 if (!find_field_any (p, wordlen, desc))
1131 break;
1132 else
1133 {
1134 last = p;
1135 p = getword (str, last, &wordlen);
1136 }
1137 }
1138
1139 /* Remainder (str => p) is family list. Trim off trailing commas and leading and trailing white space
1140 */
1141
1142 while (last > str && g_ascii_isspace (*(last - 1)))
1143 last--;
1144
1145 if (last > str && *(last - 1) == ',')
1146 last--;
1147
1148 while (last > str && g_ascii_isspace (*(last - 1)))
1149 last--;
1150
1151 while (last > str && g_ascii_isspace (*str))
1152 str++;
1153
1154 if (str != last)
1155 {
1156 int i;
1157 char **families;
1158
1159 desc->family_name = g_strndup (str, last - str);
1160
1161 /* Now sanitize it to trim space from around individual family names.
1162 * bug #499624 */
1163
1164 families = g_strsplit (desc->family_name, ",", -1);
1165
1166 for (i = 0; families[i]; i++)
1167 g_strstrip (families[i]);
1168
1169 g_free (desc->family_name);
1170 desc->family_name = g_strjoinv (",", families);
1171 g_strfreev (families);
1172
1173 desc->mask |= PANGO_FONT_MASK_FAMILY;
1174 }
1175
1176 return desc;
1177}
1178