Hi, i’m new to SVG and have trouble parsing svg files to extract all the text with their absolute positions and bounding boxes. This is the code I wrote, From my understanding, GetScreenCTM() should give me a transformation matrix which when applied to the initial x and y pos from GetBBox() should give me the correct answer but I am not sure if I understood it clearly.
foreach ( SVGTextElement textElement in textElements )
{
var nodeText = textElement.TextContent;
if ( !string.IsNullOrEmpty(nodeText) )
{
var bbox = textElement.GetBBox();
var ctm = textElement.GetScreenCTM();
var x1 = bbox.X;
var y1 = bbox.Y;
var width = bbox.Width;
var height = bbox.Height;
var x2 = x1 + width;
var y2 = y1 + height;
var p1 = new Vector2D((int) ( ( x1 * ctm.A ) + ctm.E ), (int) ( ( y1 * ctm.D ) + ctm.F ));
var p2 = new Vector2D((int) ( ( x2 * ctm.A ) + ctm.E ), (int) ( ( y2 * ctm.D ) + ctm.F ));
var textBoundingBox = new Bounds2D(p1, p2); // rect with x,y, width and height
}
}