Measuring the height of text in different fonts

The aligned text with the picture is uploaded to the word document. But there is one problem. When sending an upload request, you can change the font of the text in the document.

The problem is that the height of the symbol changes dynamically depending on the font, and the position of the image is strictly fixed.

Is there a way to somehow measure the height of the empty space highlighted by a narrow red rectangle above the font text (see in the picture)?

@ramazanovam910 You can use LayoutCollector and LayoutEnumerator classes to get bounds of document elements. For example you can use the following code to calculate bounding box of a shape:

Document doc = new Document(@"C:\Temp\in.docx");
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);

// get shape.
Shape s = (Shape)doc.GetChild(NodeType.Shape, 0, true);

// Calculate bounds of the shape.
enumerator.Current = collector.GetEntity(s);
Console.WriteLine(enumerator.Rectangle);

With text things are a little harder, since your cannot directly move LayoutEnumerator to a Run. However, you can place a bookmark and move to the bookmark start. Then move LayoutEnumerator to the parent line and get line bounds:

Document doc = new Document(@"C:\Temp\in.docx");
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);

// Calculate bounds of line with bookmark
enumerator.Current = collector.GetEntity(doc.Range.Bookmarks["some_bookmakr"].BookmarkStart);
// Move enumerator to the parent line.
while(enumerator.Type!= LayoutEntityType.Line)
    enumerator.MoveParent();

Console.WriteLine(enumerator.Rectangle);