diff options
author | Mattias Andrée <maandree@kth.se> | 2023-01-10 18:45:42 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-01-10 18:45:42 +0100 |
commit | abf2630e7039c53126faf6585769e2abfba657dd (patch) | |
tree | 68a97f64a78472154a1da3fb988022ccf417bc49 /libfonts_do_decoded_font_descriptions_match.c | |
parent | m (diff) | |
download | libfonts-abf2630e7039c53126faf6585769e2abfba657dd.tar.gz libfonts-abf2630e7039c53126faf6585769e2abfba657dd.tar.bz2 libfonts-abf2630e7039c53126faf6585769e2abfba657dd.tar.xz |
m + implement libfonts_do_{decoded_,}font_descriptions_match
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libfonts_do_decoded_font_descriptions_match.c')
-rw-r--r-- | libfonts_do_decoded_font_descriptions_match.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/libfonts_do_decoded_font_descriptions_match.c b/libfonts_do_decoded_font_descriptions_match.c new file mode 100644 index 0000000..69f7cf0 --- /dev/null +++ b/libfonts_do_decoded_font_descriptions_match.c @@ -0,0 +1,71 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +#define LIST_ALL_FIELDS(X, _)\ + X(xlfd_version) _\ + X(foundry) _\ + X(family_name) _\ + X(weight_name) _\ + X(slant) _\ + X(setwidth_name) _\ + X(add_style_name) _\ + X(pixel_size) _\ + X(point_size) _\ + X(resolution_x) _\ + X(resolution_y) _\ + X(spacing) _\ + X(average_width) _\ + X(charset_registry) _\ + X(charset_encoding) _\ + X(charset_subset) + + +static int +equal(const char *desc, const char *spec) +{ + size_t i; + + if (!spec) + return !desc; + if (spec[0] == '*' && !spec[1]) + return 1; + if (!desc) + return 0; + + for (; desc[i] && spec[i]; i++) + if (spec[i] != desc[i] && spec[i] != '?') + return 0; + + return desc[i] == spec[i]; +} + +int +libfonts_do_decoded_font_descriptions_match(const struct libfonts_font_description *desc, + const struct libfonts_font_description *spec) +{ + if (desc->private_font_name || spec->private_font_name) + return libfonts_do_font_descriptions_match(desc->private_font_name, spec->private_font_name); + +#define X(F)\ + if (!equal(desc->F, spec->F))\ + return 0 + LIST_ALL_FIELDS(X, ;); +#undef X + + return libfonts_do_font_descriptions_match(desc->unrecognised_fields, spec->unrecognised_fields); +} + + +#else + + +int +main(void) +{ + return 0; /* XXX add test */ +} + + +#endif |