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 » Community » U++ community news and announcements » New example: Text to SVG path converter
New example: Text to SVG path converter [message #53071] Wed, 19 February 2020 16:00 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I have needed something to do this and it ended as quite nice small utility and in examples folder...

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

BTW, the conversion routine is surprisingly simple in U++:

struct TextToSvg : FontGlyphConsumer {
	String t;
	
	void Put(Pointf p);
	
	virtual void Move(Pointf p);
	virtual void Line(Pointf p);
	virtual void Quadratic(Pointf p1, Pointf p2);
	virtual void Cubic(Pointf p1, Pointf p2, Pointf p3);
	virtual void Close();
};

void TextToSvg::Put(Pointf p)
{
	t << Format("%.2f %.2f ", p.x, p.y);
}

void TextToSvg::Move(Pointf p)
{
	t << 'M';
	Put(p);
}

void TextToSvg::Line(Pointf p)
{
	t << 'L';
	Put(p);
}

void TextToSvg::Quadratic(Pointf p1, Pointf p)
{
	t << 'Q';
	Put(p1);
	Put(p);
}

void TextToSvg::Cubic(Pointf p1, Pointf p2, Pointf p)
{
	t << 'C';
	Put(p1);
	Put(p2);
	Put(p);
}

void TextToSvg::Close()
{
	t << 'Z';
}

String TextToSvgPath(double x, double y, const char *text, Font fnt, bool singleline)
{
	WString ws = ToUnicode(text, CHARSET_DEFAULT);
	TextToSvg t;
	for(const wchar *s = ~ws; *s; s++) {
		fnt.Render(t, x, y, *s);
		x += fnt[*s];
		if(!singleline)
			t.t << "\n";
	}
	return t.t;
}

  • Attachment: TextToSvg.png
    (Size: 69.96KB, Downloaded 371 times)
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: small theide improvement
Next Topic: ide: Insert clipboard/file as...
Goto Forum:
  


Current Time: Thu Mar 28 16:25:34 CET 2024

Total time taken to generate the page: 0.00942 seconds