Re: font size change only in large steps
Uli Schlachter <[email protected]> Sat, 29 Sep 2018 08:12:51 +0200
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <[email protected]> |
Hi, On 28.09.2018 14:10, Alois Treindl wrote: > I noticed that cairo does not allow me to set a precise font size, like 9.4 pt > or 9.7 pt. > What I get is exactly the same font size, for a range of font sizes. Try disabling metrics hinting via CAIRO_HINT_METRICS_OFF. See the attached example program. Per the docs, this metrics hinting quantizises font metrics so that they are integer values in device space, i.e. does exactly what you are trying to get rid of. You might also want to do cairo_font_options_set_hint_style(opt, CAIRO_HINT_STYLE_NONE), depending on, well, if you want the font outlines to be hinted or not. Cheers, Uli -- Sent from my Game Boy. -- cairo mailing list [email protected] https://lists.cairographics.org/mailman/listinfo/cairo
test.c
(text/x-csrc, 712 B)
#include <cairo.h>
#include <stdio.h>
static void measure(cairo_t *cr)
{
cairo_text_extents_t exts;
cairo_text_extents(cr, "Some text", &exts);
printf("Size: %gx%g\n", exts.width, exts.height);
}
int main()
{
cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);
cairo_t *cr = cairo_create(s);
cairo_font_options_t *opt = cairo_font_options_create();
measure(cr);
cairo_get_font_options(cr, opt);
cairo_font_options_set_hint_metrics(opt, CAIRO_HINT_METRICS_OFF);
/*cairo_font_options_set_hint_style(opt, CAIRO_HINT_STYLE_NONE);*/
cairo_set_font_options(cr, opt);
measure(cr);
cairo_font_options_destroy(opt);
cairo_destroy(cr);
cairo_surface_destroy(s);
return 0;
}