I'm currently using draw2d lib to render some image. I noticed the core algorithm and method are the same for building SVG, or PNG images.
I do need to render this images as SVG (for web use) and PNG (for PDF use)
The only difference is at the entry type and output.
for PNG rendering I've
as input:
var gc *draw2dimg.GraphicContext
var img *image.RGBA
img = image.NewRGBA(image.Rect(0, 0, xSize, ySize))
gc = draw2dimg.NewGraphicContext(img)
as output:
draw2dimg.SaveToPngFile(FileName, img)
and for SVG I've:
as input:
var gc *draw2dsvg.GraphicContext
var img *draw2dsvg.Svg
img = draw2dsvg.NewSvg()
gc = draw2dsvg.NewGraphicContext(img)
as output:
draw2dsvg.SaveToSvgFile(FileName, img)
between input and output I've the same implementation.
Is there any way in Go to use different input type and get the same implementation without have to duplicate some code?