[cairo] PDF: Font size is rounded
Kouhei Sutou
kou at cozmixng.org
Fri Apr 1 13:53:58 UTC 2016
Hi,
In <56FE6110.8070301 at redneon.com>
"Re: [cairo] PDF: Font size is rounded" on Fri, 1 Apr 2016 22:22:48 +1030,
Adrian Johnson <ajohnson at redneon.com> wrote:
>> The specified font size of scaled TrueType font is rounded
>> when PDF surface is used. Is it the expected behavior?
>
> The PDF surface should turn off hinting metrics when generating PDF
> output. Have you tried checking the metrics returned by
> cairo_scaled_font_glyph_extents()?. Use cairo_set_font_options() to turn
> off hinting metrics when doing this.
I didn't tried it. Does the following code implement your
suggestion?
cairo_select_font_face(cr,
"DejaVu Sans Mono",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, font_size);
{
cairo_font_options_t *options;
options = cairo_font_options_create();
cairo_get_font_options(cr, options);
cairo_font_options_set_hint_metrics(options, CAIRO_HINT_METRICS_OFF);
cairo_set_font_options(cr, options);
}
{
cairo_scaled_font_t *font;
cairo_text_extents_t extents;
font = cairo_get_scaled_font(cr);
cairo_scaled_font_text_extents(font, "abcdefghijklm", &extents);
printf("-------------\n"
"font size: %10f\n"
"x_bearing: %10f\n"
"y_bearing: %10f\n"
" width: %10f\n"
" height: %10f\n"
"x_advance: %10f\n"
"y_advance: %10f\n",
font_size,
extents.x_bearing,
extents.y_bearing,
extents.width,
extents.height,
extents.x_advance,
extents.y_advance);
}
The test program with the above change outputs the
following:
-------------
font size: 8.000000
x_bearing: 0.515625
y_bearing: -6.125000
width: 61.718750
height: 7.843750
x_advance: 62.613281
y_advance: 0.000000
-------------
font size: 8.125000
x_bearing: 0.515625
y_bearing: -6.125000
width: 61.718750
height: 7.843750
x_advance: 62.613281
y_advance: 0.000000
-------------
font size: 8.250000
x_bearing: 0.515625
y_bearing: -6.125000
width: 61.718750
height: 7.843750
x_advance: 62.613281
y_advance: 0.000000
(snip)
All of 8.0 font size, 8.125 font size and 8.25 font size
reports the same width and height.
It seems that
cairo_font_options_set_hint_metrics(options, CAIRO_HINT_METRICS_OFF);
doesn't effect the result...
Full program: http://pub.cozmixng.org/~kou/tmp/truetype-size.c
Thanks,
--
kou
More information about the cairo
mailing list