Вопрос

I am using open office API with Java UNO. I need to get size of selected text in the document content (for example embedded pictures have own size in mm but text inserted via XText.insertString(...) method doesn't have any size).
In other words: I want to get size (preferably in mm) of the box which surrounds part of text (it can be whole paragraph or selected text via some type of cursor).
Is there any possibility to achieve that?

Это было полезно?

Решение

After searching, I think there is no option to achieve this at the moment. For my purposes I write small method for getting height of the paragraph in 1/100 mm.

Here is how this method works:

  1. Get XTextViewCursor of the XTextDocumment controller for going left/right.
  2. Go to paragraph to measure.
  3. Loop through paragraph getting each char. For each char do: check its height (CharHeight property of the paragraph); get XLineCursor from XTextViewCursor and check if there is end of the line - if is then add (to the result) biggest height of the character in line.

This is temporary solution (still wait for something better) and has number of bugs (example line-spacing different than single; paragraph should only contain text) but maybe it will be helpful for someone.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top