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

Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Strange issue with text in Painter
Re: Strange issue with text in Painter [message #50966 is a reply to message #50852] Tue, 15 January 2019 10:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member

FontEntry fi_cache[63];

const CommonFontInfo& GetFontInfo(Font font)
{
	INTERLOCKED {
		font.RealizeStd();
		unsigned hash = FoldHash(font.GetHashValue()) % 63;
		FontEntry& e = fi_cache[hash];
		if(e.font != font.AsInt64()) {
			Mutex::Lock __(sFontLock);
			e.font = font.AsInt64();
			e.info = GetFontInfoSys(font);
		}
		return e.info;
	}
}



(Removal of thread__ for fi_cache)
Re: Strange issue with text in Painter [message #50967 is a reply to message #50966] Tue, 15 January 2019 10:19 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
Hi,

Removal of thread__ for fc_cache and fi_cache do not help. The issue is still there.

-

As for the testcode, I could not spot any false characters there, but the granularity due to significant zooming ruins part of the larger texts.

BR, Tom
Re: Strange issue with text in Painter [message #50968 is a reply to message #50852] Tue, 15 January 2019 10:21 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
That testing code I have posted works better with

	virtual void LeftDown(Point p, dword)
	{
		start = (Pointf)p / scale;
		SetCapture();
	}

	virtual void MouseMove(Point p, dword keyflags)
	{
		if(HasCapture()) {
			Pointf pos = (Pointf)p / scale;
			translate += (pos - start);
			start = pos;
			Refresh();
		}
	}


Smile
Re: Strange issue with text in Painter [message #50969 is a reply to message #50968] Tue, 15 January 2019 11:13 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
Yes Smile

And:

PainterText().MinimizeBox().MaximizeBox().Sizeable().Run();


Is nice to have too to fill the screen.

But I still can't reproduce the issue with this.

One thing that caught my attention, though, is that the large bold upright texts show up extremely coarse, which is kind of expected due to the original zoom level fitting it all in one UHD screen. But why on earth are those smaller non-bold italic / upright fonts perfectly rendered although they are even smaller in the original view?

BR, Tom
Re: Strange issue with text in Painter [message #50970 is a reply to message #50969] Tue, 15 January 2019 11:20 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Yes, I have noticed it too. I am not so sure original zoom level has anything to do with that though... (it should get new tolerance value)
Re: Strange issue with text in Painter [message #50971 is a reply to message #50970] Tue, 15 January 2019 11:23 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
As to this issue, is it possible that all other texts are using your custom "Sheer" italic?

It actually looks like setting tolerance to 0.3 is not a good idea...

EDIT: tolerance is ok

[Updated on: Tue, 15 January 2019 11:27]

Report message to a moderator

Re: Strange issue with text in Painter [message #50972 is a reply to message #50971] Tue, 15 January 2019 11:27 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Is it by any means possible that missing letter are from those 'ugly' texts?
Re: Strange issue with text in Painter [message #50973 is a reply to message #50971] Tue, 15 January 2019 11:43 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Tue, 15 January 2019 12:23
As to this issue, is it possible that all other texts are using your custom "Sheer" italic?

It actually looks like setting tolerance to 0.3 is not a good idea...

EDIT: tolerance is ok


My custom reverse italic (using sheer to lean back) is using standard upright font and the normal italic is using standard italic served by Painter (as is without custom sheer). The ugly characters appear when the font is bold.

The names of lakes and other water areas (light blue) are using this reverse italic. Smaller place names are in plain italic. Larger place names are in straight-up bold. Municipalities are in even larger straight-up capital non-bold letters.

Best regards,

Tom
Re: Strange issue with text in Painter [message #50974 is a reply to message #50972] Tue, 15 January 2019 11:45 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Interesting, I have tried to hunt down 'ugly text issue' like this:

void Painter::TextOp(const Pointf& p, const wchar *text, Font fnt, int n, const double *dx)
{
	DDUMP(WString(text, n));


And interestingly, it looks like those are not painted as Text... or at least not stored into painting file as Text. Is that somehow possible that you have some separate path for them?
Re: Strange issue with text in Painter [message #50975 is a reply to message #50972] Tue, 15 January 2019 11:45 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Tue, 15 January 2019 12:27
Is it by any means possible that missing letter are from those 'ugly' texts?


I do not know about the missing letters, but the wrong size / wrong italicizing letters tend to come at same size and italicizing as many of the other texts that already occur on the view.

BR, Tom
Re: Strange issue with text in Painter [message #50976 is a reply to message #50975] Tue, 15 January 2019 11:51 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
(gtg now, 2-3 hours)
Re: Strange issue with text in Painter [message #50977 is a reply to message #50976] Tue, 15 January 2019 11:54 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
I have 1 h 8'...

Anyway, I need to pull back that 'Bold' from some place names. E.g. 'Paloniemi', which is rendered ugly, is just slightly larger straight up text than the more common place names which are italic... not even bold!

Best regards,

Tom

Re: Strange issue with text in Painter [message #50978 is a reply to message #50977] Tue, 15 January 2019 12:27 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
Tom1 wrote on Tue, 15 January 2019 12:54
I have 1 h 8'...

Anyway, I need to pull back that 'Bold' from some place names. E.g. 'Paloniemi', which is rendered ugly, is just slightly larger straight up text than the more common place names which are italic... not even bold!

Best regards,

Tom



OK, now I know: There is no separate path for those ugly texts. But I suppose the font size causes some conditional conversion to polygons in Painting. I forced all fonts to be of height 12, and then applied suitable Scale to Painter. As a result all the fonts were (ugly) rendered with precision that was insufficient when zooming in. Then I did this using height 75 and again suitable scale to painter. This time all the texts rendered beautifully in Painting. So I guess the storage format and precision in Painting is dependent on font size.

BR, Tom

EDIT: I changed font height to 1 and tried again: This time all fonts rendered perfectly!! But, the inter-character spacing precision in words was terrible.

EDIT: I think I understand why I cannot send the problem in a painting to you: The Painting is generated ST and characters are partly rendered already, so the error will not show up. I must generate a file with only unrendered characters, which get rendered at your end only.

[Updated on: Tue, 15 January 2019 12:59]

Report message to a moderator

Re: Strange issue with text in Painter [message #50979 is a reply to message #50967] Tue, 15 January 2019 13:28 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
Tom1 wrote on Tue, 15 January 2019 11:19
Hi,

Removal of thread__ for fc_cache and fi_cache do not help. The issue is still there.

-

As for the testcode, I could not spot any false characters there, but the granularity due to significant zooming ruins part of the larger texts.

BR, Tom


Hi!

It looks like this change of removing thread__ for fc_cache and fi_cache did not get compiled for me as I was simultaneously working on the testcode. Now I recompiled all and tried this once more and BANG! The problem was gone from my own program. And I also got it back by adding the thread__ ahead of those two caches. I think this solved the issue!

I must fly now... Will be back for more testing tomorrow.

A million thanks and best regards,

Tom
Re: Strange issue with text in Painter [message #50980 is a reply to message #50978] Tue, 15 January 2019 14:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Tom1 wrote on Tue, 15 January 2019 12:27

So I guess the storage format and precision in Painting is dependent on font size.


Except it is not, AFAIK... Smile

Besides, in this situation you are just using PaintingPainter, which really just directly stores Painter commands (including TextOp and CharacterOp). And the problem is that those ugly texts get stored as curves. Maybe I am blind, but I do not see a code path that could lead to THAT.

Mirek
Re: Strange issue with text in Painter [message #50981 is a reply to message #50979] Tue, 15 January 2019 14:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Tom1 wrote on Tue, 15 January 2019 13:28
Tom1 wrote on Tue, 15 January 2019 11:19
Hi,

Removal of thread__ for fc_cache and fi_cache do not help. The issue is still there.

-

As for the testcode, I could not spot any false characters there, but the granularity due to significant zooming ruins part of the larger texts.

BR, Tom


Hi!

It looks like this change of removing thread__ for fc_cache and fi_cache did not get compiled for me as I was simultaneously working on the testcode. Now I recompiled all and tried this once more and BANG! The problem was gone from my own program. And I also got it back by adding the thread__ ahead of those two caches. I think this solved the issue!

I must fly now... Will be back for more testing tomorrow.

A million thanks and best regards,

Tom


Obviously the next step is to try whether it is caused by first, second or both...

Mirek
Re: Strange issue with text in Painter [message #50982 is a reply to message #50981] Tue, 15 January 2019 16:20 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Upon further investigation we can forget about ugly texts. Most likely these are just results of font hinting process in Win32.

(As to what got me so confused, those texts are so mangled that I misread the name and then failed to find it in the list...)

EDIT: Hinting confirmed. I have added |GGO_UNHINTED to the GetGlyphOutlineW call and problem disappeared... (now in trunk).

[Updated on: Tue, 15 January 2019 16:26]

Report message to a moderator

Re: Strange issue with text in Painter [message #50983 is a reply to message #50981] Tue, 15 January 2019 16:37 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
Ok, I will try both one at a time tomorrow.

BR, Tom
Re: Strange issue with text in Painter [message #50984 is a reply to message #50983] Wed, 16 January 2019 08:54 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
Good morning Mirek,

Removing "thread__" from "thread__ CharEntry fc_cache[512];" fixes it.

Removing "thread__" from "thread__ FontEntry fi_cache[63];" does not have any effect on the problem.

Best regards,

Tom

BTW: Why should the caches be thread_local anyway? Isn't it true that Painter will use the same fonts with a whole bunch of threads when painting in MT? Having them common for all threads would have the used fonts cached after first hit and available to all threads. (Well, I'm likely missing something important here, but you'll probably educate me on that shortly...) Smile

[Updated on: Wed, 16 January 2019 09:12]

Report message to a moderator

Re: Strange issue with text in Painter [message #50986 is a reply to message #50984] Wed, 16 January 2019 09:18 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Tom1 wrote on Wed, 16 January 2019 08:54
Good morning Mirek,

Removing "thread__" from "thread__ CharEntry fc_cache[512];" fixes it.

Removing "thread__" from "thread__ FontEntry fi_cache[63];" does not have any effect on the problem.

Best regards,

Tom

BTW: Why should the caches be thread_local anyway? Isn't it true that Painter will use the same fonts with a whole bunch of threads when painting in MT? Having them common for all threads would have the used fonts cached after first hit and available to all threads. (Well, I'm likely missing something important here, but you'll probably educate me on that shortly...) Smile


Only to avoid confusion, how the code for CharEntry exactly looks now for you? And again, the rest of the code is absolutely the same as trunk?

Mirek
Re: Strange issue with text in Painter [message #50987 is a reply to message #50984] Wed, 16 January 2019 09:21 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Tom1 wrote on Wed, 16 January 2019 08:54

BTW: Why should the caches be thread_local anyway? Isn't it true that Painter will use the same fonts with a whole bunch of threads when painting in MT? Having them common for all threads would have the used fonts cached after first hit and available to all threads. (Well, I'm likely missing something important here, but you'll probably educate me on that shortly...) Smile


These functions are not Painter specific. They are used for rendering text with Draw as well. thread_local is used to avoid locking the mutex for each glyphinfo query (e.g. Font fnt = Arial(20); int char_width = fnt['A']; - operator[] is using this cache)

Mirek
Re: Strange issue with text in Painter [message #50988 is a reply to message #50986] Wed, 16 January 2019 09:37 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Wed, 16 January 2019 10:18
Tom1 wrote on Wed, 16 January 2019 08:54
Good morning Mirek,

Removing "thread__" from "thread__ CharEntry fc_cache[512];" fixes it.

Removing "thread__" from "thread__ FontEntry fi_cache[63];" does not have any effect on the problem.

Best regards,

Tom

BTW: Why should the caches be thread_local anyway? Isn't it true that Painter will use the same fonts with a whole bunch of threads when painting in MT? Having them common for all threads would have the used fonts cached after first hit and available to all threads. (Well, I'm likely missing something important here, but you'll probably educate me on that shortly...) Smile


Only to avoid confusion, how the code for CharEntry exactly looks now for you? And again, the rest of the code is absolutely the same as trunk?

Mirek


I refreshed from trunk this morning and the only change is in Font.cpp:

CharEntry fc_cache[512];


Instead of original:
thread__ CharEntry fc_cache[512];


BR, Tom
Re: Strange issue with text in Painter [message #50989 is a reply to message #50988] Wed, 16 January 2019 09:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Tom1 wrote on Wed, 16 January 2019 09:37
mirek wrote on Wed, 16 January 2019 10:18
Tom1 wrote on Wed, 16 January 2019 08:54
Good morning Mirek,

Removing "thread__" from "thread__ CharEntry fc_cache[512];" fixes it.

Removing "thread__" from "thread__ FontEntry fi_cache[63];" does not have any effect on the problem.

Best regards,

Tom

BTW: Why should the caches be thread_local anyway? Isn't it true that Painter will use the same fonts with a whole bunch of threads when painting in MT? Having them common for all threads would have the used fonts cached after first hit and available to all threads. (Well, I'm likely missing something important here, but you'll probably educate me on that shortly...) Smile


Only to avoid confusion, how the code for CharEntry exactly looks now for you? And again, the rest of the code is absolutely the same as trunk?

Mirek


I refreshed from trunk this morning and the only change is in Font.cpp:

CharEntry fc_cache[512];


Instead of original:
thread__ CharEntry fc_cache[512];


BR, Tom


Well,there should be additional INTERLOCKED (to replace thread__)... Anyway, that is probably not relevant..

Any chance that you see a bug there in the code? I see nothing Sad
Re: Strange issue with text in Painter [message #50990 is a reply to message #50987] Wed, 16 January 2019 09:40 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Wed, 16 January 2019 10:21
Tom1 wrote on Wed, 16 January 2019 08:54

BTW: Why should the caches be thread_local anyway? Isn't it true that Painter will use the same fonts with a whole bunch of threads when painting in MT? Having them common for all threads would have the used fonts cached after first hit and available to all threads. (Well, I'm likely missing something important here, but you'll probably educate me on that shortly...) Smile


These functions are not Painter specific. They are used for rendering text with Draw as well. thread_local is used to avoid locking the mutex for each glyphinfo query (e.g. Font fnt = Arial(20); int char_width = fnt['A']; - operator[] is using this cache)

Mirek


OK, I see. I'm not surprised you had a good reason for it! Smile
Re: Strange issue with text in Painter [message #50991 is a reply to message #50989] Wed, 16 January 2019 10:45 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Wed, 16 January 2019 10:39
Tom1 wrote on Wed, 16 January 2019 09:37
mirek wrote on Wed, 16 January 2019 10:18
Tom1 wrote on Wed, 16 January 2019 08:54
Good morning Mirek,

Removing "thread__" from "thread__ CharEntry fc_cache[512];" fixes it.

Removing "thread__" from "thread__ FontEntry fi_cache[63];" does not have any effect on the problem.

Best regards,

Tom

BTW: Why should the caches be thread_local anyway? Isn't it true that Painter will use the same fonts with a whole bunch of threads when painting in MT? Having them common for all threads would have the used fonts cached after first hit and available to all threads. (Well, I'm likely missing something important here, but you'll probably educate me on that shortly...) Smile


Only to avoid confusion, how the code for CharEntry exactly looks now for you? And again, the rest of the code is absolutely the same as trunk?

Mirek


I refreshed from trunk this morning and the only change is in Font.cpp:

CharEntry fc_cache[512];


Instead of original:
thread__ CharEntry fc_cache[512];


BR, Tom


Well,there should be additional INTERLOCKED (to replace thread__)... Anyway, that is probably not relevant..

Any chance that you see a bug there in the code? I see nothing Sad


I have read the code back and forth, but I clearly do not understand what's the reason for this. I'll keep digging...

BR, Tom
Re: Strange issue with text in Painter [message #50992 is a reply to message #50991] Wed, 16 January 2019 10:52 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
Now I'm even more confused. I removed the access to fc_cache entirely:

thread__ CharEntry fc_cache[512];

GlyphInfo GetGlyphInfo(Font font, int chr)
{
	font.RealizeStd();
	unsigned hash = GlyphHash(font, chr);
/*	CharEntry& e = fc_cache[hash & 511];
	if(e.font != font.AsInt64() || e.chr != chr)
		e = GetGlyphEntry(font, chr, hash);
	return e.info;*/
	return GetGlyphEntry(font, chr, hash).info;
}


But the error is still there!

BR, Tom
Re: Strange issue with text in Painter [message #50993 is a reply to message #50991] Wed, 16 January 2019 10:53 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Can you try this (with thread__ in place)

void PaintCharacter(Painter& sw, const Pointf& p, int chr, Font font)
{
	GlyphInfo gi = GetGlyphInfo(font, chr);
	PaintCharPath pw;
	pw.sw = &sw;
	if(gi.IsNormal())
		font.Render(pw, p.x, p.y, chr);
	else
	if(gi.IsReplaced()) {
		Font fnt = font;
		fnt.Face(gi.lspc);
		fnt.Height(gi.rspc);
		fnt.Render(pw, p.x, p.y + font.GetAscent() - fnt.GetAscent(), chr);
		DLOG("Replaced " << font << " -> " << fnt << ", " << chr << " " << (char)chr);
	}
	else
	if(gi.IsComposed()) {
		DLOG("Composed " << font << ", " << chr << " " << (char)chr);
		ComposedGlyph cg;
		Compose(font, chr, cg);
		font.Render(pw, p.x, p.y, cg.basic_char);
		sw.Div();
		cg.mark_font.Render(pw, p.x + cg.mark_pos.x, p.y + cg.mark_pos.y, cg.mark_char);
	}
	sw.EvenOdd(true);
}


bring it to error and check whether there is anything in the log?

Mirek
Re: Strange issue with text in Painter [message #50994 is a reply to message #50992] Wed, 16 January 2019 11:11 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Maybe you can try to call GetGlyphInfoSys directly there, with Mutex::Lock __(sFontLock);


thread__ CharEntry fc_cache[512];

GlyphInfo GetGlyphInfo(Font font, int chr)
{
	font.RealizeStd();
/*	unsigned hash = GlyphHash(font, chr);
	CharEntry& e = fc_cache[hash & 511];
	if(e.font != font.AsInt64() || e.chr != chr)
		e = GetGlyphEntry(font, chr, hash);
	return e.info;*/
	return GetGlyphEntry(font, chr, hash).info;
*/
   Mutex::Lock __(sFontLock);
   return GetGlyphInfoSys(font, chr);
}


Another thing to test is whether

thread__ CharEntry fc_cache[512];

GlyphInfo GetGlyphInfo(Font font, int chr)
{
	font.RealizeStd();
	unsigned hash = GlyphHash(font, chr);
/*	CharEntry& e = fc_cache[hash & 511];
	if(e.font != font.AsInt64() || e.chr != chr)
		e = GetGlyphEntry(font, chr, hash);
	return e.info;*/
	return GetGlyphEntry(font, chr, hash).info;
}


still depends on thread__ (hopefully not Smile

[Updated on: Wed, 16 January 2019 11:18]

Report message to a moderator

Re: Strange issue with text in Painter [message #50995 is a reply to message #50993] Wed, 16 January 2019 11:31 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Wed, 16 January 2019 11:53
Can you try this (with thread__ in place)

void PaintCharacter(Painter& sw, const Pointf& p, int chr, Font font)
{
	GlyphInfo gi = GetGlyphInfo(font, chr);
	PaintCharPath pw;
	pw.sw = &sw;
	if(gi.IsNormal())
		font.Render(pw, p.x, p.y, chr);
	else
	if(gi.IsReplaced()) {
		Font fnt = font;
		fnt.Face(gi.lspc);
		fnt.Height(gi.rspc);
		fnt.Render(pw, p.x, p.y + font.GetAscent() - fnt.GetAscent(), chr);
		DLOG("Replaced " << font << " -> " << fnt << ", " << chr << " " << (char)chr);
	}
	else
	if(gi.IsComposed()) {
		DLOG("Composed " << font << ", " << chr << " " << (char)chr);
		ComposedGlyph cg;
		Compose(font, chr, cg);
		font.Render(pw, p.x, p.y, cg.basic_char);
		sw.Div();
		cg.mark_font.Render(pw, p.x + cg.mark_pos.x, p.y + cg.mark_pos.y, cg.mark_char);
	}
	sw.EvenOdd(true);
}


bring it to error and check whether there is anything in the log?

Mirek


Nothing is shown on log.

BR, Tom
Re: Strange issue with text in Painter [message #50996 is a reply to message #50994] Wed, 16 January 2019 11:35 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
thread__ CharEntry fc_cache[512];

GlyphInfo GetGlyphInfo(Font font, int chr)
{
	font.RealizeStd();
/*	unsigned hash = GlyphHash(font, chr);
	CharEntry& e = fc_cache[hash & 511];
	if(e.font != font.AsInt64() || e.chr != chr)
		e = GetGlyphEntry(font, chr, hash);
	return e.info;
	return GetGlyphEntry(font, chr, hash).info;
*/
   Mutex::Lock __(sFontLock);
   return GetGlyphInfoSys(font, chr);
}


Still fails.

BR, Tom
Re: Strange issue with text in Painter [message #50997 is a reply to message #50996] Wed, 16 January 2019 11:39 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
CharEntry fc_cache[512];

GlyphInfo GetGlyphInfo(Font font, int chr)
{
	font.RealizeStd();
	unsigned hash = GlyphHash(font, chr);
/*	CharEntry& e = fc_cache[hash & 511];
	if(e.font != font.AsInt64() || e.chr != chr)
		e = GetGlyphEntry(font, chr, hash);
	return e.info;*/
	return GetGlyphEntry(font, chr, hash).info;
}


This fails regardless using thread__ or not.

BR, Tom
Re: Strange issue with text in Painter [message #50998 is a reply to message #50997] Wed, 16 January 2019 11:46 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
Even this fails:
//CharEntry fc_cache[512];

GlyphInfo GetGlyphInfo(Font font, int chr)
{
	//Mutex::Lock __(sFontLock);
	GlyphInfo info;
	INTERLOCKED{
	font.RealizeStd();
	info=GetGlyphInfoSys(font, chr);
	}
	return info;
}


BR, Tom
Re: Strange issue with text in Painter [message #50999 is a reply to message #50998] Wed, 16 January 2019 12:00 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Tom1 wrote on Wed, 16 January 2019 11:46
Even this fails:
//CharEntry fc_cache[512];

GlyphInfo GetGlyphInfo(Font font, int chr)
{
	//Mutex::Lock __(sFontLock);
	GlyphInfo info;
	INTERLOCKED{
	font.RealizeStd();
	info=GetGlyphInfoSys(font, chr);
	}
	return info;
}


BR, Tom


Well, those returns some sanity...

I have found possible issue and commited to trunk, please plain trunk now.. The chance that this fixes the issue is like 5%, but it is worth trying....
Re: Strange issue with text in Painter [message #51000 is a reply to message #50999] Wed, 16 January 2019 12:07 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Wed, 16 January 2019 13:00
...

Well, those returns some sanity...

I have found possible issue and commited to trunk, please plain trunk now.. The chance that this fixes the issue is like 5%, but it is worth trying....


Unfortunately, the issue remains.

BR, Tom
Re: Strange issue with text in Painter [message #51001 is a reply to message #51000] Wed, 16 January 2019 12:16 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
What about this:

HFONT GetWin32Font(Font fnt, int angle)
{
	LTIMING("GetWin32Font");
	static HFontEntry cache[FONTCACHE];
	ONCELOCK {
		for(int i = 0; i < FONTCACHE; i++)
			cache[i].font.Height(-30000);
	}
	HFontEntry be;
	be = cache[0];
/*	for(int i = 0; i < FONTCACHE; i++) {
		HFontEntry e = cache[i];
		if(i)
			cache[i] = be;
		if(e.font == fnt && e.angle == angle) {
			if(i)
				cache[0] = e;
			return e.hfont;
		}
		be = e;
	}*/
	LTIMING("GetWin32Font2");
	if(be.hfont)
		DeleteObject(be.hfont);

	be.font = fnt;
	be.angle = angle;
#ifdef PLATFORM_WINCE
	LOGFONT lfnt;
	Zero(lfnt);
	lfnt.lfHeight = fnt.GetHeight() ? -abs(fnt.GetHeight()) : -12;
	lfnt.lfWeight = fnt.IsBold() ? FW_BOLD : FW_NORMAL;
	lfnt.lfItalic = fnt.IsItalic();
	lfnt.lfUnderline = fnt.IsUnderline();
	lfnt.lfStrikeOut = fnt.IsStrikeout();
	wcscpy(lfnt.lfFaceName, ToSystemCharset(fnt.GetFaceName()));
	be.hfont = CreateFontIndirect(&lfnt);
#else
	be.hfont = CreateFont(
		fnt.GetHeight() ? -abs(fnt.GetHeight()) : -12,
		fnt.GetWidth(), angle, angle, fnt.IsBold() ? FW_BOLD : FW_NORMAL,
		fnt.IsItalic(), fnt.IsUnderline(), fnt.IsStrikeout(),
		fnt.GetFace() == Font::SYMBOL ? SYMBOL_CHARSET : DEFAULT_CHARSET,
		fnt.IsTrueTypeOnly() ? OUT_TT_ONLY_PRECIS : OUT_DEFAULT_PRECIS,
		CLIP_DEFAULT_PRECIS,
		fnt.IsNonAntiAliased() ? NONANTIALIASED_QUALITY : DEFAULT_QUALITY,
		DEFAULT_PITCH|FF_DONTCARE,
		fnt.GetFaceName()
	);
#endif
	cache[0] = be;
	return be.hfont;
}


(It is actually possible that this will INCREASE the number of wrong letters, even that would be important to know)

[Updated on: Wed, 16 January 2019 12:17]

Report message to a moderator

Re: Strange issue with text in Painter [message #51002 is a reply to message #51001] Wed, 16 January 2019 12:47 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Wed, 16 January 2019 13:16
What about this:

HFONT GetWin32Font(Font fnt, int angle)
{
	LTIMING("GetWin32Font");
	static HFontEntry cache[FONTCACHE];
	ONCELOCK {
		for(int i = 0; i < FONTCACHE; i++)
			cache[i].font.Height(-30000);
	}
	HFontEntry be;
	be = cache[0];
/*	for(int i = 0; i < FONTCACHE; i++) {
		HFontEntry e = cache[i];
		if(i)
			cache[i] = be;
		if(e.font == fnt && e.angle == angle) {
			if(i)
				cache[0] = e;
			return e.hfont;
		}
		be = e;
	}*/
	LTIMING("GetWin32Font2");
	if(be.hfont)
		DeleteObject(be.hfont);

	be.font = fnt;
	be.angle = angle;
#ifdef PLATFORM_WINCE
	LOGFONT lfnt;
	Zero(lfnt);
	lfnt.lfHeight = fnt.GetHeight() ? -abs(fnt.GetHeight()) : -12;
	lfnt.lfWeight = fnt.IsBold() ? FW_BOLD : FW_NORMAL;
	lfnt.lfItalic = fnt.IsItalic();
	lfnt.lfUnderline = fnt.IsUnderline();
	lfnt.lfStrikeOut = fnt.IsStrikeout();
	wcscpy(lfnt.lfFaceName, ToSystemCharset(fnt.GetFaceName()));
	be.hfont = CreateFontIndirect(&lfnt);
#else
	be.hfont = CreateFont(
		fnt.GetHeight() ? -abs(fnt.GetHeight()) : -12,
		fnt.GetWidth(), angle, angle, fnt.IsBold() ? FW_BOLD : FW_NORMAL,
		fnt.IsItalic(), fnt.IsUnderline(), fnt.IsStrikeout(),
		fnt.GetFace() == Font::SYMBOL ? SYMBOL_CHARSET : DEFAULT_CHARSET,
		fnt.IsTrueTypeOnly() ? OUT_TT_ONLY_PRECIS : OUT_DEFAULT_PRECIS,
		CLIP_DEFAULT_PRECIS,
		fnt.IsNonAntiAliased() ? NONANTIALIASED_QUALITY : DEFAULT_QUALITY,
		DEFAULT_PITCH|FF_DONTCARE,
		fnt.GetFaceName()
	);
#endif
	cache[0] = be;
	return be.hfont;
}


(It is actually possible that this will INCREASE the number of wrong letters, even that would be important to know)


It seems this fixes the issue! Smile

BR, Tom
Re: Strange issue with text in Painter [message #51003 is a reply to message #51002] Wed, 16 January 2019 13:09 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
How about

HFONT GetWin32Font(Font fnt, int angle)
{
	LTIMING("GetWin32Font");
	static HFontEntry cache[FONTCACHE];
	ONCELOCK {
		for(int i = 0; i < FONTCACHE; i++)
			cache[i].font.Height(-30000);
	}
	HFontEntry be;
	be = cache[0];
INTERLOCKED
	for(int i = 0; i < FONTCACHE; i++) {
		HFontEntry e = cache[i];
		if(i)
			cache[i] = be;
		if(e.font == fnt && e.angle == angle) {
			if(i)
				cache[0] = e;
			return e.hfont;
		}
		be = e;
	}
	LTIMING("GetWin32Font2");
	if(be.hfont)
		DeleteObject(be.hfont);

	be.font = fnt;
	be.angle = angle;
#ifdef PLATFORM_WINCE
	LOGFONT lfnt;
	Zero(lfnt);
	lfnt.lfHeight = fnt.GetHeight() ? -abs(fnt.GetHeight()) : -12;
	lfnt.lfWeight = fnt.IsBold() ? FW_BOLD : FW_NORMAL;
	lfnt.lfItalic = fnt.IsItalic();
	lfnt.lfUnderline = fnt.IsUnderline();
	lfnt.lfStrikeOut = fnt.IsStrikeout();
	wcscpy(lfnt.lfFaceName, ToSystemCharset(fnt.GetFaceName()));
	be.hfont = CreateFontIndirect(&lfnt);
#else
	be.hfont = CreateFont(
		fnt.GetHeight() ? -abs(fnt.GetHeight()) : -12,
		fnt.GetWidth(), angle, angle, fnt.IsBold() ? FW_BOLD : FW_NORMAL,
		fnt.IsItalic(), fnt.IsUnderline(), fnt.IsStrikeout(),
		fnt.GetFace() == Font::SYMBOL ? SYMBOL_CHARSET : DEFAULT_CHARSET,
		fnt.IsTrueTypeOnly() ? OUT_TT_ONLY_PRECIS : OUT_DEFAULT_PRECIS,
		CLIP_DEFAULT_PRECIS,
		fnt.IsNonAntiAliased() ? NONANTIALIASED_QUALITY : DEFAULT_QUALITY,
		DEFAULT_PITCH|FF_DONTCARE,
		fnt.GetFaceName()
	);
#endif
	cache[0] = be;
	return be.hfont;
}
Re: Strange issue with text in Painter [message #51004 is a reply to message #51003] Wed, 16 January 2019 13:20 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Wed, 16 January 2019 14:09
How about

HFONT GetWin32Font(Font fnt, int angle)
{
	LTIMING("GetWin32Font");
	static HFontEntry cache[FONTCACHE];
	ONCELOCK {
		for(int i = 0; i < FONTCACHE; i++)
			cache[i].font.Height(-30000);
	}
	HFontEntry be;
	be = cache[0];
INTERLOCKED
	for(int i = 0; i < FONTCACHE; i++) {
		HFontEntry e = cache[i];
		if(i)
			cache[i] = be;
		if(e.font == fnt && e.angle == angle) {
			if(i)
				cache[0] = e;
			return e.hfont;
		}
		be = e;
	}
	LTIMING("GetWin32Font2");
	if(be.hfont)
		DeleteObject(be.hfont);

	be.font = fnt;
	be.angle = angle;
#ifdef PLATFORM_WINCE
	LOGFONT lfnt;
	Zero(lfnt);
	lfnt.lfHeight = fnt.GetHeight() ? -abs(fnt.GetHeight()) : -12;
	lfnt.lfWeight = fnt.IsBold() ? FW_BOLD : FW_NORMAL;
	lfnt.lfItalic = fnt.IsItalic();
	lfnt.lfUnderline = fnt.IsUnderline();
	lfnt.lfStrikeOut = fnt.IsStrikeout();
	wcscpy(lfnt.lfFaceName, ToSystemCharset(fnt.GetFaceName()));
	be.hfont = CreateFontIndirect(&lfnt);
#else
	be.hfont = CreateFont(
		fnt.GetHeight() ? -abs(fnt.GetHeight()) : -12,
		fnt.GetWidth(), angle, angle, fnt.IsBold() ? FW_BOLD : FW_NORMAL,
		fnt.IsItalic(), fnt.IsUnderline(), fnt.IsStrikeout(),
		fnt.GetFace() == Font::SYMBOL ? SYMBOL_CHARSET : DEFAULT_CHARSET,
		fnt.IsTrueTypeOnly() ? OUT_TT_ONLY_PRECIS : OUT_DEFAULT_PRECIS,
		CLIP_DEFAULT_PRECIS,
		fnt.IsNonAntiAliased() ? NONANTIALIASED_QUALITY : DEFAULT_QUALITY,
		DEFAULT_PITCH|FF_DONTCARE,
		fnt.GetFaceName()
	);
#endif
	cache[0] = be;
	return be.hfont;
}


Works perfectly. Smile

BR, Tom

EDIT: I'll be back online after about one hour...

[Updated on: Wed, 16 January 2019 13:25]

Report message to a moderator

Re: Strange issue with text in Painter [message #51005 is a reply to message #51004] Wed, 16 January 2019 13:26 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
We are close but not there yet... The problem is that all calls to GetWin32Font should already be serialized (locked) - the only one that was not quite properly locked I have fixed in the trunk today.

Just for sanity check, can you do Find in Files search over all project files for GetWin32Font ?

For me, it returns

C:\u\upp.src\uppsrc\Draw\FontWin32.cpp (20): HFONT GetWin32Font(Font fnt, int angle)
C:\u\upp.src\uppsrc\Draw\FontWin32.cpp (22): 	LTIMING("GetWin32Font");
C:\u\upp.src\uppsrc\Draw\FontWin32.cpp (41): 	LTIMING("GetWin32Font2");
C:\u\upp.src\uppsrc\Draw\FontWin32.cpp (106): 	HFONT hfont = GetWin32Font(font, 0);
C:\u\upp.src\uppsrc\Draw\FontWin32.cpp (262): 		HFONT hfont = GetWin32Font(font, 0);
C:\u\upp.src\uppsrc\Draw\FontWin32.cpp (344): 	HFONT hfont = GetWin32Font(font, 0);
C:\u\upp.src\uppsrc\Draw\FontWin32.cpp (401): 	HFONT hfont = GetWin32Font(fnt, 0);
C:\u\upp.src\uppsrc\CtrlCore\DrawTextWin32.cpp (9): HFONT  GetWin32Font(Font fnt, int angle);
C:\u\upp.src\uppsrc\CtrlCore\DrawTextWin32.cpp (21): 	Mutex::Lock ___(sFontLock); // need this because of GetWin32Font
C:\u\upp.src\uppsrc\CtrlCore\DrawTextWin32.cpp (22): 	HGDIOBJ orgfont = ::SelectObject(handle, GetWin32Font(font, angle));
 (): 10 occurrence(s) have been found.


Do you have any other occurences?

Mirek
Re: Strange issue with text in Painter [message #51006 is a reply to message #51005] Wed, 16 January 2019 14:27 Go to previous messageGo to previous message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
The "GetWin32Font" occurences are the same.

The bad news is that I just found one missing character error again with this last code. But this is just one, which means the frequency of errors dropped significantly because of INTERLOCKing the GetWin32Font -cache. Now I must go back and check again more thoroughly when the GetWin32Font -cache is entirely disabled.

BR, Tom
Previous Topic: MT + Subpixel appear incompatible in Painter
Next Topic: Painter: Excessive memory usage in PainterExamples moving window to edges of screen.
Goto Forum:
  


Current Time: Mon May 18 12:26:21 GMT+2 2026

Total time taken to generate the page: 0.01332 seconds