Discussion:
[cairo] font size change only in large steps
Alois Treindl
2018-09-28 12:10:54 UTC
Permalink
--
cairo mailing list
***@cairographics.org
https://lists.cairographics.org/mailman/listinfo/cairo
Alois Treindl
2018-09-28 12:13:39 UTC
Permalink
I send the same as pure text email:

We use cairo do draw and write on bitmap surfaces, or SVG, Postcript and
pdf surfaces.

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.

Example: I print the word Jupiter with font Arial in font sizes 10.7 pt
down to 8.0 pt in steps of 0.1 pt.

I get
pt size size in 1/00 mm string length in 1/100 mm units
10.7 pts 377 cmm 1588
10.6 pts 373 cmm 1588
10.5 pts 370 cmm 1588
10.4 pts 366 cmm 1482
10.3 pts 363 cmm 1482
10.2 pts 359 cmm 1482
10.1 pts 356 cmm 1482
10.0 pts 352 cmm 1482
9.9 pts 349 cmm 1482
9.8 pts 345 cmm 1482
9.7 pts 342 cmm 1376
9.6 pts 338 cmm 1376
9.5 pts 335 cmm 1376
9.4 pts 331 cmm 1376
9.3 pts 328 cmm 1376
9.2 pts 324 cmm 1376
9.1 pts 321 cmm 1376
9.0 pts 317 cmm 1270
8.9 pts 313 cmm 1270
8.8 pts 310 cmm 1270
8.7 pts 306 cmm 1270
8.6 pts 303 cmm 1270
8.5 pts 299 cmm 1270
8.4 pts 296 cmm 1270
8.3 pts 292 cmm 1270
8.2 pts 289 cmm 1164
8.1 pts 285 cmm 1164
8.0 pts 282 cmm 1164

The font size I get is unchanged from 10.7 to 10.5 pt, from 10.4 to 9.8
pt, from 9.7 to 9.1 pt, from 9.0 to 8.3 pt, from 8.2 to 7.6 pt and so on.

I kind of understand this result for a bitmap surface, where fonts are
rendered in a way that they can only change their size by whole pixels.

But the result is exactly the same for PDF or Postscript surfaces.

There, the actual rendering does not happen in cairo, but on the target
device which, for example, prints a PDF or postscript file.
The font rendering engine for Arial is inside the printer, and it may
well be able to render Arial glyphs in many different sizes, depending
on the printer resolution.

Why does this happen in Cairo, and is there a way to get around it, to
get arbitrary font sizes at least for PDF, Postscript of SVG surfaces?

PS: I send a similar posting a few days ago but with png images
attached. This did not make it to the mailing list. I hope this one does.
--
cairo mailing list
***@cairographics.org
htt
Uli Schlachter
2018-09-29 06:12:51 UTC
Permalink
Hi,
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.
Alois Treindl
2018-09-29 08:52:00 UTC
Permalink
#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;
}
Alois Treindl
2018-09-29 08:57:35 UTC
Permalink
sorry, sent html message again which this list dos not accept.
I send a second time.
----
I added font size changes to the example, and print extents with metric
on and off.
The problem which I am addressing appears: font size changes only in steps.

9.0 pt on  Size: 49x7    9.0 pt off  Size: 45.7764x7
9.1 pt on  Size: 49x7    9.1 pt off  Size: 45.7764x7
9.2 pt on  Size: 49x7    9.2 pt off  Size: 45.7764x7
9.3 pt on  Size: 49x7    9.3 pt off  Size: 45.7764x7
9.4 pt on  Size: 49x7    9.4 pt off  Size: 45.7764x7
9.5 pt on  Size: 51x7    9.5 pt off  Size: 50.5293x7
9.6 pt on  Size: 51x7    9.6 pt off  Size: 50.5293x7
9.7 pt on  Size: 51x7    9.7 pt off  Size: 50.5293x7
9.8 pt on  Size: 51x7    9.8 pt off  Size: 50.5293x7
9.9 pt on  Size: 51x7    9.9 pt off  Size: 50.5293x7
10.0 pt on  Size: 51x7    10.0 pt off  Size: 50.5293x7

I ran also the same example but with PDF surface, and get as output:
ctest2
9.0 pt on  Size: 45.4951x6.8125    9.0 pt off  Size: 45.4951x6.8125
9.1 pt on  Size: 45.4951x6.8125    9.1 pt off  Size: 45.4951x6.8125
9.2 pt on  Size: 45.4951x6.8125    9.2 pt off  Size: 45.4951x6.8125
9.3 pt on  Size: 45.4951x6.8125    9.3 pt off  Size: 45.4951x6.8125
9.4 pt on  Size: 45.4951x6.8125    9.4 pt off  Size: 45.4951x6.8125
9.5 pt on  Size: 50.5605x7.5625    9.5 pt off  Size: 50.5605x7.5625
9.6 pt on  Size: 50.5605x7.5625    9.6 pt off  Size: 50.5605x7.5625
9.7 pt on  Size: 50.5605x7.5625    9.7 pt off  Size: 50.5605x7.5625
9.8 pt on  Size: 50.5605x7.5625    9.8 pt off  Size: 50.5605x7.5625
9.9 pt on  Size: 50.5605x7.5625    9.9 pt off  Size: 50.5605x7.5625
10.0 pt on  Size: 50.5605x7.5625    10.0 pt off  Size: 50.5605x7.5625

with PDF, metrics on or off makes no difference. But the font size
changes are in steps.
Post by Uli Schlachter
Hi,
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
Alois Treindl
2018-09-29 09:25:26 UTC
Permalink
It is important to know which version of cairo I am using.

The sample I posted earlier is run on cairo-1.14.8-2.el7.x86_64on RHEL7.5

The problem appeared only with the update of Redhat Linux from RHEL6 to
RHEL7.

If I run the samples on the old machine, which has
cairo-1.10.2-1.el6.x86_64, the fonts scale properly:

[***@as81 devlop]$ ctest1  bitmap surface
9.0 pt on  Size: 45x7    9.0 pt off  Size: 45.7764x7
9.1 pt on  Size: 45x7    9.1 pt off  Size: 46.222x7
9.2 pt on  Size: 45x7    9.2 pt off  Size: 46.7418x7
9.3 pt on  Size: 46x7    9.3 pt off  Size: 47.1874x7
9.4 pt on  Size: 46x7    9.4 pt off  Size: 47.7072x7
9.5 pt on  Size: 46x7    9.5 pt off  Size: 48.1528x7
9.6 pt on  Size: 46x8    9.6 pt off  Size: 48.5984x8
9.7 pt on  Size: 46x8    9.7 pt off  Size: 49.1183x8
9.8 pt on  Size: 48x8    9.8 pt off  Size: 49.5639x8
9.9 pt on  Size: 53x8    9.9 pt off  Size: 50.0837x8
10.0 pt on  Size: 55x8    10.0 pt off  Size: 50.5293x8

[***@as81 devlop]$ ctest2  PDF surface
9.0 pt on  Size: 45.4951x6.8125    9.0 pt off  Size: 45.4951x6.8125
9.1 pt on  Size: 45.9407x6.8125    9.1 pt off  Size: 45.9407x6.8125
9.2 pt on  Size: 46.4606x6.8125    9.2 pt off  Size: 46.4606x6.8125
9.3 pt on  Size: 46.9062x6.8125    9.3 pt off  Size: 46.9062x6.8125
9.4 pt on  Size: 47.426x6.8125    9.4 pt off  Size: 47.426x6.8125
9.5 pt on  Size: 48.1841x7.5625    9.5 pt off  Size: 48.1841x7.5625
9.6 pt on  Size: 48.6297x7.5625    9.6 pt off  Size: 48.6297x7.5625
9.7 pt on  Size: 49.1496x7.5625    9.7 pt off  Size: 49.1496x7.5625
9.8 pt on  Size: 49.5951x7.5625    9.8 pt off  Size: 49.5951x7.5625
9.9 pt on  Size: 50.115x7.5625    9.9 pt off  Size: 50.115x7.5625
10.0 pt on  Size: 50.5605x7.5625    10.0 pt off  Size: 50.5605x7.5625

What happened between cairo 1.10 and cairo 1.14 to cause this issue?
Post by Alois Treindl
sorry, sent html message again which this list dos not accept.
I send a second time.
----
I added font size changes to the example, and print extents with
metric on and off.
The problem which I am addressing appears: font size changes only in steps.
9.0 pt on  Size: 49x7    9.0 pt off  Size: 45.7764x7
9.1 pt on  Size: 49x7    9.1 pt off  Size: 45.7764x7
9.2 pt on  Size: 49x7    9.2 pt off  Size: 45.7764x7
9.3 pt on  Size: 49x7    9.3 pt off  Size: 45.7764x7
9.4 pt on  Size: 49x7    9.4 pt off  Size: 45.7764x7
9.5 pt on  Size: 51x7    9.5 pt off  Size: 50.5293x7
9.6 pt on  Size: 51x7    9.6 pt off  Size: 50.5293x7
9.7 pt on  Size: 51x7    9.7 pt off  Size: 50.5293x7
9.8 pt on  Size: 51x7    9.8 pt off  Size: 50.5293x7
9.9 pt on  Size: 51x7    9.9 pt off  Size: 50.5293x7
10.0 pt on  Size: 51x7    10.0 pt off  Size: 50.5293x7
ctest2
9.0 pt on  Size: 45.4951x6.8125    9.0 pt off  Size: 45.4951x6.8125
9.1 pt on  Size: 45.4951x6.8125    9.1 pt off  Size: 45.4951x6.8125
9.2 pt on  Size: 45.4951x6.8125    9.2 pt off  Size: 45.4951x6.8125
9.3 pt on  Size: 45.4951x6.8125    9.3 pt off  Size: 45.4951x6.8125
9.4 pt on  Size: 45.4951x6.8125    9.4 pt off  Size: 45.4951x6.8125
9.5 pt on  Size: 50.5605x7.5625    9.5 pt off  Size: 50.5605x7.5625
9.6 pt on  Size: 50.5605x7.5625    9.6 pt off  Size: 50.5605x7.5625
9.7 pt on  Size: 50.5605x7.5625    9.7 pt off  Size: 50.5605x7.5625
9.8 pt on  Size: 50.5605x7.5625    9.8 pt off  Size: 50.5605x7.5625
9.9 pt on  Size: 50.5605x7.5625    9.9 pt off  Size: 50.5605x7.5625
10.0 pt on  Size: 50.5605x7.5625    10.0 pt off  Size: 50.5605x7.5625
with PDF, metrics on or off makes no difference. But the font size
changes are in steps.
Post by Uli Schlachter
Hi,
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
Alois Treindl
2018-09-29 10:04:44 UTC
Permalink
The good news is:

I downloaded cairo source 1.14.12 and compiled it on RHEL 7.5, which
creates libcairo.so.2.11400.12

If I throw this into /usr/lib64 and run ldconfig, the problem goes away.

Font size varies in steps as it should.


[***@as80 devlop]$ ctest1  bitmap
9.0 pt on  Size: 49x7    9.0 pt off  Size: 45.4966x6.80713
9.1 pt on  Size: 49x7    9.1 pt off  Size: 46.0021x6.88276
9.2 pt on  Size: 49x7    9.2 pt off  Size: 46.5076x6.9584
9.3 pt on  Size: 49x7    9.3 pt off  Size: 47.0131x7.03403
9.4 pt on  Size: 49x7    9.4 pt off  Size: 47.5187x7.10967
9.5 pt on  Size: 51x7    9.5 pt off  Size: 48.0242x7.1853
9.6 pt on  Size: 51x7    9.6 pt off  Size: 48.5297x7.26094
9.7 pt on  Size: 51x7    9.7 pt off  Size: 49.0352x7.33657
9.8 pt on  Size: 51x7    9.8 pt off  Size: 49.5407x7.41221
9.9 pt on  Size: 51x7    9.9 pt off  Size: 50.0462x7.48784
10.0 pt on  Size: 51x7    10.0 pt off  Size: 50.5518x7.56348

[***@as80 devlop]$ ctest2  PDF
9.0 pt on  Size: 45.4966x6.80713    9.0 pt off  Size: 45.4966x6.80713
9.1 pt on  Size: 46.0021x6.88276    9.1 pt off  Size: 46.0021x6.88276
9.2 pt on  Size: 46.5076x6.9584    9.2 pt off  Size: 46.5076x6.9584
9.3 pt on  Size: 47.0131x7.03403    9.3 pt off  Size: 47.0131x7.03403
9.4 pt on  Size: 47.5187x7.10967    9.4 pt off  Size: 47.5187x7.10967
9.5 pt on  Size: 48.0242x7.1853    9.5 pt off  Size: 48.0242x7.1853
9.6 pt on  Size: 48.5297x7.26094    9.6 pt off  Size: 48.5297x7.26094
9.7 pt on  Size: 49.0352x7.33657    9.7 pt off  Size: 49.0352x7.33657
9.8 pt on  Size: 49.5407x7.41221    9.8 pt off  Size: 49.5407x7.41221
9.9 pt on  Size: 50.0462x7.48784    9.9 pt off  Size: 50.0462x7.48784
10.0 pt on  Size: 50.5518x7.56348    10.0 pt off  Size: 50.5518x7.56348
Post by Alois Treindl
It is important to know which version of cairo I am using.
The sample I posted earlier is run on cairo-1.14.8-2.el7.x86_64on RHEL7.5
The problem appeared only with the update of Redhat Linux from RHEL6
to RHEL7.
If I run the samples on the old machine, which has
Loading...