Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » RichText,QTF,RTF... » Font alignment issues
Re: Font alignment issues [message #22651 is a reply to message #22650] Mon, 03 August 2009 13:46 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
BTW, unfortunately, benchmark revealed that this optization provides significant benefits.... (about 20x for 30 characters of Arial(20)).

Mirek
Re: Font alignment issues [message #22652 is a reply to message #22651] Mon, 03 August 2009 13:56 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 169
Registered: May 2007
Location: Grenoble, France
Experienced Member
OK, here are the screenshots:



Without fix:
index.php?t=getfile&id=1868&private=0

With fix:
index.php?t=getfile&id=1869&private=0



Lionel
Re: Font alignment issues [message #22653 is a reply to message #22652] Mon, 03 August 2009 14:17 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Excellent. Look at some identifiers like Point... I believe that metrics simply do not match glyphs (we have sort of forced them on by removing the optimization).

Thinking about the issue:

It looks like you are using subpixel rendering. Can you please remove the fix and try other modes?

I think this might be the issue. Maybe truetype is returning different metrics based on hinting style; and we are only using "raw" mode for metrics...

That would also explain why it works with bigger fonts, sort of.

Mirek
Re: Font alignment issues [message #22654 is a reply to message #22653] Mon, 03 August 2009 14:39 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 169
Registered: May 2007
Location: Grenoble, France
Experienced Member
Thanks for the hints Mirek.

I tried without subpixel rendering but the problem is the same.

In fact, I found where the problem comes from :

for some reason I can't remember, but probably to get harmonized font sizes between gtk apps and other ones, I switched my dpi to 88 (I think it is 96 naturally). I used 96 dpi instead of 88 and all the issues are gone, see by yourself :

index.php?t=getfile&id=1870&private=0

It reminds me some topics where you were talking about the dpi concept problem, and the way it was badly handled by other libraries.

Is that normal that when specifying a wrong dpi (that is configurable so after all, I believe other people do like me), I get thoses issues ? Are there several ways to get proper font hinting size ?

Thanks for your help,
Lionel

[Updated on: Mon, 03 August 2009 14:39]

Report message to a moderator

Re: Font alignment issues [message #22655 is a reply to message #22654] Mon, 03 August 2009 14:47 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
chickenk wrote on Mon, 03 August 2009 08:39

Thanks for the hints Mirek.

I tried without subpixel rendering but the problem is the same.




Actually, very good news Smile

Quote:


In fact, I found where the problem comes from :

for some reason I can't remember, but probably to get harmonized font sizes between gtk apps and other ones, I switched my dpi to 88 (I think it is 96 naturally). I used 96 dpi instead of 88 and all the issues are gone, see by yourself :



Nice! I knew there must be something differnt with your system...

Quote:


Is that normal that when specifying a wrong dpi (that is configurable so after all, I believe other people do like me), I get thoses issues ? Are there several ways to get proper font hinting size ?

Thanks for your help,
Lionel


Going to try & fix....

Mirek

[Updated on: Mon, 03 August 2009 14:49]

Report message to a moderator

Re: Font alignment issues [message #22657 is a reply to message #22655] Mon, 03 August 2009 15:17 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, I was not able to reproduce the problem by changing dpi (at least changing it in Appearance of Gnome - did you meant "other" dpi?).

Anyway, I have tried to add FC_DPI to font pattern, it does not seem to make things worse, maybe it will make it better. Please check svn for "Attempt to fix linux/dpi" and report.

Thanks for your help.

Mirek
Re: Font alignment issues [message #22658 is a reply to message #22657] Mon, 03 August 2009 16:31 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 169
Registered: May 2007
Location: Grenoble, France
Experienced Member
OK I recompiled the new sources, the bad news are it does not change anything in my case. As far as I use 88 dpi instead of 96, the display is wrong...

I am not sure it's worth taking so much of your time about that. It may be a rare case coming from my configuration (I'm still wondering what have I done to have such differences, I can't see...).

If you think it's important to fix it because it applies to many people, I'll be glad to help you. But don't waste your time just for my case, I can live with it. Very Happy

Lionel
Re: Font alignment issues [message #22659 is a reply to message #22658] Mon, 03 August 2009 17:13 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
chickenk wrote on Mon, 03 August 2009 10:31

OK I recompiled the new sources, the bad news are it does not change anything in my case. As far as I use 88 dpi instead of 96, the display is wrong...

I am not sure it's worth taking so much of your time about that. It may be a rare case coming from my configuration (I'm still wondering what have I done to have such differences, I can't see...).

If you think it's important to fix it because it applies to many people, I'll be glad to help you. But don't waste your time just for my case, I can live with it. Very Happy

Lionel


Well, I am afraid it might kick us somewhere else... Font metrics is foundation, there is no place for weird behaviour...

Another attempt:

Draw::FontFc.cpp:

FcPattern *CreateFcPattern(Font font)
{
	LTIMING("CreateXftFont");
	double sina, cosa;
	int hg = abs(font.GetHeight());
	if(hg == 0) hg = 10;
	String face = font.GetFaceName();
	FcPattern *p = FcPatternCreate();
	FcPatternAddString(p, FC_FAMILY, (FcChar8*)~face);
	FcPatternAddInteger(p, FC_SLANT, font.IsItalic() ? 110 : 0);
	FcPatternAddInteger(p, FC_PIXEL_SIZE, hg);
	FcPatternAddInteger(p, FC_DPI, 96);
	FcPatternAddInteger(p, FC_WEIGHT, font.IsBold() ? 200 : 100);
	FcPatternAddBool(p, FC_MINSPACE, 1);
	FcResult result;
	FcConfigSubstitute(0, p, FcMatchPattern);
	FcDefaultSubstitute(p);
	FcPattern *m = FcFontMatch(0, p, &result);
	FcPatternDestroy(p);
	return m;
}


CtrlCore/DrawTextX11.cpp:

XftFont *CreateXftFont(Font font, int angle)
{
	LTIMING("CreateXftFont");
	XftFont *xftfont;
	double sina, cosa;
	Std(font);
	int hg = abs(font.GetHeight());
	if(hg == 0) hg = 10;
	int i = font.GetFace();
	if(i < 0 || i >= Font::GetFaceCount())
		i = 0;
	String face = font.GetFaceName();
	FcPattern *p = FcPatternCreate();
	FcPatternAddString(p, FC_FAMILY, (FcChar8*)~face);
	FcPatternAddInteger(p, FC_SLANT, font.IsItalic() ? 110 : 0);
	FcPatternAddInteger(p, FC_PIXEL_SIZE, hg);
	FcPatternAddInteger(p, FC_DPI, 96);
	FcPatternAddInteger(p, FC_WEIGHT, font.IsBold() ? 200 : 100);
	FcPatternAddBool(p, FC_MINSPACE, 1);
	if(angle) {
		FcMatrix mx;
		Draw::SinCos(angle, sina, cosa);
		mx.xx = cosa;
		mx.xy = -sina;
		mx.yx = sina;
		mx.yy = cosa;
		FcPatternAddMatrix(p, FC_MATRIX, &mx);
	}
	FcResult result;
	FcPattern *m = XftFontMatch(Xdisplay, Xscreenno, p, &result);
	if(font.IsNonAntiAliased() || gtk_antialias >= 0) {
		FcPatternDel(m, FC_ANTIALIAS);
		FcPatternAddBool(m, FC_ANTIALIAS,
		                 font.IsNonAntiAliased() ? FcFalse : gtk_antialias ? FcTrue : FcFalse);
	}
	if(gtk_hinting >= 0) {
		FcPatternDel(m, FC_HINTING);
		FcPatternAddBool(m, FC_HINTING, gtk_hinting);
	}
	const char *hs[] = { "hintnone", "hintslight", "hintmedium", "hintfull" };
	for(int i = 0; i < 4; i++)
		if(gtk_hintstyle == hs[i]) {
			FcPatternDel(m, FC_HINT_STYLE);
			FcPatternAddInteger(m, FC_HINT_STYLE, i);
		}
	const char *rgba[] = { "_", "rgb", "bgr", "vrgb", "vbgr" };
	for(int i = 0; i < __countof(rgba); i++)
		if(gtk_rgba == rgba[i]) {
			FcPatternDel(m, FC_RGBA);
			FcPatternAddInteger(m, FC_RGBA, i);
		}
	xftfont = XftFontOpenPattern(Xdisplay, m);
	FcPatternDestroy(p);
	return xftfont;
}


(We try to tell him in both cases to use 96dpi - which is fine, because at the time we have are only using correct pixel size).

Mirek
Re: Font alignment issues [message #22660 is a reply to message #22659] Mon, 03 August 2009 17:22 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 169
Registered: May 2007
Location: Grenoble, France
Experienced Member
sorry... still messed up.

I don't have much time left to think about it today, so I'll make other tries tomorrow.

Thank you for your patience

Lionel
Re: Font alignment issues [message #22661 is a reply to message #22660] Mon, 03 August 2009 17:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
chickenk wrote on Mon, 03 August 2009 11:22

sorry... still messed up.

I don't have much time left to think about it today, so I'll make other tries tomorrow.

Thank you for your patience

Lionel


Too bad... If only I could reproduce the problem...

Mirek
Re: Font alignment issues [message #22673 is a reply to message #22651] Tue, 04 August 2009 11:26 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
luzr wrote on Mon, 03 August 2009 14:46

BTW, unfortunately, benchmark revealed that this optization provides significant benefits.... (about 20x for 30 characters of Arial(20)).

Mirek

As a side note, what was the optimization about? Do you mean that using a single call to X to draw the characters is 20x faster than using 30 calls to X? My own custom code for printing text is kind of slow but I thought that X is just slow at handling different fonts. So slow that you can barely print a screen full of text in “real” time. I use one character at a time printing.
Re: Font alignment issues [message #22677 is a reply to message #22673] Tue, 04 August 2009 17:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
cbpporter wrote on Tue, 04 August 2009 05:26

luzr wrote on Mon, 03 August 2009 14:46

BTW, unfortunately, benchmark revealed that this optization provides significant benefits.... (about 20x for 30 characters of Arial(20)).

Mirek

As a side note, what was the optimization about? Do you mean that using a single call to X to draw the characters is 20x faster than using 30 calls to X?



Well, I have tested in Win32, but this is what I have found. Situation in X11 can be different.

Quote:


My own custom code for printing text is kind of slow but I thought that X is just slow at handling different fonts. So slow that you can barely print a screen full of text in “real” time. I use one character at a time printing.



Hard to say. I am not sure how much custom your code is; in any case you might want to check Xft sources, if that is what you are using...

Mirek
Re: Font alignment issues [message #22722 is a reply to message #22673] Sat, 08 August 2009 19:46 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
cbpporter wrote on Tue, 04 August 2009 05:26

luzr wrote on Mon, 03 August 2009 14:46

BTW, unfortunately, benchmark revealed that this optization provides significant benefits.... (about 20x for 30 characters of Arial(20)).

Mirek

As a side note, what was the optimization about? Do you mean that using a single call to X to draw the characters is 20x faster than using 30 calls to X? My own custom code for printing text is kind of slow but I thought that X is just slow at handling different fonts. So slow that you can barely print a screen full of text in “real” time. I use one character at a time printing.



I have just tested in X11/Xft (Fedora code, default install) - single char printing is 26x slower...

Means, printing more than single glyph at time is quite a good idea...

Mirek
Re: Font alignment issues [message #22724 is a reply to message #22722] Sun, 09 August 2009 00:12 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
It was tough fight, but I believe the issue (88dpi, 9pt, subpixel rendering -> wrong text metrics) is now solved.

PLEASE CHECK!

Mirek
Re: Font alignment issues [message #22736 is a reply to message #22724] Mon, 10 August 2009 09:17 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 169
Registered: May 2007
Location: Grenoble, France
Experienced Member
Hi Mirek,

this time it works GREAT !!! Surprised

Thank you for fighting this out and all the great work you've done.

I just have a quick question: is it intended behavior that the navigator bar list does not take dpi into account? To make a try I used a very small dpi (50). Normal text is hardly readable at this dpi on my PC. I launched theIDE and I discovered that the bottom list of the navigator bar uses the same font size (in pixels) than when I use 88 or 96 dpi. That is really not a problem for me, just wanted to check if it is intended behaviour.

Best regards,
Lionel
Re: Font alignment issues [message #22740 is a reply to message #22736] Mon, 10 August 2009 16:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
chickenk wrote on Mon, 10 August 2009 03:17


I just have a quick question: is it intended behavior that the navigator bar list does not take dpi into account? To make a try I used a very small dpi (50). Normal text is hardly readable at this dpi on my PC. I launched theIDE and I discovered that the bottom list of the navigator bar uses the same font size (in pixels) than when I use 88 or 96 dpi. That is really not a problem for me, just wanted to check if it is intended behaviour.



Well, after some checking, the reason is that the font is scaled using layout scale (VertLayoutZoom).

Anyway, there is "small font size" protection in layout scaling - basically, layout are not scaled down below designed size. They can only scale up. This is to avoid numerous troubles in the process. Here, this heurestics applies to the font too.

I am not sure whether this is worth fixing.

Mirek
Re: Font alignment issues [message #22752 is a reply to message #22740] Tue, 11 August 2009 10:38 Go to previous messageGo to next message
masu is currently offline  masu
Messages: 378
Registered: February 2006
Senior Member
Mirek,

I cannot link with CtrlCore package anymore using NOGTK flag after you had fixed this issue.
The error is located in CtrlCore/DrawTextX11.cpp which uses parts of GTK library without respecting NOGTK flag.

Matthias
Re: Font alignment issues [message #22753 is a reply to message #22752] Tue, 11 August 2009 13:29 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
masu wrote on Tue, 11 August 2009 04:38

Mirek,

I cannot link with CtrlCore package anymore using NOGTK flag after you had fixed this issue.
The error is located in CtrlCore/DrawTextX11.cpp which uses parts of GTK library without respecting NOGTK flag.

Matthias


Fixed.

Mirek
Previous Topic: how get font height
Next Topic: Problem with pasting images with transparency
Goto Forum:
  


Current Time: Thu Mar 28 11:37:39 CET 2024

Total time taken to generate the page: 0.01314 seconds