U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » RichText,QTF,RTF... » Font alignment issues
Font alignment issues [message #22516] Tue, 21 July 2009 13:40 Go to next message
chickenk is currently offline  chickenk
Messages: 171
Registered: May 2007
Location: Grenoble, France
Experienced Member
Hi Mirek,

I am using the latest svn revision (r1439).

I am not sure this is the correct place for this post, which is related to fonts under unix.

A. In the Navigator bar

Some special characters miss some space to be aligned correctly. It can be seen on the screenshot below (look at the '>' and '<' characters. I also saw that problem on '&' characters).

http://www.ultimatepp.org/forum/index.php?t=getfile&id=1857&private=0

B. Standard and underlined characters not the same width

When using a standard app (TestScatter2 in this example), pressing Alt underlines the characters used for shortcuts. Since the new Draw and fonts refactoring, it seems the underlined characters don't always have the same width than previously non-underlined one. Again, 2 screenshots to illustrate (open them in 2 tabs and switch between them to see the problem):

Normal
Pressing Alt key

Thanks for having a look!

regards,
Lionel
Re: Font alignment issues [message #22545 is a reply to message #22516] Sun, 26 July 2009 05:04 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
I have problems to reproduce it. I am testing on Ubuntu 8.04.

Perhaps it was fixed already?

If not, any details about your platform?

Mirek
Re: Font alignment issues [message #22560 is a reply to message #22545] Mon, 27 July 2009 09:04 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 171
Registered: May 2007
Location: Grenoble, France
Experienced Member
Hi Mirek,

I tried with latest svn. Still the same.

Here are my OS characteristics (that may be relevant for you, ask if you need more):

- Linux Fedora Core 11
- X.Org X Server 1.6.1.901 (1.6.2 RC 1)
- theide-svn compiled in 'GCC Optimal' mode, the applied flags are 'GUI MAIN GCC SHARED LINUX POSIX'
- GTK+ 2.16.2 (and associates)
- Window Manager: Enlightenment DR17 (in Gnome I have the same result)

I removed the .upp/theide-svn directory to start again with a fresh configuration, to make sure it did not come from customized fonts. Still the same problem.

I don't know what else you could need, so don't hesitate to ask me.

Update: in NOGTK mode, the display works fine. I believe this may be related to gtk font handling... I'll search more.

Lionel

[Updated on: Mon, 27 July 2009 09:35]

Report message to a moderator

Re: Font alignment issues [message #22567 is a reply to message #22560] Mon, 27 July 2009 17:01 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
chickenk wrote on Mon, 27 July 2009 03:04



Update: in NOGTK mode, the display works fine. I believe this may be related to gtk font handling... I'll search more.

Lionel


OK, this is interesting clue...

Try these logs please:

void Font::InitStdFont()
{
	ONCELOCK {
		DrawLock __;
		List();
		AStdFont = Arial(12);
		String name;
		int    height = 0;
		GetStdFontSys(name, height);
LOG(name);
LOG(height);
		int q = FindFaceNameIndex(name);
LOG(q);
		if(q > 0) {
			AStdFont = Font(q, max(height, 1));
			SyncStdFont();
		}
LOG(AStdFont);
	}
}


You might also try to choose different GUI font (in gtk settings) and see what happens.

Mirek
Re: Font alignment issues [message #22572 is a reply to message #22567] Mon, 27 July 2009 17:53 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 171
Registered: May 2007
Location: Grenoble, France
Experienced Member
I replaced the LOG() by DUMP() for easier output:

name = xxxx
height = 0
q = 0
AStdFont = <sans-serif:12>

and the fact is that my std font in Gtk is 9 pt, not 12... it seems the alignment is wrong only when the font size is set to a value smaller than 12. With the same font (Sans) at 12 or greater, the alignment is correct.

Besides, it depends on the font used... some show an alignment problem, others don't. Is that a kerning issue? (I'm absolutely not versed in font management.)
Re: Font alignment issues [message #22576 is a reply to message #22572] Tue, 28 July 2009 02:38 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
OK, in that case, what is the result of LOGs if everything works (font > 12pt)?

Also, more logs (for case when it does not work):

void Font::SyncStdFont()
{
	DrawLock __;
LOG(AStdFont());
	StdFontSize = Size(AStdFont.GetAveWidth(), AStdFont().Bold().GetCy());
}

void Font::SetStdFont(Font font)
{
LOG("SetStdFont " << font);
	DrawLock __;
	static bool x;
	InitStdFont();
	AStdFont = font;
	SyncStdFont();
}

void Std(Font& font)
{
LOG("Std: " << GetStdFont());
	if(IsNull(font))
		font = StdFont();
	if(font.GetFace() == 0)
		font.Face(GetStdFont().GetFace());
	if(font.GetHeight() == 0)
		font.Height(GetStdFont().GetHeight());
}


This I believe should fix the issue partially:

void Font::InitStdFont()
{
	ONCELOCK {
		DrawLock __;
		List();
		AStdFont = Arial(12);
		String name;
		int    height = 0;
		GetStdFontSys(name, height);
		int q = FindFaceNameIndex(name);
		if(q > 0) {
			AStdFont = Font(q, max(height, 1));
		}
		SyncStdFont();
	}
}


I believe this will work, but is not the correct fix...

Mirek

[Updated on: Tue, 28 July 2009 02:43]

Report message to a moderator

Re: Font alignment issues [message #22598 is a reply to message #22576] Wed, 29 July 2009 12:41 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 171
Registered: May 2007
Location: Grenoble, France
Experienced Member
luzr wrote on Tue, 28 July 2009 02:38

OK, in that case, what is the result of LOGs if everything works (font > 12pt)?

Still the same:

xxxx
0
0
<sans-serif:12>

It looks like this never changes...

luzr wrote on Tue, 28 July 2009 02:38


Also, more logs (for case when it does not work):

void Font::SyncStdFont()
{
	DrawLock __;
LOG(AStdFont());
	StdFontSize = Size(AStdFont.GetAveWidth(), AStdFont().Bold().GetCy());
}

void Font::SetStdFont(Font font)
{
LOG("SetStdFont " << font);
	DrawLock __;
	static bool x;
	InitStdFont();
	AStdFont = font;
	SyncStdFont();
}

void Std(Font& font)
{
LOG("Std: " << GetStdFont());
	if(IsNull(font))
		font = StdFont();
	if(font.GetFace() == 0)
		font.Face(GetStdFont().GetFace());
	if(font.GetHeight() == 0)
		font.Height(GetStdFont().GetHeight());
}


This I believe should fix the issue partially:

void Font::InitStdFont()
{
	ONCELOCK {
		DrawLock __;
		List();
		AStdFont = Arial(12);
		String name;
		int    height = 0;
		GetStdFontSys(name, height);
		int q = FindFaceNameIndex(name);
		if(q > 0) {
			AStdFont = Font(q, max(height, 1));
		}
		SyncStdFont();
	}
}


I believe this will work, but is not the correct fix...

Mirek


The fix provokes an infinite loop in InitStdFont(), so that a segfault is thrown. Without the fix, but with the added LOG() :

- using 16pt font size:
name = xxxx
height = 0
q = 0
AStdFont = <sans-serif:12>
SetStdFont <sans-serif:12>
<sans-serif:12>
Std: <sans-serif:12>
Std: <sans-serif:12>
SetStdFont <sans-serif:16>
<sans-serif:16>
Std: <sans-serif:16>
Std: <sans-serif:16>
Std: <sans-serif:16>
Std: <sans-serif:16>
Std: <sans-serif:16>
[...]


- using 9pt font size:
name = xxxx
height = 0
q = 0
AStdFont = <sans-serif:12>
SetStdFont <sans-serif:12>
<sans-serif:12>
Std: <sans-serif:12>
Std: <sans-serif:12>
SetStdFont <sans-serif:11>
<sans-serif:11>
Std: <sans-serif:11>
Std: <sans-serif:11>
Std: <sans-serif:11>
Std: <sans-serif:11>
Std: <sans-serif:11>
[...]


We have 11pt instead of 9 here! I believe that's the problem.

[Updated on: Wed, 29 July 2009 12:47]

Report message to a moderator

Re: Font alignment issues [message #22609 is a reply to message #22598] Fri, 31 July 2009 20:03 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
chickenk wrote on Wed, 29 July 2009 06:41

luzr wrote on Tue, 28 July 2009 02:38

OK, in that case, what is the result of LOGs if everything works (font > 12pt)?

Still the same:

xxxx
0
0
<sans-serif:12>

It looks like this never changes...

luzr wrote on Tue, 28 July 2009 02:38


Also, more logs (for case when it does not work):

void Font::SyncStdFont()
{
	DrawLock __;
LOG(AStdFont());
	StdFontSize = Size(AStdFont.GetAveWidth(), AStdFont().Bold().GetCy());
}

void Font::SetStdFont(Font font)
{
LOG("SetStdFont " << font);
	DrawLock __;
	static bool x;
	InitStdFont();
	AStdFont = font;
	SyncStdFont();
}

void Std(Font& font)
{
LOG("Std: " << GetStdFont());
	if(IsNull(font))
		font = StdFont();
	if(font.GetFace() == 0)
		font.Face(GetStdFont().GetFace());
	if(font.GetHeight() == 0)
		font.Height(GetStdFont().GetHeight());
}


This I believe should fix the issue partially:

void Font::InitStdFont()
{
	ONCELOCK {
		DrawLock __;
		List();
		AStdFont = Arial(12);
		String name;
		int    height = 0;
		GetStdFontSys(name, height);
		int q = FindFaceNameIndex(name);
		if(q > 0) {
			AStdFont = Font(q, max(height, 1));
		}
		SyncStdFont();
	}
}


I believe this will work, but is not the correct fix...

Mirek


The fix provokes an infinite loop in InitStdFont(), so that a segfault is thrown. Without the fix, but with the added LOG() :

- using 16pt font size:
name = xxxx
height = 0
q = 0
AStdFont = <sans-serif:12>
SetStdFont <sans-serif:12>
<sans-serif:12>
Std: <sans-serif:12>
Std: <sans-serif:12>
SetStdFont <sans-serif:16>
<sans-serif:16>
Std: <sans-serif:16>
Std: <sans-serif:16>
Std: <sans-serif:16>
Std: <sans-serif:16>
Std: <sans-serif:16>
[...]


- using 9pt font size:
name = xxxx
height = 0
q = 0
AStdFont = <sans-serif:12>
SetStdFont <sans-serif:12>
<sans-serif:12>
Std: <sans-serif:12>
Std: <sans-serif:12>
SetStdFont <sans-serif:11>
<sans-serif:11>
Std: <sans-serif:11>
Std: <sans-serif:11>
Std: <sans-serif:11>
Std: <sans-serif:11>
Std: <sans-serif:11>
[...]


We have 11pt instead of 9 here! I believe that's the problem.


These are pixels, not points...

Mirek
Re: Font alignment issues [message #22613 is a reply to message #22609] Sat, 01 August 2009 10:15 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
I have now tried with Fedora 11 (in VirtualBox) and could not reproduce the problem.

There must be something different with your setup, I guess.

Mirek
Re: Font alignment issues [message #22614 is a reply to message #22613] Sat, 01 August 2009 10:17 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Perhaps the installation of enlightenment DR17 caused the trouble?

Mirek
Re: Font alignment issues [message #22619 is a reply to message #22614] Sat, 01 August 2009 11:27 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 171
Registered: May 2007
Location: Grenoble, France
Experienced Member
luzr wrote on Sat, 01 August 2009 10:17

Perhaps the installation of enlightenment DR17 caused the trouble?

Mirek


I don't think so because e17 does not have any relationship with gtk libraries. It does not even read properties from it, like Chameleon does, it has its own theming engine.

But the e17 engine does use freetype2 (AFAIK) like gtk does... Where do you take the font properties from ? GTK or freetype?

Re: Font alignment issues [message #22624 is a reply to message #22619] Sat, 01 August 2009 12:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
chickenk wrote on Sat, 01 August 2009 05:27

luzr wrote on Sat, 01 August 2009 10:17

Perhaps the installation of enlightenment DR17 caused the trouble?

Mirek


I don't think so because e17 does not have any relationship with gtk libraries. It does not even read properties from it, like Chameleon does, it has its own theming engine.

But the e17 engine does use freetype2 (AFAIK) like gtk does... Where do you take the font properties from ? GTK or freetype?




Well, this bug seems like mismatch between Xft and FontConfig/Freetype.

We take basic system font from GTK. Anyway, even if that would be wrong, it should not manifest as what I have seen in screenshots - just the font would be different.

What I see is that Xft uses different metrics to place characters than what we have read from Freetype. Which is strange, because after all, Xft is using Fc/Freetype as well.

One possible cause is that we somehow request different fonts from Xft and Freetype.

Mirek

[Updated on: Sat, 01 August 2009 12:56]

Report message to a moderator

Re: Font alignment issues [message #22631 is a reply to message #22624] Sun, 02 August 2009 09:01 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Possible way to check the theory (removes "paint text with single call to X11" optimization):

void Draw::DrawText(int x, int y, int angle, const wchar *text, Font font,
		            Color ink, int n, const int *dx)
{
	if(IsNull(ink)) return;
	if(n < 0)
		n = wstrlen(text);
	Std(font);
	double sina;
	double cosa;
	int    d = 0;
	if(angle)
		Draw::SinCos(angle, sina, cosa);
	for(int i = 0; i < n; i++) {
		wchar chr = text[i];
		GlyphInfo gi = GetGlyphInfo(font, chr);
		if(gi.IsNormal())
		      DrawTextOp(int(x + cosa * d), int(y - sina * d), angle, &chr, font, ink, 1, NULL);
		else
		if(gi.IsReplaced()) {
			Font fnt = font;
			fnt.Face(gi.lspc);
			fnt.Height(gi.rspc);
			if(angle)
				DrawTextOp(int(x + cosa * d), int(y - sina * (font.GetAscent() - fnt.GetAscent() + d)),
				             angle, &chr, fnt, ink, 1, NULL);
			else
				DrawTextOp(x + d, y + font.GetAscent() - fnt.GetAscent(), 0, &chr, fnt, ink, 1, NULL);
			GlyphMetrics(gi, font, chr);
		}
		else
		if(gi.IsComposed()) {
			ComposedGlyph cg;
			Compose(font, chr, cg);
			if(angle) {
				DrawTextOp(int(x + cosa * d), int(y - sina * d), angle, &cg.basic_char, font, ink, 1, NULL);
				DrawTextOp(int(x + cosa * (d + cg.mark_pos.x)), int(y - sina * (cg.mark_pos.y + d)), angle, &cg.mark_char, cg.mark_font, ink, 1, NULL);
			}
			else {
				DrawTextOp(x + d, y, 0, &cg.basic_char, font, ink, 1, NULL);
				DrawTextOp(x + cg.mark_pos.x + d, y + cg.mark_pos.y, 0, &cg.mark_char, cg.mark_font, ink, 1, NULL);
			}
			GlyphMetrics(gi, font, chr);
		}
		d += dx ? *dx++ : gi.width;
	}
}


Please check and report results.
Re: Font alignment issues [message #22632 is a reply to message #22631] Sun, 02 August 2009 10:04 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 171
Registered: May 2007
Location: Grenoble, France
Experienced Member
I can only check on my fedora on Monday. Please be patient...

Thanks for your help so far !

Lionel
Re: Font alignment issues [message #22641 is a reply to message #22632] Mon, 03 August 2009 10:34 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 171
Registered: May 2007
Location: Grenoble, France
Experienced Member
Hi Mirek,

here is a screenshot with the new DrawText method (ouch...):

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

This is at 9pt size, but at 12pt or greater it is the same. The characters seem to get a 0px width.

regards,
Lionel
Re: Font alignment issues [message #22643 is a reply to message #22641] Mon, 03 August 2009 10:46 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
OK, lets search for some more clues:

GlyphInfo  GetGlyphInfoSys(Font font, int chr)
{
	LTIMING("GetGlyphInfoSys");
LOG("GetGlyphInfoSys " << font << ": " << chr << " " << (char)chr);
	GlyphInfo gi;
	FT_Face face = FTFace(font, NULL);
	gi.lspc = gi.rspc = 0;
	gi.width = 0x8000;
	if(face) {
LOG("Face found");
		LTIMING("GetGlyphInfoSys 2");
		int glyph_index = FT_Get_Char_Index(face, chr);
		if(glyph_index &&
			(FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP) == 0 ||
			 FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT) == 0)) {
				FT_Glyph_Metrics& m = face->glyph->metrics;
				int left  = FLOOR(m.horiBearingX);
				int width = TRUNC(CEIL(m.horiBearingX + m.width) - left);				
				gi.width = TRUNC(ROUND(face->glyph->advance.x));
DUMP(face->glyph->advance.x);
DUMP(gi.width);
				gi.lspc = TRUNC(left);
				gi.rspc = gi.width - width - gi.lspc;
		}
	}
	return gi;
}


Thanks for help.

Mirek
Re: Font alignment issues [message #22645 is a reply to message #22643] Mon, 03 August 2009 12:17 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 171
Registered: May 2007
Location: Grenoble, France
Experienced Member
here it is, with all modifs from above (I only removed the LOG() from the Std(Font& font) function because it gave a much bigger log).

Lionel
Re: Font alignment issues [message #22646 is a reply to message #22645] Mon, 03 August 2009 12:29 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Ops, sorry, there seems to have been bug in DrawText test.

Remove those logs for now and try:

void Draw::DrawText(int x, int y, int angle, const wchar *text, Font font,
		            Color ink, int n, const int *dx)
{
	if(IsNull(ink)) return;
	if(n < 0)
		n = wstrlen(text);
	Std(font);
	double sina;
	double cosa;
	int    d = 0;
//	if(angle)
		Draw::SinCos(angle, sina, cosa);
	for(int i = 0; i < n; i++) {
		wchar chr = text[i];
		GlyphInfo gi = GetGlyphInfo(font, chr);
		if(gi.IsNormal())
	//		if(angle)
				DrawTextOp(int(x + cosa * d), int(y - sina * d), angle, &chr, font, ink, 1, NULL);
	/*		else {
				int c = 1;
				int dd = 0;
				while(c < n) {
					GlyphInfo gi2 = GetGlyphInfo(font, text[i + c]);
					if(!gi2.IsNormal())
						break;
					dd += dx ? dx[c] : gi.width;
					c++;
					gi = gi2;
				}
				DrawTextOp(x + d, y, 0, text + i, font, ink, c, dx);
				d += dd;
				i += c - 1;
				if(dx)
					dx += c - 1;
			}*/_DBG_
		else
		if(gi.IsReplaced()) {
			Font fnt = font;
			fnt.Face(gi.lspc);
			fnt.Height(gi.rspc);
			if(angle)
				DrawTextOp(int(x + cosa * d), int(y - sina * (font.GetAscent() - fnt.GetAscent() + d)),
				             angle, &chr, fnt, ink, 1, NULL);
			else
				DrawTextOp(x + d, y + font.GetAscent() - fnt.GetAscent(), 0, &chr, fnt, ink, 1, NULL);
			GlyphMetrics(gi, font, chr);
		}
		else
		if(gi.IsComposed()) {
			ComposedGlyph cg;
			Compose(font, chr, cg);
			if(angle) {
				DrawTextOp(int(x + cosa * d), int(y - sina * d), angle, &cg.basic_char, font, ink, 1, NULL);
				DrawTextOp(int(x + cosa * (d + cg.mark_pos.x)), int(y - sina * (cg.mark_pos.y + d)), angle, &cg.mark_char, cg.mark_font, ink, 1, NULL);
			}
			else {
				DrawTextOp(x + d, y, 0, &cg.basic_char, font, ink, 1, NULL);
				DrawTextOp(x + cg.mark_pos.x + d, y + cg.mark_pos.y, 0, &cg.mark_char, cg.mark_font, ink, 1, NULL);
			}
			GlyphMetrics(gi, font, chr);
		}
		d += dx ? *dx++ : gi.width;
	}
}




Thanks.

Mirek
Re: Font alignment issues [message #22647 is a reply to message #22646] Mon, 03 August 2009 12:42 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 171
Registered: May 2007
Location: Grenoble, France
Experienced Member
Hi Mirek,

your try was right, this time everything works perfectly. I tried very small fonts (7pt) and they always are correctly placed.

It also still works when using large fonts.

I hope I could help you locate the problem. If you need more help don't hesitate to ask.

Thanks,
Lionel
Re: Font alignment issues [message #22650 is a reply to message #22647] Mon, 03 August 2009 13:36 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
chickenk wrote on Mon, 03 August 2009 06:42

Hi Mirek,

your try was right, this time everything works perfectly. I tried very small fonts (7pt) and they always are correctly placed.

It also still works when using large fonts.

I hope I could help you locate the problem. If you need more help don't hesitate to ask.

Thanks,
Lionel


Hey, that is not the end of issue Smile

What we did is that we completely removed optimization. Well, in reality, maybe that is exactly what was needed, but I would like to try better first....

OK, I will try benchmarking the issue first...

BTW, can you post me a screenshot? I would like to compare two screenshots with and without the fix...

Mirek

[Updated on: Mon, 03 August 2009 13:37]

Report message to a moderator

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: 14290
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: 171
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: 14290
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: 171
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: 14290
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: 14290
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: 171
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: 14290
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: 171
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: 14290
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: 1428
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: 14290
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: 14290
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: 14290
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: 171
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: 14290
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: 14290
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: Tue Apr 28 13:55:51 GMT+2 2026

Total time taken to generate the page: 0.01228 seconds