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 next 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)
Re: New example: Text to SVG path converter [message #53078 is a reply to message #53071] Sun, 23 February 2020 11:23 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Very nice,

I am always suprised how well things just fit in (when you know very well what is available inside

While taking a look at this example I also decided to open some complex files with SvgViewer and some glitches appearead with the file I tested :
https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/gallar do.svg

LEFT : UPP SvgViewer
RIGHT: Linux image viewer
Re: New example: Text to SVG path converter [message #53079 is a reply to message #53078] Sun, 23 February 2020 19:06 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Didier wrote on Sun, 23 February 2020 11:23
Very nice,

I am always suprised how well things just fit in (when you know very well what is available inside

While taking a look at this example I also decided to open some complex files with SvgViewer and some glitches appearead with the file I tested :
https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/gallar do.svg

LEFT : UPP SvgViewer
RIGHT: Linux image viewer


Well, it looks like the differences are caused by missing filters, which is the part of SVG I did not got to implement yet....
Re: New example: Text to SVG path converter [message #53080 is a reply to message #53079] Sun, 23 February 2020 19:52 Go to previous message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
OK, I understand
The file uses many times the following filters:

  • feGaussianBlur
  • linearGradient
  • radialGradient

So this explains it
Since nobody complained about it missing, all seems good Wink

[Updated on: Sun, 23 February 2020 19:53]

Report message to a moderator

Previous Topic: small theide improvement
Next Topic: ide: Insert clipboard/file as...
Goto Forum:
  


Current Time: Thu Mar 28 19:37:57 CET 2024

Total time taken to generate the page: 0.01034 seconds