This is just the very beginnings of an SVG writer (mostly a proof of concept). And so far, it'll only create very basic SVG images. I also plan at some point to merge the TSvgReader and TSvgWriter classes so it'll be simpler to read, edit and rewrite SVGs.
//create an SVG file ... with TSvgWriter.Create do try //image size <svg> Svg.width := 250; Svg.height := 300; //group <g> several shapes //and rotate them 15 degrees anticlockwise with Svg.AddChild(TSvgGroupWriter) as TSvgGroupWriter do begin MatrixTranslate(Matrix, 10,20); MatrixRotate(Matrix, PointD(100,130), -angle15); //<text> and <tspan> //owned by (ie inside) group with AddChild(TSvgTextWriter) as TSvgTextWriter do begin fontInfo.family := ttfSansSerif; fontInfo.size := 12; position := PointD(30,230); AddText('This is '); with AddChild(TSvgTSpanWriter) as TSvgTSpanWriter do begin FillColor := $FF990000; offset.sy := 5; fontInfo.size := 20; fontInfo.weight := 600; AddText('BIG'); end; AddText(' text.'); end; //<rect> inside group with AddChild(TSvgRectWriter) as TSvgRectWriter do begin FillColor := $10FF3300; StrokeColor := clMaroon32; strokeWidth := 3.0; RecWH := RectWH(10,10, 180, 240); Radii := SizeD(20,30); end; //<path> inside group with AddChild(TSvgPathWriter) as TSvgPathWriter do begin FillColor := $10007F7F; StrokeColor := clTeal32; strokeWidth := 3.0; MoveTo(110,80); CubicBezierTo(PointD(145,80), PointD(145,30), PointD(110,30)); LineHTo(70); LineVTo(10); LIneTo(110,10); CubicBezierTo(PointD(160,10), PointD(160,100), PointD(110,100)); CubicSplineTo(PointD(60,190), PointD(110,190)); LineTo(150,190); LineVTo(170); LineHTo(110); CubicBezierTo(PointD(75,170), PointD(75,120), PointD(110,120)); //ClosePath; Rotate(PointD(110,110), angle45); Skew(angle45, 0); Translate(-120, 25); end; end; //save the new SVG SaveToStream(memStream); //SaveToFile('test.svg'); finally free; end;
Copyright ©2019 Angus Johnson - Image32 ver. 3.3 - Documentation last updated on 21-September-2021