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
Font alignment issues [message #22516] Tue, 21 July 2009 13:40 Go to next message
chickenk is currently offline  chickenk
Messages: 168
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: 11993
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: 168
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: 11993
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: 168
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: 11993
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: 168
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: 11993
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: 11993
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: 11993
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: 168
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: 11993
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: 11993
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: 168
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: 168
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: 11993
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: 168
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: 11993
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: 168
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 previous message
mirek is currently offline  mirek
Messages: 11993
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

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


Current Time: Fri Aug 23 06:30:32 CEST 2019

Total time taken to generate the page: 0.01344 seconds