aboutsummaryrefslogtreecommitdiff
path: root/font.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-17 20:50:26 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-17 20:50:26 +0000
commit89450bfd44dfc0739d20c48e82fbaa5ecf58a818 (patch)
treee7c4719a6cce69520b3783012488efaaeb540dfb /font.c
parentselection: implement double-click-to-select-word (diff)
font: sync cairo's options with the FC pattern
Configure cairo's 'options' with default values, then update the FontConfig pattern. Finally, update the cairo options after having retrieved the final FontConfig option.
Diffstat (limited to 'font.c')
-rw-r--r--font.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/font.c b/font.c
index 12002e46..74357f9b 100644
--- a/font.c
+++ b/font.c
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdbool.h>
+#include <assert.h>
#include <fontconfig/fontconfig.h>
#include <cairo-ft.h>
@@ -35,6 +36,12 @@ font_from_name(const char *name)
return NULL;
}
+ cairo_font_options_t *options = cairo_font_options_create();
+ cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_DEFAULT);
+ cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_DEFAULT);
+ cairo_font_options_set_subpixel_order(options, CAIRO_SUBPIXEL_ORDER_DEFAULT);
+ cairo_ft_font_options_substitute(options, pattern);
+
FcDefaultSubstitute(pattern);
FcResult result;
@@ -46,6 +53,23 @@ font_from_name(const char *name)
return NULL;
}
+ FcBool fc_hinting, fc_antialias;
+ if (FcPatternGetBool(final_pattern, FC_HINTING,0, &fc_hinting) != FcResultMatch) {
+ LOG_WARN("failed to get fontconfig hinting style");
+ fc_hinting = FcTrue;
+ }
+
+ if (FcPatternGetBool(final_pattern, FC_ANTIALIAS, 0, &fc_antialias) != FcResultMatch) {
+ LOG_WARN("failed to get fontconfig antialias");
+ fc_antialias = FcTrue;
+ }
+
+ cairo_font_options_set_hint_style(
+ options, fc_hinting ? CAIRO_HINT_STYLE_DEFAULT : CAIRO_HINT_STYLE_NONE);
+ cairo_font_options_set_antialias(
+ options, fc_antialias ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
+ assert(cairo_font_options_get_antialias(options) == CAIRO_ANTIALIAS_NONE);
+
double size;
if (FcPatternGetDouble(final_pattern, FC_PIXEL_SIZE, 0, &size)) {
LOG_ERR("%s: failed to get size", name);
@@ -68,7 +92,6 @@ font_from_name(const char *name)
cairo_matrix_init_identity(&ctm);
cairo_matrix_init_scale(&matrix, size, size);
- cairo_font_options_t *options = cairo_font_options_create();
cairo_scaled_font_t *scaled_font = cairo_scaled_font_create(
face, &matrix, &ctm, options);