2 commits - .gitlab-ci.yml src/cairo-scaled-font-subsets.c src/cairo-type1-fallback.c test/ft-variable-font.c test/meson.build test/reference
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Jan 17 02:23:29 UTC 2024
.gitlab-ci.yml | 1
src/cairo-scaled-font-subsets.c | 1
src/cairo-type1-fallback.c | 1
test/ft-variable-font.c | 127 +++++++++++++++++++++++
test/meson.build | 1
test/reference/ft-variable-font.image16.ref.png |binary
test/reference/ft-variable-font.pdf.ref.png |binary
test/reference/ft-variable-font.ps.ref.png |binary
test/reference/ft-variable-font.ref.png |binary
test/reference/ft-variable-font.script.xfail.png |binary
test/reference/ft-variable-font.svg.ref.png |binary
11 files changed, 131 insertions(+)
New commits:
commit 61da2c20587a47b59e693d3a562b848418715bda
Merge: ee07a8118 3bcad03f6
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Wed Jan 17 02:23:27 2024 +0000
Merge branch 'font-options' into 'master'
Copy font-options during creation of a fallback font
Closes #819
See merge request cairo/cairo!530
commit 3bcad03f6bc33c436122f4acaefc9e58caa37116
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Jan 14 09:17:40 2024 -0700
Copy font-options during creation of a fallback font
Specially important for font variations, which before did not
work in PDF, etc, output.
Script surface is not updated. It seems out of date with all
recent additions to cairo_font_options_t, so it loses the
variations :(.
Fixes https://gitlab.freedesktop.org/cairo/cairo/-/issues/819
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 9384e0abd..0b54eefd3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -91,6 +91,7 @@ fedora image:
dejavu-sans-mono-fonts
dejavu-serif-fonts
google-noto-emoji-color-fonts
+ google-noto-sans-vf-fonts
fonttools
util-linux
diff --git a/src/cairo-scaled-font-subsets.c b/src/cairo-scaled-font-subsets.c
index 8a25a4612..a240bebbe 100644
--- a/src/cairo-scaled-font-subsets.c
+++ b/src/cairo-scaled-font-subsets.c
@@ -922,6 +922,7 @@ _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t *subsets,
font_face = cairo_scaled_font_get_font_face (scaled_font);
cairo_matrix_init_identity (&identity);
_cairo_font_options_init_default (&font_options);
+ cairo_scaled_font_get_font_options (scaled_font, &font_options);
cairo_font_options_set_hint_style (&font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_hint_metrics (&font_options, CAIRO_HINT_METRICS_OFF);
unscaled_font = cairo_scaled_font_create (font_face,
diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c
index 3a44c4666..c81e85143 100644
--- a/src/cairo-type1-fallback.c
+++ b/src/cairo-type1-fallback.c
@@ -107,6 +107,7 @@ cairo_type1_font_create (cairo_scaled_font_subset_t *scaled_font_subset,
cairo_matrix_init_identity (&ctm);
_cairo_font_options_init_default (&font_options);
+ cairo_scaled_font_get_font_options (scaled_font_subset->scaled_font, &font_options);
cairo_font_options_set_hint_style (&font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_hint_metrics (&font_options, CAIRO_HINT_METRICS_OFF);
diff --git a/test/ft-variable-font.c b/test/ft-variable-font.c
new file mode 100644
index 000000000..2adba66dd
--- /dev/null
+++ b/test/ft-variable-font.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright © 2021 Adrian Johnson
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Adrian Johnson <ajohnson at redneon.com>
+ */
+
+#include "cairo-test.h"
+#include <cairo-ft.h>
+
+#define SIZE 200
+#define HEIGHT SIZE
+#define WIDTH (SIZE * 1.5)
+#define FONT "Noto Sans"
+
+static cairo_test_status_t
+set_variable_font (cairo_t *cr)
+{
+ cairo_font_options_t *font_options;
+ cairo_font_face_t *font_face;
+ FcPattern *pattern;
+ FcPattern *resolved;
+ FcChar8 *font_name;
+ FcBool variable;
+ FcResult result;
+
+ pattern = FcPatternCreate ();
+ if (pattern == NULL)
+ return CAIRO_TEST_NO_MEMORY;
+
+ FcPatternAddString (pattern, FC_FAMILY, (FcChar8 *) FONT);
+ FcPatternAddBool (pattern, FC_VARIABLE, TRUE);
+ FcConfigSubstitute (NULL, pattern, FcMatchPattern);
+
+ font_options = cairo_font_options_create ();
+ cairo_get_font_options (cr, font_options);
+ cairo_ft_font_options_substitute (font_options, pattern);
+
+ FcDefaultSubstitute (pattern);
+ resolved = FcFontMatch (NULL, pattern, &result);
+ if (resolved == NULL) {
+ FcPatternDestroy (pattern);
+ return CAIRO_TEST_NO_MEMORY;
+ }
+
+ if (FcPatternGetString (resolved, FC_FAMILY, 0, &font_name) == FcResultMatch) {
+ if (strcmp((char*)font_name, FONT) != 0) {
+ const cairo_test_context_t *ctx = cairo_test_get_context (cr);
+ cairo_test_log (ctx, "Could not find %s font\n", FONT);
+ return CAIRO_TEST_UNTESTED;
+ }
+ } else {
+ return CAIRO_TEST_FAILURE;
+ }
+ if (FcPatternGetBool (resolved, FC_VARIABLE, 0, &variable) == FcResultMatch) {
+ if (!variable) {
+ const cairo_test_context_t *ctx = cairo_test_get_context (cr);
+ cairo_test_log (ctx, "Could not find %s font\n", FONT);
+ return CAIRO_TEST_UNTESTED;
+ }
+ } else {
+ return CAIRO_TEST_FAILURE;
+ }
+
+ font_face = cairo_ft_font_face_create_for_pattern (resolved);
+ cairo_set_font_face (cr, font_face);
+
+ cairo_font_options_destroy (font_options);
+ cairo_font_face_destroy (font_face);
+ FcPatternDestroy (pattern);
+ FcPatternDestroy (resolved);
+
+ return CAIRO_TEST_SUCCESS;
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+ cairo_test_status_t result;
+ cairo_font_options_t *font_options;
+
+ cairo_set_source_rgb (cr, 1, 1, 1);
+ cairo_paint (cr);
+ cairo_set_source_rgb (cr, 0, 0, 0);
+
+ result = set_variable_font (cr);
+ if (result != CAIRO_TEST_SUCCESS)
+ return result;
+
+ font_options = cairo_font_options_create ();
+ cairo_font_options_set_variations (font_options, "wght=700");
+ cairo_set_font_options (cr, font_options);
+ cairo_font_options_destroy (font_options);
+
+ cairo_set_font_size (cr, SIZE/2);
+ cairo_move_to (cr, SIZE/8, 0.7 * SIZE);
+
+ cairo_show_text(cr, "Test");
+
+ return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (ft_variable_font,
+ "Test variable font",
+ "ft, font", /* keywords */
+ NULL, /* requirements */
+ WIDTH, HEIGHT,
+ NULL, draw)
diff --git a/test/meson.build b/test/meson.build
index 53a8eb675..d7834438f 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -429,6 +429,7 @@ test_ft_font_sources = [
'ft-text-vertical-layout-type1.c',
'ft-text-vertical-layout-type3.c',
'ft-text-antialias-none.c',
+ 'ft-variable-font.c',
]
test_ft_svg_font_sources = [
diff --git a/test/reference/ft-variable-font.image16.ref.png b/test/reference/ft-variable-font.image16.ref.png
new file mode 100644
index 000000000..94d4d63c4
Binary files /dev/null and b/test/reference/ft-variable-font.image16.ref.png differ
diff --git a/test/reference/ft-variable-font.pdf.ref.png b/test/reference/ft-variable-font.pdf.ref.png
new file mode 100644
index 000000000..f782a8ee4
Binary files /dev/null and b/test/reference/ft-variable-font.pdf.ref.png differ
diff --git a/test/reference/ft-variable-font.ps.ref.png b/test/reference/ft-variable-font.ps.ref.png
new file mode 100644
index 000000000..1e1fdf249
Binary files /dev/null and b/test/reference/ft-variable-font.ps.ref.png differ
diff --git a/test/reference/ft-variable-font.ref.png b/test/reference/ft-variable-font.ref.png
new file mode 100644
index 000000000..49050251a
Binary files /dev/null and b/test/reference/ft-variable-font.ref.png differ
diff --git a/test/reference/ft-variable-font.script.xfail.png b/test/reference/ft-variable-font.script.xfail.png
new file mode 100644
index 000000000..0057da29c
Binary files /dev/null and b/test/reference/ft-variable-font.script.xfail.png differ
diff --git a/test/reference/ft-variable-font.svg.ref.png b/test/reference/ft-variable-font.svg.ref.png
new file mode 100644
index 000000000..eeb99d7c9
Binary files /dev/null and b/test/reference/ft-variable-font.svg.ref.png differ
More information about the cairo-commit
mailing list