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 » Draw, Display, Images, Bitmaps, Icons » Strange issue with text in Painter
Re: Strange issue with text in Painter [message #51030 is a reply to message #51028] Thu, 17 January 2019 10:42 Go to previous messageGo to next message
Tom1
Messages: 798
Registered: March 2007
Contributor
mirek wrote on Thu, 17 January 2019 11:19
Well, I should have done that in the previous request, but I got idea how to make these .logs better and how to possibly try to catch the error:

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;
			LOGFONT lf;
			int ret = GetObject(e.hfont, sizeof(lf), &lf);
			LOG("GetWin32Font found at " << i << " " << fnt << " " << lf.lfFaceName << " " << lf.lfHeight);
			VERIFY(abs(lf.lfHeight) == abs(fnt.GetHeight()));
			return e.hfont;
		}
		be = e;
	}
	LTIMING("GetWin32Font2");
	if(be.hfont)
		DeleteObject(be.hfont);

	LOG("GetWin32Font not found " << fnt);

	be.font = fnt;
	be.angle = angle;
	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()
	);

	cache[0] = be;
	return be.hfont;
}


Well, instead of pointing out the error, this one fixed the error...

// Tom

EDIT: Added the log...
  • Attachment: ChartTest.7z
    (Size: 3.84KB, Downloaded 27 times)

[Updated on: Thu, 17 January 2019 10:44]

Report message to a moderator

Re: Strange issue with text in Painter [message #51031 is a reply to message #51030] Thu, 17 January 2019 10:51 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12573
Registered: November 2005
Ultimate Member
Let us try the same here: (restore rest to trunk...)

void RenderCharacterSys(FontGlyphConsumer& sw, double x, double y, int ch, Font fnt)
{
	HFONT hfont = GetWin32Font(fnt, 0);
	if(hfont) {
		HDC hdc = Win32_IC();
		HFONT ohfont = (HFONT) ::SelectObject(hdc, hfont);

		LOGFONT lf;
		int ret = GetObject(hfont, sizeof(lf), &lf);
		LOG("RenderCharacterSys " << fnt << " " << ch << " " << (char)ch << ' ' << lf.lfFaceName << " " << lf.lfHeight);
		VERIFY(abs(lf.lfHeight) == abs(fnt.GetHeight()));

		GLYPHMETRICS gm;
		MAT2 m_matrix;
		memset(&m_matrix, 0, sizeof(m_matrix));
		m_matrix.eM11.value = 1;
		m_matrix.eM22.value = 1;
		int gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE|GGO_UNHINTED, &gm, 0, NULL, &m_matrix);
		if(gsz < 0)
			return;
		StringBuffer gb(gsz);
		gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE|GGO_UNHINTED, &gm, gsz, ~gb, &m_matrix);
		if(gsz < 0)
			return;
		RenderCharPath(~gb, gsz, sw, x, y + fnt.GetAscent());
		::SelectObject(hdc, ohfont);
	}
}

Re: Strange issue with text in Painter [message #51032 is a reply to message #51031] Thu, 17 January 2019 10:54 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12573
Registered: November 2005
Ultimate Member
Another try, as it looks like sort of race condition... Let us know whether it needs to be GetObject, or if any delay there works...

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;
			Atomic x;
			for(int i = 0; i < 1000; i++)
				x++;
			return e.hfont;
		}
		be = e;
	}
	LTIMING("GetWin32Font2");
	if(be.hfont)
		DeleteObject(be.hfont);

	be.font = fnt;
	be.angle = angle;
	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()
	);

	cache[0] = be;
	return be.hfont;
}
Re: Strange issue with text in Painter [message #51033 is a reply to message #51031] Thu, 17 January 2019 11:07 Go to previous messageGo to next message
Tom1
Messages: 798
Registered: March 2007
Contributor
mirek wrote on Thu, 17 January 2019 11:51
Let us try the same here: (restore rest to trunk...)

void RenderCharacterSys(FontGlyphConsumer& sw, double x, double y, int ch, Font fnt)
{
	HFONT hfont = GetWin32Font(fnt, 0);
	if(hfont) {
		HDC hdc = Win32_IC();
		HFONT ohfont = (HFONT) ::SelectObject(hdc, hfont);

		LOGFONT lf;
		int ret = GetObject(hfont, sizeof(lf), &lf);
		LOG("RenderCharacterSys " << fnt << " " << ch << " " << (char)ch << ' ' << lf.lfFaceName << " " << lf.lfHeight);
		VERIFY(abs(lf.lfHeight) == abs(fnt.GetHeight()));

		GLYPHMETRICS gm;
		MAT2 m_matrix;
		memset(&m_matrix, 0, sizeof(m_matrix));
		m_matrix.eM11.value = 1;
		m_matrix.eM22.value = 1;
		int gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE|GGO_UNHINTED, &gm, 0, NULL, &m_matrix);
		if(gsz < 0)
			return;
		StringBuffer gb(gsz);
		gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE|GGO_UNHINTED, &gm, gsz, ~gb, &m_matrix);
		if(gsz < 0)
			return;
		RenderCharPath(~gb, gsz, sw, x, y + fnt.GetAscent());
		::SelectObject(hdc, ohfont);
	}
}



This did not work. (Rest is now as in trunk.)

Tom
Re: Strange issue with text in Painter [message #51034 is a reply to message #51032] Thu, 17 January 2019 11:10 Go to previous messageGo to next message
Tom1
Messages: 798
Registered: March 2007
Contributor
mirek wrote on Thu, 17 January 2019 11:54
Another try, as it looks like sort of race condition... Let us know whether it needs to be GetObject, or if any delay there works...

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;
			Atomic x;
			for(int i = 0; i < 1000; i++)
				x++;
			return e.hfont;
		}
		be = e;
	}
	LTIMING("GetWin32Font2");
	if(be.hfont)
		DeleteObject(be.hfont);

	be.font = fnt;
	be.angle = angle;
	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()
	);

	cache[0] = be;
	return be.hfont;
}


Error is still there...

Tom
Re: Strange issue with text in Painter [message #51035 is a reply to message #51033] Thu, 17 January 2019 11:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12573
Registered: November 2005
Ultimate Member
Tom1 wrote on Thu, 17 January 2019 11:07
mirek wrote on Thu, 17 January 2019 11:51
Let us try the same here: (restore rest to trunk...)

void RenderCharacterSys(FontGlyphConsumer& sw, double x, double y, int ch, Font fnt)
{
	HFONT hfont = GetWin32Font(fnt, 0);
	if(hfont) {
		HDC hdc = Win32_IC();
		HFONT ohfont = (HFONT) ::SelectObject(hdc, hfont);

		LOGFONT lf;
		int ret = GetObject(hfont, sizeof(lf), &lf);
		LOG("RenderCharacterSys " << fnt << " " << ch << " " << (char)ch << ' ' << lf.lfFaceName << " " << lf.lfHeight);
		VERIFY(abs(lf.lfHeight) == abs(fnt.GetHeight()));

		GLYPHMETRICS gm;
		MAT2 m_matrix;
		memset(&m_matrix, 0, sizeof(m_matrix));
		m_matrix.eM11.value = 1;
		m_matrix.eM22.value = 1;
		int gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE|GGO_UNHINTED, &gm, 0, NULL, &m_matrix);
		if(gsz < 0)
			return;
		StringBuffer gb(gsz);
		gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE|GGO_UNHINTED, &gm, gsz, ~gb, &m_matrix);
		if(gsz < 0)
			return;
		RenderCharPath(~gb, gsz, sw, x, y + fnt.GetAscent());
		::SelectObject(hdc, ohfont);
	}
}



This did not work. (Rest is now as in trunk.)

Tom


Did not work means missing/wrong letters? And VERIFY never triggered?
Re: Strange issue with text in Painter [message #51036 is a reply to message #51035] Thu, 17 January 2019 11:32 Go to previous messageGo to next message
Tom1
Messages: 798
Registered: March 2007
Contributor
mirek wrote on Thu, 17 January 2019 12:28
Tom1 wrote on Thu, 17 January 2019 11:07
mirek wrote on Thu, 17 January 2019 11:51
Let us try the same here: (restore rest to trunk...)

void RenderCharacterSys(FontGlyphConsumer& sw, double x, double y, int ch, Font fnt)
{
	HFONT hfont = GetWin32Font(fnt, 0);
	if(hfont) {
		HDC hdc = Win32_IC();
		HFONT ohfont = (HFONT) ::SelectObject(hdc, hfont);

		LOGFONT lf;
		int ret = GetObject(hfont, sizeof(lf), &lf);
		LOG("RenderCharacterSys " << fnt << " " << ch << " " << (char)ch << ' ' << lf.lfFaceName << " " << lf.lfHeight);
		VERIFY(abs(lf.lfHeight) == abs(fnt.GetHeight()));

		GLYPHMETRICS gm;
		MAT2 m_matrix;
		memset(&m_matrix, 0, sizeof(m_matrix));
		m_matrix.eM11.value = 1;
		m_matrix.eM22.value = 1;
		int gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE|GGO_UNHINTED, &gm, 0, NULL, &m_matrix);
		if(gsz < 0)
			return;
		StringBuffer gb(gsz);
		gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE|GGO_UNHINTED, &gm, gsz, ~gb, &m_matrix);
		if(gsz < 0)
			return;
		RenderCharPath(~gb, gsz, sw, x, y + fnt.GetAscent());
		::SelectObject(hdc, ohfont);
	}
}



This did not work. (Rest is now as in trunk.)

Tom


Did not work means missing/wrong letters? And VERIFY never triggered?


I mean missing/wrong letters were detected.

VERIFY did not trigger. (BTW, should it be DEBUG for VERIFY to work or is it OK to run RELEASE? Loading the map in DEBUG mode takes quite a while longer than in RELEASE mode, so I prefer using RELEASE mode when there are no LOGs needed.)

Tom
Re: Strange issue with text in Painter [message #51037 is a reply to message #51036] Thu, 17 January 2019 11:36 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12573
Registered: November 2005
Ultimate Member
VERIFY should work in release too. You can run all these in release, just replace LOG with RLOG...

That said, can use perhaps send me the log? And maybe tell me what letter was missing, which word it was part of, perhaps estimate what font it should have been...

Mirek
Re: Strange issue with text in Painter [message #51038 is a reply to message #51037] Thu, 17 January 2019 11:43 Go to previous messageGo to next message
Tom1
Messages: 798
Registered: March 2007
Contributor
mirek wrote on Thu, 17 January 2019 12:36
VERIFY should work in release too. You can run all these in release, just replace LOG with RLOG...

That said, can use perhaps send me the log? And maybe tell me what letter was missing, which word it was part of, perhaps estimate what font it should have been...

Mirek


I tried this in DEBUG mode and the everything seemed to be correct. I will now switch back to RELEASE and swap RLOG instead of LOG...

Tom
Re: Strange issue with text in Painter [message #51039 is a reply to message #51038] Thu, 17 January 2019 11:46 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12573
Registered: November 2005
Ultimate Member
Another try...

HDC Win32_IC()
{
	thread_local HDC hdc = CreateIC("DISPLAY", NULL, NULL, NULL);
	return hdc;
/*	static HDC hdc;
	ONCELOCK {
		hdc = CreateIC("DISPLAY", NULL, NULL, NULL);
	}
	return hdc;*/
}
Re: Strange issue with text in Painter [message #51040 is a reply to message #51038] Thu, 17 January 2019 11:54 Go to previous messageGo to next message
Tom1
Messages: 798
Registered: March 2007
Contributor
Tom1 wrote on Thu, 17 January 2019 12:43
mirek wrote on Thu, 17 January 2019 12:36
VERIFY should work in release too. You can run all these in release, just replace LOG with RLOG...

That said, can use perhaps send me the log? And maybe tell me what letter was missing, which word it was part of, perhaps estimate what font it should have been...

Mirek


I tried this in DEBUG mode and the everything seemed to be correct. I will now switch back to RELEASE and swap RLOG instead of LOG...

Tom


OK, now I was (and will keep, until you say otherwise) in RELEASE mode. Using RLOG. The problem appeared in letter 'a', in words like "Rajanummi" or "Nummela". Font is Arial, size likely 37..38, I guess.

BR, Tom
Re: Strange issue with text in Painter [message #51041 is a reply to message #51039] Thu, 17 January 2019 12:09 Go to previous messageGo to next message
Tom1
Messages: 798
Registered: March 2007
Contributor
mirek wrote on Thu, 17 January 2019 12:46
Another try...

HDC Win32_IC()
{
	thread_local HDC hdc = CreateIC("DISPLAY", NULL, NULL, NULL);
	return hdc;
/*	static HDC hdc;
	ONCELOCK {
		hdc = CreateIC("DISPLAY", NULL, NULL, NULL);
	}
	return hdc;*/
}


This fixes the issue. Not a single missing or false letter visible (to my eye).

May I get excited already, or is this just an intermediate step towards the goal? Smile

BR, Tom
Re: Strange issue with text in Painter [message #51042 is a reply to message #51040] Thu, 17 January 2019 12:17 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12573
Registered: November 2005
Ultimate Member
Tom1 wrote on Thu, 17 January 2019 11:54
Tom1 wrote on Thu, 17 January 2019 12:43
mirek wrote on Thu, 17 January 2019 12:36
VERIFY should work in release too. You can run all these in release, just replace LOG with RLOG...

That said, can use perhaps send me the log? And maybe tell me what letter was missing, which word it was part of, perhaps estimate what font it should have been...

Mirek


I tried this in DEBUG mode and the everything seemed to be correct. I will now switch back to RELEASE and swap RLOG instead of LOG...

Tom


OK, now I was (and will keep, until you say otherwise) in RELEASE mode. Using RLOG. The problem appeared in letter 'a', in words like "Rajanummi" or "Nummela". Font is Arial, size likely 37..38, I guess.

BR, Tom


I hoped for log... Smile
Re: Strange issue with text in Painter [message #51043 is a reply to message #51042] Thu, 17 January 2019 12:21 Go to previous messageGo to next message
Tom1
Messages: 798
Registered: March 2007
Contributor
mirek wrote on Thu, 17 January 2019 13:17
Tom1 wrote on Thu, 17 January 2019 11:54
Tom1 wrote on Thu, 17 January 2019 12:43
mirek wrote on Thu, 17 January 2019 12:36
VERIFY should work in release too. You can run all these in release, just replace LOG with RLOG...

That said, can use perhaps send me the log? And maybe tell me what letter was missing, which word it was part of, perhaps estimate what font it should have been...

Mirek


I tried this in DEBUG mode and the everything seemed to be correct. I will now switch back to RELEASE and swap RLOG instead of LOG...

Tom


OK, now I was (and will keep, until you say otherwise) in RELEASE mode. Using RLOG. The problem appeared in letter 'a', in words like "Rajanummi" or "Nummela". Font is Arial, size likely 37..38, I guess.

BR, Tom


I hoped for log... Smile


Sorry, like million characters read this morning... pressing both Browse... and Upload File was too much for me... Laughing

// Tom
  • Attachment: ChartTest.7z
    (Size: 1.74KB, Downloaded 29 times)
Re: Strange issue with text in Painter [message #51044 is a reply to message #51041] Thu, 17 January 2019 12:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12573
Registered: November 2005
Ultimate Member
Tom1 wrote on Thu, 17 January 2019 12:09
mirek wrote on Thu, 17 January 2019 12:46
Another try...

HDC Win32_IC()
{
	thread_local HDC hdc = CreateIC("DISPLAY", NULL, NULL, NULL);
	return hdc;
/*	static HDC hdc;
	ONCELOCK {
		hdc = CreateIC("DISPLAY", NULL, NULL, NULL);
	}
	return hdc;*/
}


This fixes the issue. Not a single missing or false letter visible (to my eye).

May I get excited already, or is this just an intermediate step towards the goal? Smile


intermediate step... But it all sort starts feeling like some inconsistency with GDI objects and threads, maybe in Win32.... (What I did here is to have IC per thread, which really should not be necessarry...

Anyway, one more test:

void RenderCharacterSys(FontGlyphConsumer& sw, double x, double y, int ch, Font fnt)
{
	static Atomic h;
	h++;
	HFONT hfont = GetWin32Font(fnt, 0);
	VERIFY(hfont);
	if(hfont) {
		HDC hdc = Win32_IC();
		HFONT ohfont = (HFONT) ::SelectObject(hdc, hfont);
		GLYPHMETRICS gm;
		MAT2 m_matrix;
		memset(&m_matrix, 0, sizeof(m_matrix));
		m_matrix.eM11.value = 1;
		m_matrix.eM22.value = 1;
		int gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE|GGO_UNHINTED, &gm, 0, NULL, &m_matrix);
		if(gsz < 0)
			return;
		StringBuffer gb(gsz);
		gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE|GGO_UNHINTED, &gm, gsz, ~gb, &m_matrix);
		if(gsz < 0)
			return;
		RenderCharPath(~gb, gsz, sw, x, y + fnt.GetAscent());
		::SelectObject(hdc, ohfont);
	}
	h--;
	ASSERT(h == 0);
}

Re: Strange issue with text in Painter [message #51045 is a reply to message #51044] Thu, 17 January 2019 12:34 Go to previous messageGo to next message
Tom1
Messages: 798
Registered: March 2007
Contributor
mirek wrote on Thu, 17 January 2019 13:28
Tom1 wrote on Thu, 17 January 2019 12:09
mirek wrote on Thu, 17 January 2019 12:46
Another try...

HDC Win32_IC()
{
	thread_local HDC hdc = CreateIC("DISPLAY", NULL, NULL, NULL);
	return hdc;
/*	static HDC hdc;
	ONCELOCK {
		hdc = CreateIC("DISPLAY", NULL, NULL, NULL);
	}
	return hdc;*/
}


This fixes the issue. Not a single missing or false letter visible (to my eye).

May I get excited already, or is this just an intermediate step towards the goal? Smile


intermediate step... But it all sort starts feeling like some inconsistency with GDI objects and threads, maybe in Win32.... (What I did here is to have IC per thread, which really should not be necessarry...

Anyway, one more test:

void RenderCharacterSys(FontGlyphConsumer& sw, double x, double y, int ch, Font fnt)
{
	static Atomic h;
	h++;
	HFONT hfont = GetWin32Font(fnt, 0);
	VERIFY(hfont);
	if(hfont) {
		HDC hdc = Win32_IC();
		HFONT ohfont = (HFONT) ::SelectObject(hdc, hfont);
		GLYPHMETRICS gm;
		MAT2 m_matrix;
		memset(&m_matrix, 0, sizeof(m_matrix));
		m_matrix.eM11.value = 1;
		m_matrix.eM22.value = 1;
		int gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE|GGO_UNHINTED, &gm, 0, NULL, &m_matrix);
		if(gsz < 0)
			return;
		StringBuffer gb(gsz);
		gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE|GGO_UNHINTED, &gm, gsz, ~gb, &m_matrix);
		if(gsz < 0)
			return;
		RenderCharPath(~gb, gsz, sw, x, y + fnt.GetAscent());
		::SelectObject(hdc, ohfont);
	}
	h--;
	ASSERT(h == 0);
}



No assertion in RELEASE mode. Bad letters were detected.

Tom

[Updated on: Thu, 17 January 2019 12:39]

Report message to a moderator

Re: Strange issue with text in Painter [message #51046 is a reply to message #51045] Thu, 17 January 2019 12:44 Go to previous messageGo to next message
Tom1
Messages: 798
Registered: March 2007
Contributor
ASSERT does not work in RELEASE mode. I'll need to test in DEBUG mode...

Tom
Re: Strange issue with text in Painter [message #51047 is a reply to message #51045] Thu, 17 January 2019 12:47 Go to previous messageGo to next message
Tom1
Messages: 798
Registered: March 2007
Contributor
Tom1 wrote on Thu, 17 January 2019 13:34
mirek wrote on Thu, 17 January 2019 13:28
Tom1 wrote on Thu, 17 January 2019 12:09
mirek wrote on Thu, 17 January 2019 12:46
Another try...

HDC Win32_IC()
{
	thread_local HDC hdc = CreateIC("DISPLAY", NULL, NULL, NULL);
	return hdc;
/*	static HDC hdc;
	ONCELOCK {
		hdc = CreateIC("DISPLAY", NULL, NULL, NULL);
	}
	return hdc;*/
}


This fixes the issue. Not a single missing or false letter visible (to my eye).

May I get excited already, or is this just an intermediate step towards the goal? Smile


intermediate step... But it all sort starts feeling like some inconsistency with GDI objects and threads, maybe in Win32.... (What I did here is to have IC per thread, which really should not be necessarry...

Anyway, one more test:

void RenderCharacterSys(FontGlyphConsumer& sw, double x, double y, int ch, Font fnt)
{
	static Atomic h;
	h++;
	HFONT hfont = GetWin32Font(fnt, 0);
	VERIFY(hfont);
	if(hfont) {
		HDC hdc = Win32_IC();
		HFONT ohfont = (HFONT) ::SelectObject(hdc, hfont);
		GLYPHMETRICS gm;
		MAT2 m_matrix;
		memset(&m_matrix, 0, sizeof(m_matrix));
		m_matrix.eM11.value = 1;
		m_matrix.eM22.value = 1;
		int gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE|GGO_UNHINTED, &gm, 0, NULL, &m_matrix);
		if(gsz < 0)
			return;
		StringBuffer gb(gsz);
		gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE|GGO_UNHINTED, &gm, gsz, ~gb, &m_matrix);
		if(gsz < 0)
			return;
		RenderCharPath(~gb, gsz, sw, x, y + fnt.GetAscent());
		::SelectObject(hdc, ohfont);
	}
	h--;
	ASSERT(h == 0);
}



No assertion in RELEASE mode. Bad letters were detected.

Tom


OK. In DEBUG mode this asserted in just after a few seconds.

Tom
Re: Strange issue with text in Painter [message #51048 is a reply to message #51047] Thu, 17 January 2019 12:52 Go to previous messageGo to next message
Tom1
Messages: 798
Registered: March 2007
Contributor
I tried the same in RELEASE -mode after changing the "ASSERT(h == 0);" to "VERIFY(h == 0);" and it triggered.

BR, Tom
Re: Strange issue with text in Painter [message #51049 is a reply to message #51045] Thu, 17 January 2019 12:56 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 12573
Registered: November 2005
Ultimate Member
What about

HDC Win32_IC()
{
	static HDC hdc;
	ONCELOCK {
		hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
	}
	return hdc;
}
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: Tue Jul 07 21:01:16 CEST 2020

Total time taken to generate the page: 0.01698 seconds