aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-01-10 18:45:42 +0100
committerMattias Andrée <maandree@kth.se>2023-01-10 18:45:42 +0100
commitabf2630e7039c53126faf6585769e2abfba657dd (patch)
tree68a97f64a78472154a1da3fb988022ccf417bc49
parentm (diff)
downloadlibfonts-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>
-rw-r--r--Makefile2
-rw-r--r--libfonts.h2
-rw-r--r--libfonts_decode_font_description.c30
-rw-r--r--libfonts_do_decoded_font_descriptions_match.c71
-rw-r--r--libfonts_do_font_descriptions_match.c43
-rw-r--r--libfonts_encode_font_description.c36
6 files changed, 149 insertions, 35 deletions
diff --git a/Makefile b/Makefile
index 71676a7..185f639 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,8 @@ LIB_NAME = fonts
PUBLIC_OBJ =\
libfonts_calculate_subpixel_order.o\
libfonts_decode_font_description.o\
+ libfonts_do_decoded_font_descriptions_match.o\
+ libfonts_do_font_descriptions_match.o\
libfonts_encode_font_description.o\
libfonts_get_default_font.o\
libfonts_get_default_font_name.o\
diff --git a/libfonts.h b/libfonts.h
index f45c203..20a0b5d 100644
--- a/libfonts.h
+++ b/libfonts.h
@@ -1737,7 +1737,6 @@ int libfonts_decode_font_description(struct libfonts_font_description *, const c
* @return 1 if the arguments match, 0 if they don't match
*/
int libfonts_do_font_descriptions_match(const char *, const char *);
-/* TODO implement libfonts_do_font_descriptions_match */
/**
* Check if an X Logical Font Description (XLFD) matches
@@ -1749,7 +1748,6 @@ int libfonts_do_font_descriptions_match(const char *, const char *);
*/
int libfonts_do_decoded_font_descriptions_match(const struct libfonts_font_description *,
const struct libfonts_font_description *);
-/* TODO implement libfonts_do_decoded_font_descriptions_match */
/**
diff --git a/libfonts_decode_font_description.c b/libfonts_decode_font_description.c
index b06257e..b67a5cd 100644
--- a/libfonts_decode_font_description.c
+++ b/libfonts_decode_font_description.c
@@ -3,19 +3,19 @@
#ifndef TEST
-#define LIST_FIELDS_EXCEPT_FINAL(X)\
- 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)\
+#define LIST_FIELDS_EXCEPT_FINAL(X, _)\
+ 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)
@@ -169,8 +169,8 @@ libfonts_decode_font_description(struct libfonts_font_description *desc, const c
desc->F = buf;\
for (s++; *s && *s != '-'; s++)\
*buf++ = *s == '~' ? '-' : *s;\
- *buf++ = '\0';
- LIST_FIELDS_EXCEPT_FINAL(X)
+ *buf++ = '\0'
+ LIST_FIELDS_EXCEPT_FINAL(X, ;);
#undef X
if (*s != '-')
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
diff --git a/libfonts_do_font_descriptions_match.c b/libfonts_do_font_descriptions_match.c
new file mode 100644
index 0000000..1bf6069
--- /dev/null
+++ b/libfonts_do_font_descriptions_match.c
@@ -0,0 +1,43 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#ifndef TEST
+
+
+int
+libfonts_do_font_descriptions_match(const char *desc, const char *spec)
+{
+ if (!spec)
+ return !desc;
+ if (!desc)
+ return 0;
+
+ while (*spec && *desc) {
+ if (spec[0] == '*' && (!spec[1] || spec[1] == '-')) {
+ spec++;
+ while (*desc && *desc != '-')
+ desc++;
+ } else {
+ while (*spec && *desc && *spec != '-' && *desc != '-') {
+ if (*spec != *desc && *spec != '?')
+ return 0;
+ }
+ }
+ if (*spec != *desc || (*spec && *spec != '-'))
+ return 0;
+ }
+
+ return *spec == *desc;
+}
+
+
+#else
+
+
+int
+main(void)
+{
+ return 0; /* XXX add test */
+}
+
+
+#endif
diff --git a/libfonts_encode_font_description.c b/libfonts_encode_font_description.c
index f0d4c47..5c25315 100644
--- a/libfonts_encode_font_description.c
+++ b/libfonts_encode_font_description.c
@@ -3,20 +3,20 @@
#ifndef TEST
-#define LIST_FIELDS(X)\
- 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)\
+#define LIST_FIELDS(X, _)\
+ 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)
@@ -61,8 +61,8 @@ libfonts_encode_font_description(const struct libfonts_font_description *desc, c
#define X(F)\
if (!desc->F)\
goto einval;\
- n += strlen(desc->F) + 1;
- LIST_FIELDS(X)
+ n += strlen(desc->F) + 1
+ LIST_FIELDS(X, ;);
#undef X
if (desc->charset_subset)
@@ -82,8 +82,8 @@ libfonts_encode_font_description(const struct libfonts_font_description *desc, c
#define X(F)\
*p++ = '-';\
- p = encode(p, desc->F);
- LIST_FIELDS(X)
+ p = encode(p, desc->F)
+ LIST_FIELDS(X, ;);
#undef X
if (desc->charset_subset) {