Position of graphics and paragraph in a Writer document

The Application Programming Interface and the OASIS Open Document Format

Position of graphics and paragraph in a Writer document

Postby _savage » 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:

Code: Select all   Expand viewCollapse view
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

I can do the same with the graphics of a document, using the anchors to obtain the graphics' coordinates relative to the first page:

Code: Select all   Expand viewCollapse view
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

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?
Mac 10.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 138
Joined: Sun Apr 21, 2013 12:55 am

Re: Position of graphics and paragraph in a Writer document

Postby musikai » Thu Apr 14, 2016 10:15 pm

You can get position infos of a graphic object with:
Code: Select all   Expand viewCollapse view
posx = g.HoriOrientPosition
posy = g.VertOrientPosition


But the values depend on the anchor type and the HoriOrientRelation. If eg. the image is anchored AS_CHARACTER then the values aren't used at all.
If the image is set to be 3cm from left, it can be relative to the paragraph text area or to the entire page or.... There are at least 5 different relations possible.

So also this approach may become complex.

See also:
https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=80905#p373220
https://forum.openoffice.org/en/forum/viewtopic.php?f=7&t=82121
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/libreofficesongbookarchitect.html
musikai
Volunteer
 
Posts: 182
Joined: Wed Nov 11, 2015 12:19 am


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 3 guests