SVG Bitmapped Images or Musical Symbol Fonts

If anyone knows how to get at the NSVGimage* handle from within a module, please let me know. This handle is created in the SetPanel(LoadSvg()) call, but not exposed. I imagine there is some way to get at this, but I can’t find it. Once I have that handle, it should be a simple matter to walk the SVGimage and find the NVGshape object for my rasterized bitmap image loaded from my SVG file.

I basically have the NSVGimage shape list crawl working via the code:

std::shared_ptr<rack::Svg> svg=APP->window->loadSvg(asset::plugin(pluginInstance, "res/Meander.svg"));
setPanel(svg);

if (svg)
{
	DEBUG("shapes");
	auto hn = svg->handle;
	for( auto s = hn->shapes; s; s = s->next )
	{
		DEBUG("shape->id=%s", s->id);
	}
}

A lot of shapes are found, but none with my rasterized bitmap image id. Note sure why. Okay, there it it. Not sure how I missed it. Of course it is a path, shape->id=path1825 .

Okay, this is probably my last post on this topic. Does anyone know if the only way to render a NSVGShape is to traverse the NSVGpath* paths list and transform all of the cubic Bezier points coordinates? I had been expecting that there would be some “origin” for the shape and that the path points would render relative to this, but that does not appear to be the case. It shouldn’t be too much trouble to transform all of the points, but I want to make sure that is what I need to do in order to get this path object to draw at a different location on the panel than what was in the SVG file.

So I think you have most of it. But I think the bit you might be missing (although you also might not!) is that nanosvg is a library that goes from SVG file -> set of objects; and then nanovg is a library that goes from set of vector drawing commands -> screen. The code you found in rack which draws an svg is what goes from set of nanosvg object types to set of nanovg drawing commands. But you can go from svg -> nanosvg to other drawing surfaces as well. For instance, here’s a set of code I wrote in surge-proper to render an SVG asset using VSTGUI

So to your question: You probably don’t want to go through all your bezier paths and transform everything. You probably want to go through all your bezier paths and draw them in a draw context where the rendered has a transform applied.

In pseudocode, you are thinking you need to do

for( s : shapes )
    if( s matches condition )
       drawthese += transform( s )
for( d : draw these )
   do some drawing code( d )

but the more common pattern is

graphicslibrary_initiate_transform( ... )
for( s : shapes )
   if (s matches condition )
     draw(s)

For nanovg the transform code is all pretty simple. There’s nvgSave and nvgRestore as well as a scale, transform, rotate, etc…

Hope that helps.

Thanks @baconpaul . After sleeping on this, I think I have answered the question at the start of this thread. Since I now have the MusiSync font, there is no need to try to use my 30 year old music bitmap fonts. It was a fun adventure figuring out how to access an SVG file rasterized bitmap path object from within a Rack module, but it doesn’t seem very realistic for my current purposes inside of my Meander module. Maybe I will think up a problem for this solution:wink:

Hi @k-chaffin I I don’t want to seem annoying, the symbols in the image look terrible, I think the problem is that you weld the paths (the symbols and pentagram ) and the optimization make mess on it, I suggest keep it separated without path optimization

I agree, the rasterized bitmap font looks terrible. That is why I have abandoned this and will just use MusiSync font and nvg for staff lines etc. This was just an experiment since I did not have an opensource music font until several pointed me towards MusiSync.

Here is the corresponding panel graphics using MusiSync and nvg:

image

By the way, when I developed Meander for Windows from 1988-2003, I had to develop all of my musical fonts as no such thing really existed. So, I created bitmap images, by scanning in some cases. The results were pretty cool for the time, but not now.

Here is the same graphics captured just now from my Meander for Windows program, which still works fine 30+ years since I began developing it.

image

1 Like

yes, since the problem in bitmaps is the aliasing and in the svg is just that have a weird trace :wink:

Chuckle. Well glad you have it all sorted! Have a great weekend.