ori
December 9, 2020, 9:03pm
1
Does Cinder support the ability to get a string and create SVG file from it? or to create kind of SVG file like bitmap(or any other buffers)?
Like this:
SVG doc;
doc.loadByString("<svg><text x='0' y='15' fill='red'> SVG </text></svg>"));
//now, doc include SVG file
I would like also to know if a file containing a Text tag can be loaded by Cinder (by the loadAsset function or any other function that loads SVG files)
Something like this maybe?
std::string svgString = "<svg><text x='0' y='15' fill='red'> SVG </text></svg>";
BufferRef buffer = Buffer::create( (void *)svgString.c_str(), svgString.size() );
DataSourceBufferRef dataSource = DataSourceBuffer::create( buffer );
svg::DocRef doc = svg::Doc::create( dataSource );
About your second question, the svg reader has a Text
node, so it should work.
ori
December 13, 2020, 4:23pm
3
Thanks for the quick reply! But Iām looking for more than that. After loading the string I need to convert the doc sto buffer bitmap.
Something like this:
Bitmap bitmap = doc.renderToBitmap()
BufferRef buffer2= Buffer::create((void*) bitmap.data(),bitmap.size())
I need the buffer to be gray-scale and not RGBA but it is not very necessary. Is it possible to convert the doc
object to a buffer?
What is your use case?
Did you check the svg samples? This is how you can render a Surface from an svg.
void SimpleViewerApp::mouseDown( MouseEvent event ) { mUseCairo = ! mUseCairo; } void SimpleViewerApp::fileDrop( FileDropEvent event ) { load( event.getFile( 0 ) ); } gl::TextureRef renderCairoToTexture( svg::DocRef doc ) { cairo::SurfaceImage srf( 640, 480, true ); if( doc->getWidth() && doc->getHeight() ) srf = cairo::SurfaceImage( doc->getWidth(), doc->getHeight(), true ); else srf = cairo::SurfaceImage( 640, 480, true ); cairo::Context ctx( srf ); ctx.render( *doc ); ctx.flush();
1 Like