[cairo] PDF: Font size is rounded
Adrian Johnson
ajohnson at redneon.com
Sat Apr 2 03:46:27 UTC 2016
On 02/04/16 00:23, Kouhei Sutou wrote:
> 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.
I put some printfs in _cairo_ft_scaled_glyph_init (in cairo-ft-font.c).
It appears that FreeType is returning hinted metrics. I'm guessing that
to get unhinted metrics of TrueType fonts we need to set the scale to
the EM size like we do for win32 fonts.
I'm attaching a patch to do this. It fixes your test case. I don't know
if this patch is the correct way to fix the problem. I am not familiar
with the FreeType font backend.
> 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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-FT-scale-to-em-size-to-get-unhinted-metrics.patch
Type: text/x-patch
Size: 1191 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20160402/9a71d491/attachment.bin>
More information about the cairo
mailing list