Re: Scaled fixed size fonts
Fred Kiefer <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <[email protected]> |
It took me a bit longer to find the time to write up a simple example. I started of with one of the example files I found on this list. It simply creates an SVG surface and writes two lines of text in two different point sizes. Run the code as it is now, copy the result to somewhere save and then exchange the two writing blocks and run it again. In the first case the second line will look horrible in the second case that line is OK, but the first one is unreadable. This proves that for fixed sized fonts the font selection is order dependent and that the first selected font will be scaled for other sizes. Does this explain the issue in enough detail? As I explained in my original mail, this has nothing to do with the SVG backend, I only use that to show the issue. It is caused by the way the FT fonts get created. Please take the time to scroll down to the original mail. Fred On 14.01.2014 09:25, Fred Kiefer wrote: > Hi Behdad, > > I hope to find time to write a full example later today. Here a > simple way to reproduce the issue. Create a font face for one of the > Adobe fixed fonts. Create a scaled font with 12 pixel size. Next > create another scaled font from the font face with 24 pixel size use > that for drawing. The 12 pixel font will get used, but scaled to 24 > pixel. > > Fred > > On the road > > Am 14.01.2014 um 09:12 schrieb Behdad Esfahbod <[email protected]>: > >> Hi, >> >> Your message is a bit vague in details. Do you have a simple test >> case? >> >> behdad >> >>> On 14-01-06 03:48 AM, Fred Kiefer wrote: In the GNUstep project >>> we use cairo as our default drawing backend. One user complained >>> that with cairo some fonts get displayed worse than with the >>> direct xlib based backend. It turns out that on this computer >>> only the Adobe fonts are installed and this are fixed size >>> fonts. I investigated a bit in our code and later in the cairo >>> code and this burns down to the function >>> cairo_scaled_font_create() returning not the best suited fixed >>> size font, but a scaled version of the standard 12 point font. >>> >>> The reason is that _cairo_ft_font_face_get_implementation() in >>> cairo-ft-font.c reuses the same resolved font even when the font >>> isn't scalable and the matrix did change. My suggestion now is to >>> extend the tests in this function to first inspect the pattern >>> whether it is scalable. If it isn't, compare the pixel size of >>> the cached resolved font with the new pixel size (This code needs >>> to be extracted from _cairo_ft_resolve_pattern) and if that >>> doesn't match within certain limits (which might be the hard bit >>> to define) the old resolved font gets thrown away and replaced by >>> a newly created one. Or we leave the cached one alone and just >>> create a new one? >>> >>> This solution will use up more resource than the current one and >>> if there is no better matching fixed pixel font it will result in >>> the same display with a lot more overhead. Still for some cases >>> it will result in better drawn fonts. And for the most common >>> case where scalable fonts get used it will be almost no >>> overhead. >>> >>> Would cairo be willing to accept a patch in this direction? I am >>> willing to write one, but only if this effort isn't completely >>> wasted. -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo
t.c
(text/x-csrc, 1.2 KB)
#include "cairo.h"
#include "cairo-svg.h"
int main(int argc, char* argv[])
{
double font_size = 12.0,
height = 200.0,
left = 15.0,
line1 = 30.0,
line2 = 70.0,
width = 200.0;
char *filename = "temp.svg",
*text = "This is a Test";
cairo_surface_t *surface = cairo_svg_surface_create(filename,
width,
height);
//cairo_svg_surface_restrict_to_version (surface, CAIRO_SVG_VERSION_1_1);
cairo_t* cr = cairo_create (surface);
int size = height * width;
int data[size];
cairo_select_font_face (cr,
"Adobe Helvetica",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size (cr, (double)font_size);
cairo_move_to (cr, left, line1);
cairo_show_text (cr, text);
cairo_set_font_size (cr, (double)2*font_size);
cairo_move_to (cr, left, line2);
cairo_show_text (cr, text);
cairo_fill(cr);
cairo_destroy(cr);
cairo_surface_finish(surface);
cairo_surface_destroy(surface);
return 0;
}