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 #50884 is a reply to message #50881] Fri, 11 January 2019 18:50 Go to previous messageGo to next message
Tom1
Messages: 1252
Registered: March 2007
Senior Contributor
mirek wrote on Fri, 11 January 2019 16:43
Still no clues... Anyway, let us modify logging a bit:

void ApproximateChar(LinearPathConsumer& t, Pointf at, int ch, Font fnt, double tolerance)
{
	PAINTER_TIMING("ApproximateChar");
	Value v;
	INTERLOCKED {
		DLOG("==== ApproximateChar " << ch << " " << (char)ch << " " << fnt << ", tolerance: " << tolerance);
		PAINTER_TIMING("ApproximateChar::Fetch");
		static LRUCache<Value, GlyphKey> cache;
		cache.Shrink(500000);
		sMakeGlyph h;
		h.gk.fnt = fnt;
		h.gk.chr = ch;
		h.gk.tolerance = tolerance;
		v = cache.Get(h);
		DDUMP(ValueTo< Vector<float> >(v));
#if 1
		GlyphPainter chp;
		chp.move = chp.pos = Null;
		chp.tolerance = tolerance;
		PaintCharacter(chp, Pointf(0, 0), ch, fnt);
		DDUMP(chp.glyph);
		ASSERT(ValueTo< Vector<float> >(v) == chp.glyph);
#endif
	}
	const Vector<float>& g = ValueTo< Vector<float> >(v);
	int i = 0;
	while(i < g.GetCount()) {
		Pointf p;
		p.x = g[i++];
		if(p.x > 1e30) {
			p.x = g[i++];
			p.y = g[i++];
			t.Move(p + at);
		}
		else {
			PAINTER_TIMING("ApproximateChar::Line");
			p.y = g[i++];
			t.Line(p + at);
		}
	}
}


(If error is here, it should also assert....)


Strangely enough, this did not exhibit the problem at all. There are no buggy letters, as far as I could tell from looking around the map for 30 minutes. No asserts either, but that is to be expected as the problem did not surface here... I have been running with MSBT17x64 but I must next look at 32-bit compiler to see if it behaves differently. And maybe test on Linux too to see if the behavior changes.

I will continue with this on Monday...

As for the transformation matrix, I cannot see a chance for it to change between successive letters. That would require another thread to break the matrix, but this issue happens in ST too, so I think it is next to impossible.

Anyway, thanks for your efforts on this so far and have a nice weekend!

Tom

Re: Strange issue with text in Painter [message #50885 is a reply to message #50882] Fri, 11 January 2019 19:26 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14110
Registered: November 2005
Ultimate Member
IDK, I see no issues and as the last try I a have adapted our benchmarking snippet to test zooming in hope that it will reproduce the caching error:

#include <CtrlLib/CtrlLib.h>
#include <Painter/Painter.h>

using namespace Upp;

class PainterText : public TopWindow {
public:
	Painting p;
	FileSel fs;
	BufferPainter bpainter;
	double scale = 2;
	
	void Open(){
		if(fs.ExecuteOpen("Select a painting to view")){
			p.Clear();
			p.Serialize(FileIn(fs.Get()));
		}
	}

	virtual void MouseWheel(Point p, int zdelta, dword keyflags)
	{
		if(zdelta < 0)
			scale *= 0.8;
		else
			scale /= 0.8;
		Refresh();
	}


	virtual bool Key(dword key, int count){
		Refresh();
		switch(key){
			case K_CTRL_O:
				Open();
				return true;
		}
		return false;
	}
	
	typedef PainterText CLASSNAME;

	PainterText(){
		Sizeable();

		p.Serialize(FileIn("C:/xxx/PainteTest/T5.painting"));
	}
		
	virtual void Paint(Draw &draw){
		ImageBuffer ib(GetSize());
		{
			bpainter.Create(ib);
			bpainter.Co(false);
			bpainter.PreClipDashed();
			bpainter.Clear(White());
			bpainter.EvenOdd();
			
			bpainter.Scale(scale);
			bpainter.Paint(p);

			bpainter.Finish();
		}
		
		SetSurface(draw,Rect(ib.GetSize()),ib,ib.GetSize(),Point(0,0));
	}
};

GUI_APP_MAIN
{
	PainterText().Run();
}


but nothing.... Is not it possible that some new addition to your code is overwritting the cachec? Some dangling pointer perhaps?

Mirek
Re: Strange issue with text in Painter [message #50888 is a reply to message #50884] Sat, 12 January 2019 13:14 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14110
Registered: November 2005
Ultimate Member
Tom1 wrote on Fri, 11 January 2019 18:50
mirek wrote on Fri, 11 January 2019 16:43

#if 1
		GlyphPainter chp;
		chp.move = chp.pos = Null;
		chp.tolerance = tolerance;
		PaintCharacter(chp, Pointf(0, 0), ch, fnt);
		DDUMP(chp.glyph);
		ASSERT(ValueTo< Vector<float> >(v) == chp.glyph);
#endif


(If error is here, it should also assert....)


Strangely enough, this did not exhibit the problem at all. There are no buggy letters, as far as I could tell from looking around the map for 30 minutes. No asserts either, but that is to be expected as the problem did not surface here...


Well, that is something we can work with...

First of all, it would be nice to make sure this really makes differences. Change to #if 0 to resolve this.

If this is positive, I would set back to #if 1, retest, if problem is gone, then start removing lines of testing code from the last one until the problem reappears. That should give us some clue...

Mirek
Re: Strange issue with text in Painter [message #50890 is a reply to message #50888] Sat, 12 January 2019 14:57 Go to previous messageGo to next message
Tom1
Messages: 1252
Registered: March 2007
Senior Contributor
Hi,

Yes, I will follow your instructions... starting on Monday.

The absolute worst case scenario for me is if I have any pointer issues and corruption of memory thereby.

Late last night I started to think that I may have turned off PROTECT flag simultaneously when switching again to DEBUG mode for the test. This may have contributed to disappearance of the problem too. This is something I will have to check first thing on Monday. I mean the effect of working with and without PROTECT.

Anyway, I will keep digging. And I wish to thank you for your effort on this. (Hope I have not wasted your time with some stupid mistake of my own.)

Thanks and best regards,

Tom
Re: Strange issue with text in Painter [message #50902 is a reply to message #50890] Mon, 14 January 2019 09:58 Go to previous messageGo to next message
Tom1
Messages: 1252
Registered: March 2007
Senior Contributor
Hi Mirek,

OK, here's the situation. Using PROTECT or not does not have any effect on this issue. Neither does the compiler; MSBT17 and MSBT17x64 both work the same.

After starting to comment out the lines from the bottom of the sequence, PaintCharacter() proved to be the line required for correct operation. Commenting it out it brought the problem back:
#if 1
		GlyphPainter chp;
		chp.move = chp.pos = Null;
		chp.tolerance = tolerance;
		PaintCharacter(chp, Pointf(0, 0), ch, fnt); // <<-- Required for correct rendering
//		DDUMP(chp.glyph);
//		ASSERT(ValueTo< Vector<float> >(v) == chp.glyph);
#endif


Any suggestions, how I should proceed?

Best regards,

Tom
Re: Strange issue with text in Painter [message #50903 is a reply to message #50902] Mon, 14 January 2019 10:13 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14110
Registered: November 2005
Ultimate Member
Tom1 wrote on Mon, 14 January 2019 09:58
Hi Mirek,

OK, here's the situation. Using PROTECT or not does not have any effect on this issue. Neither does the compiler; MSBT17 and MSBT17x64 both work the same.

After starting to comment out the lines from the bottom of the sequence, PaintCharacter() proved to be the line required for correct operation. Commenting it out it brought the problem back:
#if 1
		GlyphPainter chp;
		chp.move = chp.pos = Null;
		chp.tolerance = tolerance;
		PaintCharacter(chp, Pointf(0, 0), ch, fnt); // <<-- Required for correct rendering
//		DDUMP(chp.glyph);
//		ASSERT(ValueTo< Vector<float> >(v) == chp.glyph);
#endif


Any suggestions, how I should proceed?

Best regards,

Tom


Try this:

#ifdef 1
		DLOG("==== ApproximateChar " << ch << " " << (char)ch << " " << fnt << ", tolerance: " << tolerance);
		DDUMP(ValueTo< Vector<float> >(v));
		GlyphPainter chp;
		chp.move = chp.pos = Null;
		chp.tolerance = tolerance;
		extern HFONT GetWin32Font(Font fnt, int angle);
		GetWin32Font(fnt, 0);
//		PaintCharacter(chp, Pointf(0, 0), ch, fnt);
//		DDUMP(chp.glyph);
//		ASSERT(ValueTo< Vector<float> >(v) == chp.glyph);
#endif


GetWin32Font is called by PaintCharacter and has some caching inside too, maybe that is the one that is causing the trouble. Of course, if calling it fixes the problem, try to comment and uncomment...

[Updated on: Mon, 14 January 2019 10:13]

Report message to a moderator

Re: Strange issue with text in Painter [message #50904 is a reply to message #50903] Mon, 14 January 2019 10:18 Go to previous messageGo to next message
Tom1
Messages: 1252
Registered: March 2007
Senior Contributor
mirek wrote on Mon, 14 January 2019 11:13
...
Try this:

#ifdef 1
		DLOG("==== ApproximateChar " << ch << " " << (char)ch << " " << fnt << ", tolerance: " << tolerance);
		DDUMP(ValueTo< Vector<float> >(v));
		GlyphPainter chp;
		chp.move = chp.pos = Null;
		chp.tolerance = tolerance;
		extern HFONT GetWin32Font(Font fnt, int angle);
		GetWin32Font(fnt, 0);
//		PaintCharacter(chp, Pointf(0, 0), ch, fnt);
//		DDUMP(chp.glyph);
//		ASSERT(ValueTo< Vector<float> >(v) == chp.glyph);
#endif


GetWin32Font is called by PaintCharacter and has some caching inside too, maybe that is the one that is causing the trouble. Of course, if calling it fixes the problem, try to comment and uncomment...


This does not fix the issue.

BR,

Tom
Re: Strange issue with text in Painter [message #50905 is a reply to message #50904] Mon, 14 January 2019 10:26 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14110
Registered: November 2005
Ultimate Member
Tom1 wrote on Mon, 14 January 2019 10:18
mirek wrote on Mon, 14 January 2019 11:13
...
Try this:

#ifdef 1
		DLOG("==== ApproximateChar " << ch << " " << (char)ch << " " << fnt << ", tolerance: " << tolerance);
		DDUMP(ValueTo< Vector<float> >(v));
		GlyphPainter chp;
		chp.move = chp.pos = Null;
		chp.tolerance = tolerance;
		extern HFONT GetWin32Font(Font fnt, int angle);
		GetWin32Font(fnt, 0);
//		PaintCharacter(chp, Pointf(0, 0), ch, fnt);
//		DDUMP(chp.glyph);
//		ASSERT(ValueTo< Vector<float> >(v) == chp.glyph);
#endif


GetWin32Font is called by PaintCharacter and has some caching inside too, maybe that is the one that is causing the trouble. Of course, if calling it fixes the problem, try to comment and uncomment...


This does not fix the issue.

BR,

Tom


What happens if you do

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);
	}
	else
	if(gi.IsComposed()) {
		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);
}


This should have no impact at all; we are testing branches that do character replacements if characters are missing. But I guess it is worth checking (as everything else fails).
Re: Strange issue with text in Painter [message #50906 is a reply to message #50905] Mon, 14 January 2019 10:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14110
Registered: November 2005
Ultimate Member
Another idea to test:

#ifdef 1
		DLOG("==== ApproximateChar " << ch << " " << (char)ch << " " << fnt << ", tolerance: " << tolerance);
		DDUMP(ValueTo< Vector<float> >(v));
		GlyphPainter chp;
		chp.move = chp.pos = Null;
		chp.tolerance = tolerance;
		GetGlyphInfo(fnt, ch);
//		GetWin32Font(fnt, 0);
//		PaintCharacter(chp, Pointf(0, 0), ch, fnt);
		DDUMP(chp.glyph);
		ASSERT(ValueTo< Vector<float> >(v) == chp.glyph);
#endif


Does this fix the issue? (GetGlyphInfo is another caching function called from PaintCharacter).

Mirek
Re: Strange issue with text in Painter [message #50907 is a reply to message #50905] Mon, 14 January 2019 10:39 Go to previous messageGo to next message
Tom1
Messages: 1252
Registered: March 2007
Senior Contributor
Yes, this does not have any effect what so ever. (I mean the Painter.cpp :: PaintCharacter() change.)

BR, Tom

[Updated on: Mon, 14 January 2019 10:40]

Report message to a moderator

Re: Strange issue with text in Painter [message #50908 is a reply to message #50906] Mon, 14 January 2019 10:42 Go to previous messageGo to next message
Tom1
Messages: 1252
Registered: March 2007
Senior Contributor
mirek wrote on Mon, 14 January 2019 11:28
Another idea to test:

#ifdef 1
		DLOG("==== ApproximateChar " << ch << " " << (char)ch << " " << fnt << ", tolerance: " << tolerance);
		DDUMP(ValueTo< Vector<float> >(v));
		GlyphPainter chp;
		chp.move = chp.pos = Null;
		chp.tolerance = tolerance;
		GetGlyphInfo(fnt, ch);
//		GetWin32Font(fnt, 0);
//		PaintCharacter(chp, Pointf(0, 0), ch, fnt);
		DDUMP(chp.glyph);
		ASSERT(ValueTo< Vector<float> >(v) == chp.glyph);
#endif


Does this fix the issue? (GetGlyphInfo is another caching function called from PaintCharacter).

Mirek


This does not fix the issue either. (Additionally I had to comment out the ASSERT, as the chp.glyph is not initialized to compare correctly with v.)

BR, Tom
Re: Strange issue with text in Painter [message #50909 is a reply to message #50908] Mon, 14 January 2019 10:47 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14110
Registered: November 2005
Ultimate Member
What about this:

#ifdef 1
		DLOG("==== ApproximateChar " << ch << " " << (char)ch << " " << fnt << ", tolerance: " << tolerance);
		DDUMP(ValueTo< Vector<float> >(v));
		GlyphPainter chp;
		chp.move = chp.pos = Null;
		chp.tolerance = tolerance;

		struct PaintCharPath : FontGlyphConsumer {
			Painter *sw;
			
			virtual void Move(Pointf p) {
				sw->Move(p);
			}
			virtual void Line(Pointf p) {
				sw->Line(p);
			}
			virtual void Quadratic(Pointf p1, Pointf p2) {
				sw->Quadratic(p1, p2);
			}
			virtual void Cubic(Pointf p1, Pointf p2, Pointf p3) {
				sw->Cubic(p1, p2, p3);
			}
			virtual void Close() {
				sw->Close();
			}
		} pw;
		pw.sw = &chp;
		fnt.Render(pw, 0, 0, ch);
//		PaintCharacter(chp, Pointf(0, 0), ch, fnt);
//		DDUMP(chp.glyph);
//		ASSERT(ValueTo< Vector<float> >(v) == chp.glyph);
#endif


(We are trying to identify which part of PaintCharacter makes the difference...)
Re: Strange issue with text in Painter [message #50910 is a reply to message #50909] Mon, 14 January 2019 11:01 Go to previous messageGo to next message
Tom1
Messages: 1252
Registered: March 2007
Senior Contributor
Tried. Now the error appears if "fnt.Render(pw, 0, 0, ch);" is commented out from the above.

BR, Tom
Re: Strange issue with text in Painter [message #50911 is a reply to message #50910] Mon, 14 January 2019 11:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14110
Registered: November 2005
Ultimate Member
Tom1 wrote on Mon, 14 January 2019 11:01
Tried. Now the error appears if "fnt.Render(pw, 0, 0, ch);" is commented out from the above.

BR, Tom


Getting closer, but still no clue....

#ifdef 1
		DLOG("==== ApproximateChar " << ch << " " << (char)ch << " " << fnt << ", tolerance: " << tolerance);
		DDUMP(ValueTo< Vector<float> >(v));
		GlyphPainter chp;
		chp.move = chp.pos = Null;
		chp.tolerance = tolerance;

		struct PaintCharPath : FontGlyphConsumer {
			Painter *sw;
			
			virtual void Move(Pointf p) {
				sw->Move(p);
			}
			virtual void Line(Pointf p) {
				sw->Line(p);
			}
			virtual void Quadratic(Pointf p1, Pointf p2) {
				sw->Quadratic(p1, p2);
			}
			virtual void Cubic(Pointf p1, Pointf p2, Pointf p3) {
				sw->Cubic(p1, p2, p3);
			}
			virtual void Close() {
				sw->Close();
			}
		} pw;
		pw.sw = &chp;
		void RenderCharacterSys(FontGlyphConsumer& sw, double x, double y, int ch, Font fnt);
		RenderCharacterSys(pw, 0, 0, ch, fnt);
//		fnt.Render(pw, 0, 0, ch);
//		PaintCharacter(chp, Pointf(0, 0), ch, fnt);
//		DDUMP(chp.glyph);
//		ASSERT(ValueTo< Vector<float> >(v) == chp.glyph);
#endif


Now if RenderCharacterSys here is our 'toggle', I suggest start commenting out its internals to see what really makes the difference...

Mirek
Re: Strange issue with text in Painter [message #50912 is a reply to message #50911] Mon, 14 January 2019 11:11 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14110
Registered: November 2005
Ultimate Member
Oh, sorry about the part about "commenting out" - that would not work (because we are using it for the desired rendering as well).

What we need to do is to copy it and THEN start removing...

double fx_to_dbl(const FIXED& p);
Pointf fx_to_dbl(const Pointf& pp, const POINTFX& p);

struct sMakeGlyph : LRUCache<Value, GlyphKey>::Maker {
	GlyphKey gk;

	GlyphKey Key() const     { return gk; }
	int      Make(Value& v) const {
		GlyphPainter gp;
		gp.move = gp.pos = Null;
		gp.tolerance = gk.tolerance;
		PaintCharacter(gp, Pointf(0, 0), gk.chr, gk.fnt);
		int sz = gp.glyph.GetCount() * 4;
		v = RawPickToValue(pick(gp.glyph));
		return sz;
	}
};

void RenderCharPath2(const char* gbuf, unsigned total_size, FontGlyphConsumer& sw, double xx, double yy)
{
	const char* cur_glyph = gbuf;
	const char* end_glyph = gbuf + total_size;
	Pointf pp(xx, yy);
	while(cur_glyph < end_glyph) {
		const TTPOLYGONHEADER* th = (TTPOLYGONHEADER*)cur_glyph;
		const char* end_poly = cur_glyph + th->cb;
		const char* cur_poly = cur_glyph + sizeof(TTPOLYGONHEADER);
		sw.Move(fx_to_dbl(pp, th->pfxStart));
		while(cur_poly < end_poly) {
			const TTPOLYCURVE* pc = (const TTPOLYCURVE*)cur_poly;
			if (pc->wType == TT_PRIM_LINE)
				for(int i = 0; i < pc->cpfx; i++)
					sw.Line(fx_to_dbl(pp, pc->apfx[i]));
			if (pc->wType == TT_PRIM_QSPLINE)
				for(int u = 0; u < pc->cpfx - 1; u++) {
					Pointf b = fx_to_dbl(pp, pc->apfx[u]);
					Pointf c = fx_to_dbl(pp, pc->apfx[u + 1]);
					if (u < pc->cpfx - 2)
						c = Mid(b, c);
					sw.Quadratic(b, c);
				}
			cur_poly += sizeof(WORD) * 2 + sizeof(POINTFX) * pc->cpfx;
		}
		sw.Close();
		cur_glyph += th->cb;
    }
}

HFONT GetWin32Font(Font fnt, int angle);
HDC   Win32_IC();

void RenderCharacterSys2(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);
		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, &gm, 0, NULL, &m_matrix);
		if(gsz < 0)
			return;
		StringBuffer gb(gsz);
		gsz = GetGlyphOutlineW(hdc, ch, GGO_NATIVE, &gm, gsz, ~gb, &m_matrix);
		if(gsz < 0)
			return;
		RenderCharPath2(~gb, gsz, sw, x, y + fnt.GetAscent());
		::SelectObject(hdc, ohfont);
	}
}

void ApproximateChar(LinearPathConsumer& t, Pointf at, int ch, Font fnt, double tolerance)
{
	PAINTER_TIMING("ApproximateChar");
	Value v;
	INTERLOCKED {
		PAINTER_TIMING("ApproximateChar::Fetch");
		static LRUCache<Value, GlyphKey> cache;
		cache.Shrink(500000);
		sMakeGlyph h;
		h.gk.fnt = fnt;
		h.gk.chr = ch;
		h.gk.tolerance = tolerance;
		v = cache.Get(h);
#ifdef _DEBUG
		DLOG("==== ApproximateChar " << ch << " " << (char)ch << " " << fnt << ", tolerance: " << tolerance);
		DDUMP(ValueTo< Vector<float> >(v));
		GlyphPainter chp;
		chp.move = chp.pos = Null;
		chp.tolerance = tolerance;

		struct PaintCharPath : FontGlyphConsumer {
			Painter *sw;
			
			virtual void Move(Pointf p) {
				sw->Move(p);
			}
			virtual void Line(Pointf p) {
				sw->Line(p);
			}
			virtual void Quadratic(Pointf p1, Pointf p2) {
				sw->Quadratic(p1, p2);
			}
			virtual void Cubic(Pointf p1, Pointf p2, Pointf p3) {
				sw->Cubic(p1, p2, p3);
			}
			virtual void Close() {
				sw->Close();
			}
		} pw;
		pw.sw = &chp;
		RenderCharacterSys2(pw, 0, 0, ch, fnt);
//		fnt.Render(pw, 0, 0, ch);
//		PaintCharacter(chp, Pointf(0, 0), ch, fnt);
//		DDUMP(chp.glyph);
//		ASSERT(ValueTo< Vector<float> >(v) == chp.glyph);
#endif
	}
	const Vector<float>& g = ValueTo< Vector<float> >(v);
	int i = 0;
	while(i < g.GetCount()) {
		Pointf p;
		p.x = g[i++];
		if(p.x > 1e30) {
			p.x = g[i++];
			p.y = g[i++];
			t.Move(p + at);
		}
		else {
			PAINTER_TIMING("ApproximateChar::Line");
			p.y = g[i++];
			t.Line(p + at);
		}
	}
}


It this still 'toggles', start commenting from RenderCharPath2 call up...

[Updated on: Mon, 14 January 2019 11:12]

Report message to a moderator

Re: Strange issue with text in Painter [message #50913 is a reply to message #50912] Mon, 14 January 2019 11:30 Go to previous messageGo to next message
Tom1
Messages: 1252
Registered: March 2007
Senior Contributor
Commenting out this breaks rendering:
		// RenderCharPath2(~gb, gsz, sw, x, y + fnt.GetAscent());


I'll try to chop that one to slices next...

BR, Tom
Re: Strange issue with text in Painter [message #50915 is a reply to message #50913] Mon, 14 January 2019 11:32 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14110
Registered: November 2005
Ultimate Member
Also try

RenderCharPath2(~gb, gsz, sw, x, y/* + fnt.GetAscent()*/);
Re: Strange issue with text in Painter [message #50916 is a reply to message #50915] Mon, 14 January 2019 11:41 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14110
Registered: November 2005
Ultimate Member
Thinking about it, I have suspiction that maybe RawPickToValue might have to do something with all that...

What about this:

struct sMakeGlyph : LRUCache<String, GlyphKey>::Maker {
	GlyphKey gk;

	GlyphKey Key() const     { return gk; }
	int      Make(String& v) const {
		GlyphPainter gp;
		gp.move = gp.pos = Null;
		gp.tolerance = gk.tolerance;
		PaintCharacter(gp, Pointf(0, 0), gk.chr, gk.fnt);
		int sz = gp.glyph.GetCount() * 4;
		v.Set((char *)gp.glyph.begin(), sizeof(float) * gp.glyph.GetCount());
		return sz;
	}
};

void ApproximateChar(LinearPathConsumer& t, Pointf at, int ch, Font fnt, double tolerance)
{
	PAINTER_TIMING("ApproximateChar");
	String v;
	INTERLOCKED {
		PAINTER_TIMING("ApproximateChar::Fetch");
		static LRUCache<String, GlyphKey> cache;
		cache.Shrink(500000);
		sMakeGlyph h;
		h.gk.fnt = fnt;
		h.gk.chr = ch;
		h.gk.tolerance = tolerance;
		v = cache.Get(h);
	}
	int i = 0;
	int count = v.GetCount() / sizeof(float);
	const float *g = (const float *)~v;
	while(i < count) {
		Pointf p;
		p.x = g[i++];
		if(p.x > 1e30) {
			p.x = g[i++];
			p.y = g[i++];
			t.Move(p + at);
		}
		else {
			PAINTER_TIMING("ApproximateChar::Line");
			p.y = g[i++];
			t.Line(p + at);
		}
	}
}
Re: Strange issue with text in Painter [message #50917 is a reply to message #50915] Mon, 14 January 2019 11:49 Go to previous messageGo to next message
Tom1
Messages: 1252
Registered: March 2007
Senior Contributor
mirek wrote on Mon, 14 January 2019 12:32
Also try

RenderCharPath2(~gb, gsz, sw, x, y/* + fnt.GetAscent()*/);


This does not make any difference.

Tom
Re: Strange issue with text in Painter [message #50919 is a reply to message #50917] Mon, 14 January 2019 11:52 Go to previous messageGo to previous message
Tom1
Messages: 1252
Registered: March 2007
Senior Contributor
This shows the problem:
void RenderCharPath2(const char* gbuf, unsigned total_size, FontGlyphConsumer& sw, double xx, double yy)
{
	const char* cur_glyph = gbuf;
	const char* end_glyph = gbuf + total_size;
	Pointf pp(xx, yy);
	while(cur_glyph < end_glyph) {
		const TTPOLYGONHEADER* th = (TTPOLYGONHEADER*)cur_glyph;
		const char* end_poly = cur_glyph + th->cb;
		const char* cur_poly = cur_glyph + sizeof(TTPOLYGONHEADER);
		sw.Move(fx_to_dbl(pp, th->pfxStart));
/*		while(cur_poly < end_poly) {
			const TTPOLYCURVE* pc = (const TTPOLYCURVE*)cur_poly;
			if (pc->wType == TT_PRIM_LINE)
				for(int i = 0; i < pc->cpfx; i++)
					sw.Line(fx_to_dbl(pp, pc->apfx[i]));
			if (pc->wType == TT_PRIM_QSPLINE)
				for(int u = 0; u < pc->cpfx - 1; u++) {
					Pointf b = fx_to_dbl(pp, pc->apfx[u]);
					Pointf c = fx_to_dbl(pp, pc->apfx[u + 1]);
					if (u < pc->cpfx - 2)
						c = Mid(b, c);
					sw.Quadratic(b, c);
				}
			cur_poly += sizeof(WORD) * 2 + sizeof(POINTFX) * pc->cpfx;
		}
*/		sw.Close();
		cur_glyph += th->cb;
    }
}


This renders OK:

void RenderCharPath2(const char* gbuf, unsigned total_size, FontGlyphConsumer& sw, double xx, double yy)
{
	const char* cur_glyph = gbuf;
	const char* end_glyph = gbuf + total_size;
	Pointf pp(xx, yy);
	while(cur_glyph < end_glyph) {
		const TTPOLYGONHEADER* th = (TTPOLYGONHEADER*)cur_glyph;
		const char* end_poly = cur_glyph + th->cb;
		const char* cur_poly = cur_glyph + sizeof(TTPOLYGONHEADER);
		sw.Move(fx_to_dbl(pp, th->pfxStart));
		while(cur_poly < end_poly) {
			const TTPOLYCURVE* pc = (const TTPOLYCURVE*)cur_poly;
/*			if (pc->wType == TT_PRIM_LINE)
				for(int i = 0; i < pc->cpfx; i++)
					sw.Line(fx_to_dbl(pp, pc->apfx[i]));
			if (pc->wType == TT_PRIM_QSPLINE)
				for(int u = 0; u < pc->cpfx - 1; u++) {
					Pointf b = fx_to_dbl(pp, pc->apfx[u]);
					Pointf c = fx_to_dbl(pp, pc->apfx[u + 1]);
					if (u < pc->cpfx - 2)
						c = Mid(b, c);
					sw.Quadratic(b, c);
				}
*/			cur_poly += sizeof(WORD) * 2 + sizeof(POINTFX) * pc->cpfx;
		}
		sw.Close();
		cur_glyph += th->cb;
    }
}


I will now check the next suggestion with raw pick.

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: Thu Nov 07 05:21:48 CET 2024

Total time taken to generate the page: 0.01789 seconds