diff options
author | Adrian Johnson <ajohnson@redneon.com> | 2024-01-17 02:23:27 +0000 |
---|---|---|
committer | Adrian Johnson <ajohnson@redneon.com> | 2024-01-17 02:23:27 +0000 |
commit | 61da2c20587a47b59e693d3a562b848418715bda (patch) | |
tree | cb16189c63aca49d3af95cbc90968b3827fe053e | |
parent | ee07a8118527fd1b672c3de6a2ae3b4607487737 (diff) | |
parent | 3bcad03f6bc33c436122f4acaefc9e58caa37116 (diff) |
Merge branch 'font-options' into 'master'
Copy font-options during creation of a fallback font
Closes #819
See merge request cairo/cairo!530
-rw-r--r-- | .gitlab-ci.yml | 1 | ||||
-rw-r--r-- | src/cairo-scaled-font-subsets.c | 1 | ||||
-rw-r--r-- | src/cairo-type1-fallback.c | 1 | ||||
-rw-r--r-- | test/ft-variable-font.c | 127 | ||||
-rw-r--r-- | test/meson.build | 1 | ||||
-rw-r--r-- | test/reference/ft-variable-font.image16.ref.png | bin | 0 -> 3871 bytes | |||
-rw-r--r-- | test/reference/ft-variable-font.pdf.ref.png | bin | 0 -> 4379 bytes | |||
-rw-r--r-- | test/reference/ft-variable-font.ps.ref.png | bin | 0 -> 2564 bytes | |||
-rw-r--r-- | test/reference/ft-variable-font.ref.png | bin | 0 -> 4413 bytes | |||
-rw-r--r-- | test/reference/ft-variable-font.script.xfail.png | bin | 0 -> 4316 bytes | |||
-rw-r--r-- | test/reference/ft-variable-font.svg.ref.png | bin | 0 -> 4359 bytes |
11 files changed, 131 insertions, 0 deletions
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@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 Binary files differnew file mode 100644 index 000000000..94d4d63c4 --- /dev/null +++ b/test/reference/ft-variable-font.image16.ref.png diff --git a/test/reference/ft-variable-font.pdf.ref.png b/test/reference/ft-variable-font.pdf.ref.png Binary files differnew file mode 100644 index 000000000..f782a8ee4 --- /dev/null +++ b/test/reference/ft-variable-font.pdf.ref.png diff --git a/test/reference/ft-variable-font.ps.ref.png b/test/reference/ft-variable-font.ps.ref.png Binary files differnew file mode 100644 index 000000000..1e1fdf249 --- /dev/null +++ b/test/reference/ft-variable-font.ps.ref.png diff --git a/test/reference/ft-variable-font.ref.png b/test/reference/ft-variable-font.ref.png Binary files differnew file mode 100644 index 000000000..49050251a --- /dev/null +++ b/test/reference/ft-variable-font.ref.png diff --git a/test/reference/ft-variable-font.script.xfail.png b/test/reference/ft-variable-font.script.xfail.png Binary files differnew file mode 100644 index 000000000..0057da29c --- /dev/null +++ b/test/reference/ft-variable-font.script.xfail.png diff --git a/test/reference/ft-variable-font.svg.ref.png b/test/reference/ft-variable-font.svg.ref.png Binary files differnew file mode 100644 index 000000000..eeb99d7c9 --- /dev/null +++ b/test/reference/ft-variable-font.svg.ref.png |