[cairo] font size change only in large steps

Alois Treindl alois at astro.ch
Sat Sep 29 08:52:00 UTC 2018


An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20180929/ddd41215/attachment.html>
-------------- next part --------------
#include <cairo.h>
#include <stdio.h>

static void measure(cairo_t *cr, char *s)
{
	cairo_text_extents_t exts;
	cairo_text_extents(cr, "Some text", &exts);

	printf("%s Size: %gx%g", s, exts.width, exts.height);
}

int main()
{
  int i; 
  char t[80];
  double pt;
  cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1000, 1000);
  cairo_t *cr = cairo_create(s);
  cairo_font_options_t *opt, *opt0 = cairo_font_options_create();
  cairo_get_font_options(cr, opt0);
  opt = cairo_font_options_copy(opt0);
  cairo_font_options_set_hint_metrics(opt, CAIRO_HINT_METRICS_OFF);
  for (i = 90; i <= 100; i++) {
    pt = i * 0.1;
    cairo_set_font_size(cr, pt);
    cairo_set_font_options(cr, opt0);
    sprintf(t, "%.1lf pt on ", pt);
    measure(cr, t);
    cairo_set_font_options(cr, opt);
    sprintf(t, "\t%.1lf pt off ", pt);
    measure(cr, t);
    printf("\n");
  }
  cairo_font_options_destroy(opt);
  cairo_destroy(cr);
  cairo_surface_destroy(s);

	return 0;
}


More information about the cairo mailing list