Open technosaurus opened 7 years ago
Very interesting! I need scalable font support for my project https://sourceforge.net/projects/cloverefiboot/ where I already implemented a copy of nanosvg.
Is this feature to be supported?
I found some other solutions around GitHub, i.e., SVG2PNG, svg_font_renderer. But such a feature is not well supported. A potential solution is to use the strategy of svg_font_renderer, but extra effort should be devoted to
svg
, text
tags, transform
properties text
nodes with path
.Is it?
My intent here was to convert text tags into a path which nanosvg can already handle. I was hoping to get feedback on how to handle various attributes such as font size (which I assume can just be scaled, and the y-offset recomputed). A prettier or more compact default font is more than welcome - this was just a proof of concept.
It could make a good fallback mode even if someone patches nanosvg to use stb_truetype (i.e. no font found or stbtt disabled by build time configuration)
is there an update on this? Support for text would be nice to use with imgui.
AFAIK, there is no font support planned for nanosvg. You can use inkscape to transform your text to a path.
thanks @oehhar . I'm afraid that would not work for real time svg rendering application. The only alternative is svgpp, but who knows how to use that library :disappointed: .
@zhongjingjogy are you suggesting that svg2png and svg_font_renderer support text properly ?
I found some other solutions around GitHub, i.e., SVG2PNG, svg_font_renderer.
AFAIK, there is no font support planned for nanosvg. You can use inkscape to transform your text to a path.
This method works OK, thanks.
I have made some partial progress on showing the text field. Especially extract the text and font information from the svg file, and draw the text labels by some native(such as wxWidgets DrawText()) function calls.
See here: asmwarrior/SvgPanel: a wxPanel which can show svg image and simple text labels
It would be nice to have a font parsing in this library. I hope the maintainer(s) can integrate this.
@asmwarrior
I have made some partial progress on showing the text field. Especially extract the text and font information from the svg file, and draw the text labels by some native(such as wxWidgets DrawText()) function calls.
See here: asmwarrior/SvgPanel: a wxPanel which can show svg image and simple text labels
Can this be used for rendering the toolbar button?
@asmwarrior
I have made some partial progress on showing the text field. Especially extract the text and font information from the svg file, and draw the text labels by some native(such as wxWidgets DrawText()) function calls. See here: asmwarrior/SvgPanel: a wxPanel which can show svg image and simple text labels
Can this be used for rendering the toolbar button?
I think the answer is yes. But please note the font
field in a svg
file is very complex to parse, my improvement of rending the font is very limited.
I put together a SVG path-based font to use with nanosvg in lieu of text tags. My paths only use the stroke (no fill) to minimize the path size, but an outlined font effect can be reproduced by duplicating the path and reducing the stroke-width and the 'x' and 'y' offsets can be simulated by prepending "Mx y". Would something like this be the preferred way to add text support, or are there plans to add different type(s) so that the downstream projects can render the text directly such as stb_truetype for nanosvgrast.h or freetype for X11+opengl, etc...?
The font looks like this (amazingly its actually better than my first iterations) and only takes ~20 bytes per character with the following svg:
I wrote a simple (public domain) svg generator that uses these "glyphs" to generate nanosvg friendly icons here although it also handles things like newlines and tabs, which aren't necessary/desired for the svg specification.
I could implement this a couple different ways, but I thought I'd query other nanosvg users and devs for feedback first