Position of graphics and paragraph in a Writer document
Posted: Thu Apr 14, 2016 7:34 am
As I iterate over the paragraphs of a document, I can access the paragraph's coordinates relative to the first page:
I can do the same with the graphics of a document, using the anchors to obtain the graphics' coordinates relative to the first page:
However, these coordinates can be quite off from where I see the graphics, even on a different page! I assume that the anchor of a graphics doesn't necessarily represent the position of the graphics itself.
Question: How do I get the real coordinates of a graphics? Looks like using the anchor here is imprecise?
Code: Select all
controller = document.getCurrentController()
cursor = controller.getViewCursor()
par_enum = document.Text.createEnumeration()
while par_enum.hasMoreElements():
par = par_enum.nextElement()
cursor.gotoRange(par, False)
pos = cursor.getPosition() # pos.X and pos.Y are the paragraph's coordinates
Code: Select all
shape_enum = document.DrawPage.createEnumeration()
while shape_enum.hasMoreElements():
shape = shape_enum.nextElement()
cursor.gotoRange(shape.Anchor, False)
pos = cursor.getPosition() # pos.X and pos.Y are the paragraph's coordinates
Question: How do I get the real coordinates of a graphics? Looks like using the anchor here is imprecise?