I'm trying to write script which control Writer document through UNO API (from Python).
I want to know whether content in fixed size TextFrame overflow that frame area.
When contents of frame overflows, I can see "red triangle" right of the are in UI.
But I can't see are there any way to detect this from UNO API. Can I detect this, and how to do?
I wrote Writer document with TextField, and put some text into that field, through python external script.
Like:
[ (UserVariableField) ]
( [ ] are fixed width/height TextFrame.)
When I put very long UserVariable value text, it overflows Frame and overflowed strings are cutted off.
If I can, I wanna detect this happens on this frame(or text, or existence of red triangle), and modify
content text property to fit this area, like setting smaller font size, chopping text by myself or so.
I'm new to UNO API programming, and it's very difficult for me to read IDL reference.
[Half-Solved] How to detect overflow of content in TextFrame
[Half-Solved] How to detect overflow of content in TextFrame
Last edited by i12o on Sat Mar 30, 2019 9:06 am, edited 1 time in total.
LibreOffice 6.1.3.2
Linux
Linux
Re: How to detect overflow of content in TextFrame?
I can't find a direct method of seeing if the textbox overflows, but my suggestion is
Have another textfield that is hidden (perhaps in a hidden document) where the autosize is set to true
then assign a macro to the input of characters event that
-puts the same text in the hidden autosize textfield
- compares sizes and contains your code to modify the autosize textfield until the sizes match
(I have no idea how practicable/whether can be done)
Have another textfield that is hidden (perhaps in a hidden document) where the autosize is set to true
then assign a macro to the input of characters event that
-puts the same text in the hidden autosize textfield
- compares sizes and contains your code to modify the autosize textfield until the sizes match
(I have no idea how practicable/whether can be done)
Last edited by JeJe on Fri Mar 29, 2019 3:57 pm, edited 2 times in total.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: How to detect overflow of content in TextFrame?
[Tutorial] Introduction into object inspection with MRI allows you to ask every object about its capabilities.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: How to detect overflow of content in TextFrame?
The text fields in a Writer document are designed as snippets of text within the text flow, including all text formattings and line breaks. It can not overflow. It will even spread across page borders.
For a text box with a fixed place you need a form control which is availlable as text box (single or multi line), as date box, time box, numeric box, formatted box, currency box or masked field. A text box has interface http://www.openoffice.org/api/docs/comm ... rains.html which calculates the minimum size for a given text.
Install MRI and restart the office
menu:View>Toolbars>Form Controls
Design Mode = On
Draw a text box
Design mode = Off
Tools>Add-Ons>Mri
Dbl-Click DrawPage, Forms, method getByIndex, 0
For a text box with a fixed place you need a form control which is availlable as text box (single or multi line), as date box, time box, numeric box, formatted box, currency box or masked field. A text box has interface http://www.openoffice.org/api/docs/comm ... rains.html which calculates the minimum size for a given text.
Install MRI and restart the office
menu:View>Toolbars>Form Controls
Design Mode = On
Draw a text box
Design mode = Off
Tools>Add-Ons>Mri
Dbl-Click DrawPage, Forms, method getByIndex, 0
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: How to detect overflow of content in TextFrame?
I won't comment on the FormControl aspects. It's a pity that a term like TextField was allowed to occur in two very different meanings.
However, the question was about TextFrame whether containing TextField of one or another kind or not. To handle a TextFrame by user code the question if the contained text did overflow is relevant and should allow for a simple way to check.
I didn't find one. We can do it using the workaround function below which also is demonstrated in the attached example. Since I don't use Python, I give it in Basic. Please tell me if you know a simpler way meanwhile. (Probably a property of TextFrame telling it directly.)
However, the question was about TextFrame whether containing TextField of one or another kind or not. To handle a TextFrame by user code the question if the contained text did overflow is relevant and should allow for a simple way to check.
I didn't find one. We can do it using the workaround function below which also is demonstrated in the attached example. Since I don't use Python, I give it in Basic. Please tell me if you know a simpler way meanwhile. (Probably a property of TextFrame telling it directly.)
Code: Select all
Function textOverflow(Optional pTextFrame As Object) As Long
On Local error Goto leExit
textOverflow = -2 REM No TextFrame given!
oldSel = ThisComponent.CurrentController.ViewCursor
If IsMissing(pTextFrame) Then REM Shorthand not accepted by old versions.
pTextFrame = ThisComponent.CurrentController.getViewCursor().TextFrame
End If
If NOT pTextFrame.supportsService("com.sun.star.text.TextFrame") Then
Exit Function
End If
textOverflow = 0
preWidthType = pTextFrame.WidthType
If (pTextFrame.FrameIsAutomaticHeight OR (pTextFrame.WidthType<>1)) Then
textOverflow = 2 REM Automatic size. No overflow allowed.
Else
preLayoutSize = pTextFrame.LayoutSize
pTextFrame.FrameIsAutomaticHeight = True
If preLayoutSize.Height<pTextFrame.LayoutSize.Height Then
textOverflow = 1
pTextFrame.FrameIsAutomaticHeight = False
pTextFrame.WidthType = preWidthType
End If
pTextFrame.FrameIsAutomaticHeight = False
End If
leExit:
ThisComponent.CurrentController.select(oldSel)
End Function
- Attachments
-
- frameOverflow.odt
- (30.62 KiB) Downloaded 140 times
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München
Re: How to detect overflow of content in TextFrame?
Thank you so much. MRI... It's awesome.
I though that there should be easy way to check whether content inside container fits to size of container.
Cause TextFrames and table cells both shows 'red triangle' when content spill out. So there might be common
way to check it, libreoffice UI should display 'red triangle'. But it seems not so easy like this...
Anyway, I was able to write function to check whether textframe content spilled out or not. It's just rewrote code of Lupp's.
Thanks a lot!
My initial question is solved, for TextFrames. But what about TextTable cells?
Is there really no API/method/Property to detect content overflow, generally?
Thinking from postion 'red triangle' displayed in containers, it might be property or method
of paragraph, but I still haven't found one.
I though that there should be easy way to check whether content inside container fits to size of container.
Cause TextFrames and table cells both shows 'red triangle' when content spill out. So there might be common
way to check it, libreoffice UI should display 'red triangle'. But it seems not so easy like this...
Anyway, I was able to write function to check whether textframe content spilled out or not. It's just rewrote code of Lupp's.
Thanks a lot!
Code: Select all
def check_textframe_content_spilled_out(textframe):
is_overflow = 0
if textframe.FrameIsAutomaticHeight or textframe.WidthType != 1:
# Automatic Size. Never spill out.
is_overflow = 2
return False
prevlayout = textframe.LayoutSize
prevwidthtype = textframe.WidthType
prevautoheight = textframe.FrameIsAutomaticHeight
textframe.FrameIsAutomaticHeight = True
if prevlayout.Height < textframe.LayoutSize.Height:
is_overflow = 1
textframe.FrameIsAutomaticHeight = prevautoheight
textframe.WidthType = prevwidthtype
if is_overflow == 1:
return True
Is there really no API/method/Property to detect content overflow, generally?
Thinking from postion 'red triangle' displayed in containers, it might be property or method
of paragraph, but I still haven't found one.
LibreOffice 6.1.3.2
Linux
Linux
Re: [Half-Solved] How to detect overflow of content in TextF
I don't think there is one on the API level. Of course there is code to maintain and control everything needed for the persentation (layout, formatting aids, and the like) and for printing. But much code may not fit perfectly into the interface-and-service driven variant of object oriented programming the OpenOffice API is based on. If you also are using Calc and occasionally writing user code for it, you will have noticed e.g. that you cannot ask a cell for attributes overlaid by conditional formattig. That's a range of clearly visible attributes applied to the cell grid in the view and alo for printing, but not accessible via the API. A basically blue cell colored red by CF will always tell you its CellBackColor is blue, even if it's placed in the view and shining bright red. (The same with oveflow markers also existing in Calc.)i12o wrote:Thinking from postion 'red triangle' displayed in containers, it might be property or method
of paragraph, but I still haven't found one.
There isn't as far as I know, and the workaround I invented and demonstrated for TextFrame objects is not available for TextTable cells. The property .LayoutSize implemented and published for TextFrame does not exist in the cell case, and the automatic-height property, if set, isn't assigned to cells, but to rows. A roughly similar workaround would therefore require much additional fuss. You may study ways to use a linecursor, and the .Position property of the ViewCursor. I would assume it's always too complicated, and also too error-prone due to the many thinkable situations, like nesting of what you called containers.i120 wrote:Cause TextFrames and table cells both shows 'red triangle' when content spill out. So there might be common
way to check it,...
My advice for myself: Forget it!
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München