| 1 |
/* font-manager-properties.c |
| 2 |
* |
| 3 |
* Copyright (C) 2009-2023 Jerry Casiano |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. |
| 17 |
* |
| 18 |
* If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "font-manager-font-properties.h" |
| 22 |
|
| 23 |
/** |
| 24 |
* SECTION: font-manager-font-properties |
| 25 |
* @short_description: Fontconfig property configuration |
| 26 |
* @title: Font Properties |
| 27 |
* @include: font-manager-font-properties.h |
| 28 |
* |
| 29 |
* Base class for generating fontconfig configuration files which modify |
| 30 |
* font properties. |
| 31 |
*/ |
| 32 |
|
| 33 |
typedef struct |
| 34 |
{ |
| 35 |
gchar *config_dir; |
| 36 |
gchar *target_file; |
| 37 |
|
| 38 |
gint hintstyle; |
| 39 |
gboolean antialias; |
| 40 |
gboolean hinting; |
| 41 |
gboolean autohint; |
| 42 |
gboolean embeddedbitmap; |
| 43 |
gdouble less; |
| 44 |
gdouble more; |
| 45 |
gint rgba; |
| 46 |
gint lcdfilter; |
| 47 |
gdouble scale; |
| 48 |
gdouble dpi; |
| 49 |
|
| 50 |
FontManagerFontPropertiesType type; |
| 51 |
} |
| 52 |
FontManagerFontPropertiesPrivate; |
| 53 |
|
| 54 |
G_DEFINE_TYPE_WITH_PRIVATE(FontManagerFontProperties, |
| 55 |
font_manager_font_properties, |
| 56 |
G_TYPE_OBJECT) |
| 57 |
|
| 58 |
enum |
| 59 |
{ |
| 60 |
PROP_RESERVED, |
| 61 |
PROP_HINTSTYLE, |
| 62 |
PROP_ANTIALIAS, |
| 63 |
PROP_HINTING, |
| 64 |
PROP_AUTOHINT, |
| 65 |
PROP_EMBEDDEDBITMAP, |
| 66 |
PROP_LESS, |
| 67 |
PROP_MORE, |
| 68 |
PROP_RGBA, |
| 69 |
PROP_LCDFILTER, |
| 70 |
PROP_SCALE, |
| 71 |
PROP_DPI, |
| 72 |
PROP_CONFIG_DIR, |
| 73 |
PROP_TARGET_FILE, |
| 74 |
PROP_TYPE, |
| 75 |
N_PROPERTIES |
| 76 |
}; |
| 77 |
|
| 78 |
static GParamSpec *obj_properties[N_PROPERTIES] = {0}; |
| 79 |
|
| 80 |
#define DEFAULT_PARAM_FLAGS (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS) |
| 81 |
|
| 82 |
static const struct |
| 83 |
{ |
| 84 |
gint start; |
| 85 |
gint end; |
| 86 |
} |
| 87 |
PROPERTY_ID_RANGE [] = |
| 88 |
{ |
| 89 |
{ 1, 7 }, |
| 90 |
{ 8, 11 } |
| 91 |
}; |
| 92 |
|
| 93 |
GType |
| 94 |
font_manager_font_properties_type_get_type (void) |
| 95 |
{ |
| 96 |
static gsize g_define_type_id__volatile = 0; |
| 97 |
|
| 98 |
if (g_once_init_enter (&g_define_type_id__volatile)) |
| 99 |
{ |
| 100 |
static const GEnumValue values[] = { |
| 101 |
{ FONT_MANAGER_FONT_PROPERTIES_TYPE_DEFAULT, "FONT_MANAGER_FONT_PROPERTIES_TYPE_DEFAULT", "default" }, |
| 102 |
{ FONT_MANAGER_FONT_PROPERTIES_TYPE_DISPLAY, "FONT_MANAGER_FONT_PROPERTIES_TYPE_DISPLAY", "display" }, |
| 103 |
{ 0, NULL, NULL } |
| 104 |
}; |
| 105 |
GType g_define_type_id = |
| 106 |
g_enum_register_static (g_intern_static_string ("FontManagerFontPropertiesType"), values); |
| 107 |
g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); |
| 108 |
} |
| 109 |
|
| 110 |
return g_define_type_id__volatile; |
| 111 |
} |
| 112 |
|
| 113 |
static void |
| 114 |
font_manager_font_properties_dispose (GObject *gobject) |
| 115 |
{ |
| 116 |
g_return_if_fail(gobject != NULL); |
| 117 |
FontManagerFontProperties *self = FONT_MANAGER_FONT_PROPERTIES(gobject); |
| 118 |
FontManagerFontPropertiesPrivate *priv; |
| 119 |
priv = font_manager_font_properties_get_instance_private(self); |
| 120 |
g_clear_pointer(&priv->config_dir, g_free); |
| 121 |
g_clear_pointer(&priv->target_file, g_free); |
| 122 |
G_OBJECT_CLASS(font_manager_font_properties_parent_class)->dispose(gobject); |
| 123 |
} |
| 124 |
|
| 125 |
static void |
| 126 |
font_manager_font_properties_get_property (GObject *gobject, |
| 127 |
guint property_id, |
| 128 |
GValue *value, |
| 129 |
GParamSpec *pspec) |
| 130 |
{ |
| 131 |
g_return_if_fail(gobject != NULL); |
| 132 |
FontManagerFontProperties *self = FONT_MANAGER_FONT_PROPERTIES(gobject); |
| 133 |
FontManagerFontPropertiesPrivate *priv; |
| 134 |
priv = font_manager_font_properties_get_instance_private(self); |
| 135 |
switch (property_id) { |
| 136 |
case PROP_HINTSTYLE: |
| 137 |
g_value_set_int(value, priv->hintstyle); |
| 138 |
break; |
| 139 |
case PROP_ANTIALIAS: |
| 140 |
g_value_set_boolean(value, priv->antialias); |
| 141 |
break; |
| 142 |
case PROP_HINTING: |
| 143 |
g_value_set_boolean(value, priv->hinting); |
| 144 |
break; |
| 145 |
case PROP_AUTOHINT: |
| 146 |
g_value_set_boolean(value, priv->autohint); |
| 147 |
break; |
| 148 |
case PROP_EMBEDDEDBITMAP: |
| 149 |
g_value_set_boolean(value, priv->embeddedbitmap); |
| 150 |
break; |
| 151 |
case PROP_LESS: |
| 152 |
g_value_set_double(value, priv->less); |
| 153 |
break; |
| 154 |
case PROP_MORE: |
| 155 |
g_value_set_double(value, priv->more); |
| 156 |
break; |
| 157 |
case PROP_RGBA: |
| 158 |
g_value_set_int(value, priv->rgba); |
| 159 |
break; |
| 160 |
case PROP_LCDFILTER: |
| 161 |
g_value_set_int(value, priv->lcdfilter); |
| 162 |
break; |
| 163 |
case PROP_SCALE: |
| 164 |
g_value_set_double(value, priv->scale); |
| 165 |
break; |
| 166 |
case PROP_DPI: |
| 167 |
g_value_set_double(value, priv->dpi); |
| 168 |
break; |
| 169 |
case PROP_CONFIG_DIR: |
| 170 |
g_value_set_string(value, priv->config_dir); |
| 171 |
break; |
| 172 |
case PROP_TARGET_FILE: |
| 173 |
g_value_set_string(value, priv->target_file); |
| 174 |
break; |
| 175 |
case PROP_TYPE: |
| 176 |
g_value_set_int(value, ((gint) priv->type)); |
| 177 |
break; |
| 178 |
default: |
| 179 |
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec); |
| 180 |
break; |
| 181 |
} |
| 182 |
return; |
| 183 |
} |
| 184 |
|
| 185 |
static void |
| 186 |
font_manager_font_properties_set_property (GObject *gobject, |
| 187 |
guint property_id, |
| 188 |
const GValue *value, |
| 189 |
GParamSpec *pspec) |
| 190 |
{ |
| 191 |
g_return_if_fail(gobject != NULL); |
| 192 |
FontManagerFontProperties *self = FONT_MANAGER_FONT_PROPERTIES(gobject); |
| 193 |
FontManagerFontPropertiesPrivate *priv; |
| 194 |
priv = font_manager_font_properties_get_instance_private(self); |
| 195 |
switch (property_id) { |
| 196 |
case PROP_HINTSTYLE: |
| 197 |
priv->hintstyle = g_value_get_int(value); |
| 198 |
break; |
| 199 |
case PROP_ANTIALIAS: |
| 200 |
priv->antialias = g_value_get_boolean(value); |
| 201 |
break; |
| 202 |
case PROP_HINTING: |
| 203 |
priv->hinting = g_value_get_boolean(value); |
| 204 |
break; |
| 205 |
case PROP_AUTOHINT: |
| 206 |
priv->autohint = g_value_get_boolean(value); |
| 207 |
break; |
| 208 |
case PROP_EMBEDDEDBITMAP: |
| 209 |
priv->embeddedbitmap = g_value_get_boolean(value); |
| 210 |
break; |
| 211 |
case PROP_LESS: |
| 212 |
priv->less = g_value_get_double(value); |
| 213 |
break; |
| 214 |
case PROP_MORE: |
| 215 |
priv->more = g_value_get_double(value); |
| 216 |
break; |
| 217 |
case PROP_RGBA: |
| 218 |
priv->rgba = g_value_get_int(value); |
| 219 |
break; |
| 220 |
case PROP_LCDFILTER: |
| 221 |
priv->lcdfilter = g_value_get_int(value); |
| 222 |
break; |
| 223 |
case PROP_SCALE: |
| 224 |
priv->scale = g_value_get_double(value); |
| 225 |
break; |
| 226 |
case PROP_DPI: |
| 227 |
priv->dpi = g_value_get_double(value); |
| 228 |
break; |
| 229 |
case PROP_CONFIG_DIR: |
| 230 |
g_free(priv->config_dir); |
| 231 |
priv->config_dir = g_value_dup_string(value); |
| 232 |
break; |
| 233 |
case PROP_TARGET_FILE: |
| 234 |
g_free(priv->target_file); |
| 235 |
priv->target_file = g_value_dup_string(value); |
| 236 |
break; |
| 237 |
case PROP_TYPE: |
| 238 |
priv->type = ((FontManagerFontPropertiesType) g_value_get_int(value)); |
| 239 |
break; |
| 240 |
default: |
| 241 |
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec); |
| 242 |
break; |
| 243 |
} |
| 244 |
return; |
| 245 |
} |
| 246 |
|
| 247 |
static void |
| 248 |
font_manager_font_properties_parse_edit_node (FontManagerFontProperties *self, |
| 249 |
xmlNode *edit_node) |
| 250 |
{ |
| 251 |
xmlChar *prop_name = NULL; |
| 252 |
for (xmlAttrPtr prop = edit_node->properties; prop != NULL; prop = prop->next) { |
| 253 |
if (g_strcmp0((const char *) prop->name, "name") == 0) { |
| 254 |
prop_name = xmlNodeGetContent(prop->children); |
| 255 |
break; |
| 256 |
} |
| 257 |
} |
| 258 |
if (!prop_name) |
| 259 |
return; |
| 260 |
for (xmlNode *val = edit_node->children; val != NULL; val = val->next) { |
| 261 |
xmlChar *prop_val = xmlNodeGetContent(val); |
| 262 |
if (prop_val == NULL) { |
| 263 |
continue; |
| 264 |
} else if (g_strcmp0((const char *) val->name, "bool") == 0) { |
| 265 |
g_object_set(self, (const gchar *) prop_name, |
| 266 |
(g_strcmp0((const char *) prop_val, "true") == 0), NULL); |
| 267 |
} else if (g_strcmp0((const char *) val->name, "int") == 0) { |
| 268 |
g_object_set(self, (const gchar *) prop_name, atoi((const char *) prop_val), NULL); |
| 269 |
} else if (g_strcmp0((const char *) val->name, "double") == 0) { |
| 270 |
g_object_set(self, (const gchar *) prop_name, |
| 271 |
g_ascii_strtod((const char *) prop_val, NULL), NULL); |
| 272 |
} else if (g_strcmp0((const char *) val->name, "string") == 0) { |
| 273 |
g_object_set(self, (const gchar *) prop_name, (const gchar *) prop_val, NULL); |
| 274 |
} |
| 275 |
xmlFree(prop_val); |
| 276 |
} |
| 277 |
xmlFree(prop_name); |
| 278 |
return; |
| 279 |
} |
| 280 |
|
| 281 |
static void |
| 282 |
font_manager_font_properties_parse_test_node (FontManagerFontProperties *self, |
| 283 |
xmlNode *test_node) |
| 284 |
{ |
| 285 |
xmlChar *prop_name = NULL; |
| 286 |
xmlChar *prop_val = NULL; |
| 287 |
for (xmlAttrPtr prop = test_node->properties; prop != NULL; prop = prop->next) { |
| 288 |
if (g_strcmp0((const char *) prop->name, "compare") == 0) { |
| 289 |
for (xmlNode *val = test_node->children; val != NULL; val = val->next) { |
| 290 |
if (g_strcmp0((const char *) val->name, "double") == 0) { |
| 291 |
prop_name = xmlNodeGetContent(prop->children); |
| 292 |
prop_val = xmlNodeGetContent(val); |
| 293 |
break; |
| 294 |
} |
| 295 |
} |
| 296 |
break; |
| 297 |
} |
| 298 |
} |
| 299 |
if (prop_name && prop_val) |
| 300 |
g_object_set(self, (const gchar *) prop_name, atof((const char *) prop_val), NULL); |
| 301 |
if (prop_name) |
| 302 |
xmlFree(prop_name); |
| 303 |
if (prop_val) |
| 304 |
xmlFree(prop_val); |
| 305 |
return; |
| 306 |
} |
| 307 |
|
| 308 |
static void |
| 309 |
font_manager_font_properties_add_match_criteria (FontManagerFontProperties *self, |
| 310 |
FontManagerXmlWriter *writer) |
| 311 |
{ |
| 312 |
g_return_if_fail(self != NULL); |
| 313 |
FontManagerFontPropertiesPrivate *priv; |
| 314 |
priv = font_manager_font_properties_get_instance_private(self); |
| 315 |
if (priv->less != 0.0) { |
| 316 |
g_autofree gchar *val = g_strdup_printf("%.1f", priv->less); |
| 317 |
font_manager_xml_writer_add_test_element(writer, "size", "less", "double", val); |
| 318 |
} |
| 319 |
if (priv->more != 0.0) { |
| 320 |
g_autofree gchar *val = g_strdup_printf("%.1f", priv->more); |
| 321 |
font_manager_xml_writer_add_test_element(writer, "size", "more", "double", val); |
| 322 |
} |
| 323 |
return; |
| 324 |
} |
| 325 |
|
| 326 |
static void |
| 327 |
font_manager_font_properties_parse_match_node (FontManagerFontProperties *self, |
| 328 |
xmlNode *match_node) |
| 329 |
{ |
| 330 |
for (xmlNode *iter = match_node->children; iter != NULL; iter = iter->next) { |
| 331 |
if (iter->type != XML_ELEMENT_NODE) { |
| 332 |
continue; |
| 333 |
} else if (g_strcmp0((const char *) iter->name, "edit") == 0) { |
| 334 |
FONT_MANAGER_FONT_PROPERTIES_GET_CLASS(self)->parse_edit_node(self, iter); |
| 335 |
} else if (g_strcmp0((const char *) iter->name, "test") == 0) { |
| 336 |
FONT_MANAGER_FONT_PROPERTIES_GET_CLASS(self)->parse_test_node(self, iter); |
| 337 |
} |
| 338 |
} |
| 339 |
return; |
| 340 |
} |
| 341 |
|
| 342 |
static void |
| 343 |
font_manager_font_properties_add_assignments (FontManagerFontProperties *self, |
| 344 |
FontManagerXmlWriter *writer) |
| 345 |
{ |
| 346 |
g_return_if_fail(self != NULL); |
| 347 |
FontManagerFontPropertiesPrivate *priv; |
| 348 |
priv = font_manager_font_properties_get_instance_private(self); |
| 349 |
|
| 350 |
int t = (int) priv->type; |
| 351 |
for (int i = PROPERTY_ID_RANGE[t].start; i <= PROPERTY_ID_RANGE[t].end; i++) { |
| 352 |
/* Skip test elements, handled in add_match_criteria */ |
| 353 |
if (i == PROP_LESS || i == PROP_MORE) |
| 354 |
continue; |
| 355 |
g_autofree gchar *loc = NULL; |
| 356 |
g_autofree gchar *val = NULL; |
| 357 |
g_autofree gchar *val_type = NULL; |
| 358 |
const gchar *name = PROPERTIES[i].name; |
| 359 |
GType type = PROPERTIES[i].type; |
| 360 |
g_auto(GValue) value = G_VALUE_INIT; |
| 361 |
g_value_init(&value, type); |
| 362 |
g_object_get_property(G_OBJECT(self), name, &value); |
| 363 |
switch (type) { |
| 364 |
/* Brackets around case statements here avoid warnings */ |
| 365 |
case G_TYPE_INT: { |
| 366 |
val = g_strdup_printf("%i", g_value_get_int(&value)); |
| 367 |
val_type = g_strdup("int"); |
| 368 |
break; |
| 369 |
} |
| 370 |
case G_TYPE_DOUBLE: { |
| 371 |
loc = g_strdup(setlocale(LC_ALL, NULL)); |
| 372 |
setlocale(LC_ALL, "C"); |
| 373 |
val = g_strdup_printf("%.1f", g_value_get_double(&value)); |
| 374 |
val_type = g_strdup("double"); |
| 375 |
setlocale(LC_ALL, loc); |
| 376 |
break; |
| 377 |
} |
| 378 |
case G_TYPE_BOOLEAN: { |
| 379 |
if (g_value_get_boolean(&value)) |
| 380 |
val = g_strdup("true"); |
| 381 |
else |
| 382 |
val = g_strdup("false"); |
| 383 |
val_type = g_strdup("bool"); |
| 384 |
break; |
| 385 |
} |
| 386 |
case G_TYPE_STRING: { |
| 387 |
val = g_strdup(g_value_get_string(&value)); |
| 388 |
val_type = g_strdup("string"); |
| 389 |
break; |
| 390 |
} |
| 391 |
default: |
| 392 |
break; |
| 393 |
} |
| 394 |
if (val && val_type) |
| 395 |
font_manager_xml_writer_add_assignment(writer, name, val_type, val); |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
static gdouble |
| 400 |
get_default_for_double_property (int prop_id) |
| 401 |
{ |
| 402 |
switch (prop_id) { |
| 403 |
case PROP_DPI: |
| 404 |
return 96.0; |
| 405 |
case PROP_SCALE: |
| 406 |
return 1.0; |
| 407 |
default: |
| 408 |
break; |
| 409 |
} |
| 410 |
return 0.0; |
| 411 |
} |
| 412 |
|
| 413 |
static void |
| 414 |
font_manager_font_properties_load_defaults (FontManagerFontProperties *self) |
| 415 |
{ |
| 416 |
g_return_if_fail(self != NULL); |
| 417 |
FontManagerFontPropertiesPrivate *priv; |
| 418 |
priv = font_manager_font_properties_get_instance_private(self); |
| 419 |
|
| 420 |
/* Get actual values from default pattern, if possible */ |
| 421 |
FcPattern *blank = FcPatternCreate(); |
| 422 |
|
| 423 |
if (blank) { |
| 424 |
|
| 425 |
FcConfigSubstitute(0, blank, FcMatchPattern); |
| 426 |
FcDefaultSubstitute(blank); |
| 427 |
|
| 428 |
FcResult result; |
| 429 |
FcPattern *system = FcFontMatch(0, blank, &result); |
| 430 |
|
| 431 |
if (system) { |
| 432 |
|
| 433 |
gint hintstyle; |
| 434 |
gint rgba; |
| 435 |
gint lcdfilter; |
| 436 |
gdouble scale; |
| 437 |
gdouble dpi; |
| 438 |
gboolean antialias; |
| 439 |
gboolean hinting; |
| 440 |
gboolean autohint; |
| 441 |
gboolean embeddedbitmap; |
| 442 |
|
| 443 |
if (FcPatternGetInteger(system, FC_HINT_STYLE, 0, &hintstyle) == FcResultMatch) |
| 444 |
priv->hintstyle = hintstyle; |
| 445 |
|
| 446 |
if (FcPatternGetInteger(system, FC_RGBA, 0, &rgba) == FcResultMatch) { |
| 447 |
if (rgba != FC_RGBA_NONE) |
| 448 |
priv->rgba = rgba; |
| 449 |
} |
| 450 |
|
| 451 |
if (FcPatternGetInteger(system, FC_LCD_FILTER, 0, &lcdfilter) == FcResultMatch) |
| 452 |
priv->lcdfilter = lcdfilter; |
| 453 |
|
| 454 |
if (FcPatternGetDouble(system, FC_SCALE, 0, &scale) == FcResultMatch) |
| 455 |
priv->scale = scale; |
| 456 |
|
| 457 |
if (FcPatternGetDouble(system, FC_DPI, 0, &dpi) == FcResultMatch) |
| 458 |
priv->dpi = dpi; |
| 459 |
|
| 460 |
if (FcPatternGetBool(system, FC_ANTIALIAS, 0, &antialias) == FcResultMatch) |
| 461 |
priv->antialias = antialias; |
| 462 |
|
| 463 |
if (FcPatternGetBool(system, FC_HINTING, 0, &hinting) == FcResultMatch) |
| 464 |
priv->hinting = hinting; |
| 465 |
|
| 466 |
if (FcPatternGetBool(system, FC_AUTOHINT, 0, &autohint) == FcResultMatch) |
| 467 |
priv->autohint = autohint; |
| 468 |
|
| 469 |
if (FcPatternGetBool(system, FC_EMBEDDED_BITMAP, 0, &embeddedbitmap) == FcResultMatch) |
| 470 |
priv->embeddedbitmap = embeddedbitmap; |
| 471 |
|
| 472 |
FcPatternDestroy(system); |
| 473 |
|
| 474 |
} |
| 475 |
|
| 476 |
FcPatternDestroy(blank); |
| 477 |
|
| 478 |
} |
| 479 |
|
| 480 |
for (int i = 0; i < N_PROPERTIES; i++) |
| 481 |
if (obj_properties[i]) |
| 482 |
g_object_notify_by_pspec(G_OBJECT(self), obj_properties[i]); |
| 483 |
|
| 484 |
return; |
| 485 |
} |
| 486 |
|
| 487 |
static void |
| 488 |
font_manager_font_properties_class_init (FontManagerFontPropertiesClass *klass) |
| 489 |
{ |
| 490 |
GObjectClass *object_class = G_OBJECT_CLASS(klass); |
| 491 |
object_class->dispose = font_manager_font_properties_dispose; |
| 492 |
object_class->get_property = font_manager_font_properties_get_property; |
| 493 |
object_class->set_property = font_manager_font_properties_set_property; |
| 494 |
|
| 495 |
klass->parse_edit_node = font_manager_font_properties_parse_edit_node; |
| 496 |
klass->parse_test_node = font_manager_font_properties_parse_test_node; |
| 497 |
klass->add_match_criteria = font_manager_font_properties_add_match_criteria; |
| 498 |
|
| 499 |
for (int i = 0; i < N_PROPERTIES; i++) { |
| 500 |
|
| 501 |
switch (PROPERTIES[i].type) { |
| 502 |
case G_TYPE_INT: |
| 503 |
obj_properties[i] = g_param_spec_int(PROPERTIES[i].name, |
| 504 |
NULL, |
| 505 |
PROPERTIES[i].desc, |
| 506 |
0, |
| 507 |
i == PROP_LCDFILTER ? |
| 508 |
FONT_MANAGER_LCD_FILTER_LEGACY : |
| 509 |
i == PROP_TYPE ? |
| 510 |
FONT_MANAGER_FONT_PROPERTIES_TYPE_DISPLAY : |
| 511 |
FONT_MANAGER_SUBPIXEL_ORDER_NONE, |
| 512 |
0, |
| 513 |
DEFAULT_PARAM_FLAGS); |
| 514 |
break; |
| 515 |
case G_TYPE_BOOLEAN: |
| 516 |
obj_properties[i] = g_param_spec_boolean(PROPERTIES[i].name, |
| 517 |
NULL, |
| 518 |
PROPERTIES[i].desc, |
| 519 |
FALSE, |
| 520 |
DEFAULT_PARAM_FLAGS); |
| 521 |
break; |
| 522 |
case G_TYPE_DOUBLE: |
| 523 |
obj_properties[i] = g_param_spec_double(PROPERTIES[i].name, |
| 524 |
NULL, |
| 525 |
PROPERTIES[i].desc, |
| 526 |
0.0, G_MAXDOUBLE, |
| 527 |
get_default_for_double_property(i), |
| 528 |
DEFAULT_PARAM_FLAGS); |
| 529 |
break; |
| 530 |
case G_TYPE_STRING: |
| 531 |
obj_properties[i] = g_param_spec_string(PROPERTIES[i].name, |
| 532 |
NULL, |
| 533 |
PROPERTIES[i].desc, |
| 534 |
NULL, |
| 535 |
DEFAULT_PARAM_FLAGS); |
| 536 |
break; |
| 537 |
case G_TYPE_RESERVED_GLIB_FIRST: |
| 538 |
obj_properties[i] = NULL; |
| 539 |
break; |
| 540 |
default: |
| 541 |
break; |
| 542 |
} |
| 543 |
|
| 544 |
} |
| 545 |
|
| 546 |
g_object_class_install_properties(object_class, N_PROPERTIES, obj_properties); |
| 547 |
return; |
| 548 |
} |
| 549 |
|
| 550 |
static void |
| 551 |
font_manager_font_properties_init (FontManagerFontProperties *self) |
| 552 |
{ |
| 553 |
g_return_if_fail(self != NULL); |
| 554 |
FontManagerFontPropertiesPrivate *priv; |
| 555 |
priv = font_manager_font_properties_get_instance_private(self); |
| 556 |
priv->type = FONT_MANAGER_FONT_PROPERTIES_TYPE_DEFAULT; |
| 557 |
priv->config_dir = font_manager_get_user_fontconfig_directory(); |
| 558 |
font_manager_font_properties_reset(self); |
| 559 |
font_manager_font_properties_load_defaults(self); |
| 560 |
return; |
| 561 |
} |
| 562 |
|
| 563 |
/** |
| 564 |
* font_manager_font_properties_load: |
| 565 |
* @self: #FontManagerFontProperties |
| 566 |
* |
| 567 |
* Returns: %TRUE if current configuration file was successfully loaded |
| 568 |
*/ |
| 569 |
gboolean |
| 570 |
font_manager_font_properties_load (FontManagerFontProperties *self) |
| 571 |
{ |
| 572 |
g_return_val_if_fail(self != NULL, FALSE); |
| 573 |
g_autofree gchar *filepath = font_manager_font_properties_get_filepath(self); |
| 574 |
g_return_val_if_fail(filepath != NULL, FALSE); |
| 575 |
|
| 576 |
g_autoptr(GFile) file = g_file_new_for_path(filepath); |
| 577 |
if (!g_file_query_exists(file, NULL)) |
| 578 |
return FALSE; |
| 579 |
|
| 580 |
xmlDoc *doc = xmlReadFile(filepath, NULL, 0); |
| 581 |
|
| 582 |
if (doc == NULL) { |
| 583 |
/* Empty file */ |
| 584 |
return FALSE; |
| 585 |
} |
| 586 |
|
| 587 |
xmlNode *root = xmlDocGetRootElement(doc); |
| 588 |
if (root == NULL) { |
| 589 |
xmlFreeDoc(doc); |
| 590 |
xmlCleanupParser(); |
| 591 |
return FALSE; |
| 592 |
} |
| 593 |
|
| 594 |
for (xmlNode *iter = root->children; iter != NULL; iter = iter->next) { |
| 595 |
if (iter->type != XML_ELEMENT_NODE) |
| 596 |
continue; |
| 597 |
if (g_strcmp0((const char *) iter->name, "match") == 0) { |
| 598 |
font_manager_font_properties_parse_match_node(self, iter); |
| 599 |
break; |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
xmlFreeDoc(doc); |
| 604 |
return TRUE; |
| 605 |
} |
| 606 |
|
| 607 |
/** |
| 608 |
* font_manager_font_properties_save: |
| 609 |
* @self: #FontManagerFontProperties |
| 610 |
* |
| 611 |
* Returns: %TRUE if current configuration was successfully saved to file |
| 612 |
*/ |
| 613 |
gboolean |
| 614 |
font_manager_font_properties_save (FontManagerFontProperties *self) |
| 615 |
{ |
| 616 |
g_return_val_if_fail(self != NULL, FALSE); |
| 617 |
g_autofree gchar *filepath = font_manager_font_properties_get_filepath(self); |
| 618 |
g_return_val_if_fail(filepath != NULL, FALSE); |
| 619 |
g_autoptr(FontManagerXmlWriter) writer = font_manager_xml_writer_new(); |
| 620 |
font_manager_xml_writer_open(writer, filepath); |
| 621 |
font_manager_xml_writer_start_element(writer, "match"); |
| 622 |
font_manager_xml_writer_write_attribute(writer, "target", "font"); |
| 623 |
FONT_MANAGER_FONT_PROPERTIES_GET_CLASS(self)->add_match_criteria(self, writer); |
| 624 |
font_manager_font_properties_add_assignments(self, writer); |
| 625 |
font_manager_xml_writer_end_element(writer); |
| 626 |
gboolean result = font_manager_xml_writer_close(writer); |
| 627 |
return result; |
| 628 |
} |
| 629 |
|
| 630 |
/** |
| 631 |
* font_manager_font_properties_discard: |
| 632 |
* @self: #FontManagerFontProperties |
| 633 |
* |
| 634 |
* Returns: %TRUE if current configuration was successfully discarded |
| 635 |
*/ |
| 636 |
gboolean |
| 637 |
font_manager_font_properties_discard (FontManagerFontProperties *self) |
| 638 |
{ |
| 639 |
g_return_val_if_fail(self != NULL, FALSE); |
| 640 |
g_autofree gchar *filepath = font_manager_font_properties_get_filepath(self); |
| 641 |
g_autoptr(GFile) file = g_file_new_for_path(filepath); |
| 642 |
gboolean result = TRUE; |
| 643 |
if (g_file_query_exists(file, NULL)) |
| 644 |
result = g_file_delete(file, NULL, NULL); |
| 645 |
font_manager_font_properties_reset(self); |
| 646 |
font_manager_font_properties_load_defaults(self); |
| 647 |
return result; |
| 648 |
} |
| 649 |
|
| 650 |
/** |
| 651 |
* font_manager_font_properties_get_filepath: |
| 652 |
* @self: #FontManagerFontProperties |
| 653 |
* |
| 654 |
* Returns: (transfer full) (nullable): a newly allocated string containing the full |
| 655 |
* filepath to current configuration file or %NULL. Free the result using #g_free(). |
| 656 |
*/ |
| 657 |
gchar * |
| 658 |
font_manager_font_properties_get_filepath (FontManagerFontProperties *self) |
| 659 |
{ |
| 660 |
g_return_val_if_fail(self != NULL, NULL); |
| 661 |
FontManagerFontPropertiesPrivate *priv; |
| 662 |
priv = font_manager_font_properties_get_instance_private(self); |
| 663 |
if (priv->config_dir == NULL || priv->target_file == NULL) |
| 664 |
return NULL; |
| 665 |
return g_build_filename(priv->config_dir, priv->target_file, NULL); |
| 666 |
} |
| 667 |
|
| 668 |
/** |
| 669 |
* font_manager_font_properties_reset: |
| 670 |
* @self: #FontManagerFontProperties |
| 671 |
* |
| 672 |
* Reset all base properties to their default values |
| 673 |
*/ |
| 674 |
void |
| 675 |
font_manager_font_properties_reset (FontManagerFontProperties *self) |
| 676 |
{ |
| 677 |
g_return_if_fail(self != NULL); |
| 678 |
FontManagerFontPropertiesPrivate *priv; |
| 679 |
priv = font_manager_font_properties_get_instance_private(self); |
| 680 |
priv->hintstyle = FONT_MANAGER_HINT_STYLE_NONE; |
| 681 |
/* This is the default, even when not set */ |
| 682 |
priv->antialias = TRUE; |
| 683 |
priv->hinting = FALSE; |
| 684 |
priv->autohint = FALSE; |
| 685 |
priv->embeddedbitmap = FALSE; |
| 686 |
/* Default is none */ |
| 687 |
priv->rgba = FC_RGBA_NONE; |
| 688 |
priv->lcdfilter = FONT_MANAGER_LCD_FILTER_NONE; |
| 689 |
priv->scale = 1.0; |
| 690 |
priv->dpi = 96.0; |
| 691 |
priv->less = 0.0; |
| 692 |
priv->more = 0.0; |
| 693 |
|
| 694 |
for (int i = 0; i < N_PROPERTIES; i++) |
| 695 |
if (obj_properties[i]) |
| 696 |
g_object_notify_by_pspec(G_OBJECT(self), obj_properties[i]); |
| 697 |
|
| 698 |
return; |
| 699 |
} |
| 700 |
|
| 701 |
/** |
| 702 |
* font_manager_font_properties_new: |
| 703 |
* |
| 704 |
* Returns: (transfer full): A newly created #FontManagerFontProperties |
| 705 |
* Free the returned object using #g_object_unref(). |
| 706 |
*/ |
| 707 |
FontManagerFontProperties * |
| 708 |
font_manager_font_properties_new (void) |
| 709 |
{ |
| 710 |
return g_object_new(FONT_MANAGER_TYPE_FONT_PROPERTIES, NULL); |
| 711 |
} |
| 712 |
|
| 713 |
|