The following things are possible:
- primitives (lines, curves, texts, raster images, etc.)
- attributes
- classes
- gradients
- patterns
- masking
- mouse actions
- JavaScript
- metadata
Happy new year, everyone!
Seymour.
Thank you, srod. This is my first contribution to T&T. The approval of srod is a good sign!srod wrote:Very very interesting Seymour; thanks for this great contribution.
Well, this was my intention, to make SVG more available to PB programmers. To make it simple instead of daunting.Must admit that I have never used SVG, but your posting makes me want to dive in and get to grips with it all. Some nice possibilities present themselves.
I'm sure there are standalone viewers, but my first thought was Chrome or Opera. I know for a fact they work very well.Foz wrote:does anyone have a suggestion for a good windows SVG viewer?
Code: Select all
s = CreateSVG(#PB_Any)
SVG_StartDrawing(s)
SVG_Box(0,0,100,100,#Green)
SVG_StopDrawing()
SaveSVG(s,"C:\test.svg")
Code: Select all
z = ArraySize(svgmem(),1)
Code: Select all
Structure PieChartSlice
name.s
value.f
color.i
EndStructure
Structure PieChart
slices.i
slice.PieChartSlice[25]
EndStructure
Procedure.i SVGPieChart(*p.PieChart,title.s,description.s)
s = CreateSVG(#PB_Any,title,description)
SVG_StartDrawing(s)
SVG_SetBackground(#SVG_FillMode_Color,#Black)
total.f
For a = 1 To *p\slices
total + *p\slice[a]\value
Next a
d.f = 800
r.f = d/2
cx.f = r
cy.f = r
fontname.s = "Courier New"
fontsize = 12
Dim text_angle.f(*p\slices)
startangle.f = -90
For a = 1 To *p\slices
clr = *p\slice[a]\color
deg_arc.f = 360/total**p\slice[a]\value
SVG_CircleSegment(cx,cy,r,Degrees2Radians(deg_arc),Degrees2Radians(startangle),clr)
SVG_SetElementStroke(#Black,1)
text_angle(a) = startangle+(deg_arc/2)
startangle + deg_arc
Next a
SVG_Circle(cx,cy,r,-1) ; outline
SVG_SetElementFill(#SVG_FillMode_None)
SVG_SetElementStroke(#White,2,50) ;` this strokeopacity doesn't work!
font = LoadFont(#PB_Any,fontname,fontsize)
img = CreateImage(#PB_Any,1,1) : StartDrawing(ImageOutput(img))
DrawingFont(FontID(font))
cc.PointF : cc\x=cx : cc\y=cy
For a = 1 To *p\slices
txt.s = *p\slice[a]\name+" ("+Str(100/total**p\slice[a]\value)+"%)"
tw.f = TextWidth(txt)
DegreeCoordsFromPoint(@cc,text_angle(a),r/3*2,@tcc.PointF)
SVG_Text(tcc\x-(tw/2),tcc\y,txt,#Black,"texel")
SVG_SetElementFont(fontname,fontsize)
Next a
StopDrawing() : FreeImage(img) : FreeFont(font)
SVG_StopDrawing()
ProcedureReturn s
EndProcedure
p.PieChart
p\slices = Random(5)+Random(5)+5
For a = 1 To p\slices
p\slice[a]\name = RandomLetters(5+Random(15))
p\slice[a]\value = Random(50)+5
p\slice[a]\color = RandomRGB(92,200)
Next a
s = SVGPieChart(@p,"Pies","A study")
If IsSVG(s)
outputfile.s = previewfol+"PureSVG - pie.svg" : SaveSVG(s,outputfile,0) : RunProgram(outputfile)
EndIf
End
I think this would actually be quite difficult. For a start you'd need code to handle bezier curves (cubic and quadratic) and elliptical arcs. And SVG filters would be very hard to emulate, though perhaps they could be ignored.Rings wrote:What about writing a viewer (no , not a web-browser) or some routines to write the SVG to a image/sprite ourselves here ? Cannot be to different (except the scripting stuff) with only the primitives and gradients.....