Apache OpenOffice (AOO) Bugzilla – Issue 63211
API: Impossible to Ascertain the Actual Size of a TextFrame
Last modified: 2013-02-24 21:08:06 UTC
FrameHeightAbsolute returns a Constant Regardless of Actual Text Content If I have a frame with automatic height and put some text into it and then ask the height of the frame I always get a default initial height - 41. Interestingly if I do the exact same thing with a com.sun.star.drawing.TextShape then it works. getSize() returns the size after the the text gets inserted. Furthermore LeftBorderDistance, RightBorderDistance, TopBorderDistance, BottomBorderDistance do not return sensible values on the TextFrame either. ########### CODE TO REPRODUCE ################################### Object writerShape = documentFactory.createInstance("com.sun.star.text.TextFrame" ); XTextContent xTextContentShape = ( XTextContent )UnoRuntime.queryInterface( XTextContent.class, writerShape ); XPropertySet xTextContentPropertySet = ( XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xTextContentShape ); xTextContentPropertySet.setPropertyValue( "Width", newInteger( width ) ); xTextContentPropertySet.setPropertyValue( ANCHOR_TYPE,TextContentAnchorType.AT_FRAME ); xTextContentPropertySet.setPropertyValue( TEXT_WRAP,WrapTextMode.NONE ); xTextContentPropertySet.setPropertyValue(FRAME_IS_AUTOMATIC_HEIGHT, new Boolean( true ) ); XPropertySet xShapeProps = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class,writerShape ); // Setting the vertical position xShapeProps.setPropertyValue( VERT_ORIENT, new Short(VertOrientation.NONE ) ); xShapeProps.setPropertyValue( HORI_ORIENT, new Short(HoriOrientation.NONE ) ); // I need to recalculate x & y for the header // Setting the vertical position xShapeProps.setPropertyValue( HORI_ORIENT_POSITION,new Integer( ( x.intValue() ) ) ); xShapeProps.setPropertyValue( VERT_ORIENT_POSITION,new Integer( ( y.intValue() ) ) ); // making sure that text can overlap xShapeProps.setPropertyValue( BACK_TRANSPARENT,Boolean.TRUE ); xShapeProps.setPropertyValue( OPAQUE, Boolean.FALSE ); XText xShapeText = ( XText )UnoRuntime.queryInterface( XText.class, writerShape ); mxDocText.insertTextContent( xParaCursor,xTextContentShape, false ); xShapeText.setString( textContentString + getDebugString( x, y, width, height ) + getRNDString()); // xTextContentPropertySet also gives me the same result Long result = AnyConverter.toLong(theFramePropSet.getPropertyValue("FrameHeightAbsolute")); System.out.println("heightInteger " + result);
MRU->CN: this looks like an API problem. Please correct me if I am wrong.
cn->rkentgibson: This is not a P1 issue, please take a look at here: http://www.openoffice.org/scdocs/ddIssues_EnterModify.html#priority
cn->rkentgibson: your samlpe code is not buildable. Can you support me a code wich includes vaulues of "width", "x", "y"... and implementations of "getDebugString()", ...?
Alrighty here is a better example. For this example you only need a Document Factory, and an XTextDocument. ##################################################### public void toOpenOffice() throws java.lang.Exception { XMultiServiceFactory documentFactory = this.connection.getDocumentFactory(); Object writerShape = documentFactory.createInstance( "com.sun.star.text.TextFrame" ); XTextContent xTextContentShape = ( XTextContent ) UnoRuntime.queryInterface( XTextContent.class, writerShape ); XPropertySet xTextContentPropertySet = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, xTextContentShape ); xTextContentPropertySet.setPropertyValue( "FrameWidthAbsolute", new Integer( 5000 ) ); xTextContentPropertySet.setPropertyValue( "AnchorType", TextContentAnchorType.AT_PAGE ); xTextContentPropertySet.setPropertyValue( "TextWrap", WrapTextMode.NONE ); xTextContentPropertySet.setPropertyValue( "FrameIsAutomaticHeight", new Boolean( true ) ); XPropertySet xShapeProps = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, writerShape ); xShapeProps.setPropertyValue( "VertOrient", new Short( VertOrientation.NONE ) ); xShapeProps.setPropertyValue( "HoriOrient", new Short( HoriOrientation.NONE ) ); xShapeProps.setPropertyValue( "HoriOrientPosition", new Integer( ( 500 ) ) ); xShapeProps.setPropertyValue( "VertOrientPosition", new Integer( ( 500 ) ) ); XText xShapeText = ( XText ) UnoRuntime.queryInterface( XText.class, writerShape ); XText mxDocText = this.connection.getTextDocument() .getText(); mxDocText.insertTextContent( mxDocText.createTextCursor(), xTextContentShape, false ); xShapeText.setString( "SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT" ); long result = AnyConverter.toLong( xTextContentPropertySet.getPropertyValue( "FrameHeightAbsolute" ) ); System.out.println( "heightInteger " + result ); } ################### thanks.
cn->tl: I could reproduce this. I have created a complex test for this. But it's currenlty not commitet into ooo-cvs, so please contact me for reproduction
Here is the Basic macro for the Java Code: ================= Sub Main oDoc = thiscomponent documentFactory = oDoc writerShape = documentFactory.createInstance( "com.sun.star.text.TextFrame" ) xTextContentShape = writerShape xTextContentPropertySet = xTextContentShape xTextContentPropertySet.setPropertyValue( "FrameWidthAbsolute", 5000 ) xTextContentPropertySet.setPropertyValue( "AnchorType", com.sun.star.text.TextContentAnchorType.AT_PAGE ) xTextContentPropertySet.setPropertyValue( "TextWrap", com.sun.star.text.WrapTextMode.NONE ) xTextContentPropertySet.setPropertyValue( "FrameIsAutomaticHeight", true ) xShapeProps = writerShape xShapeProps.setPropertyValue( "VertOrient", com.sun.star.text.VertOrientation.NONE ) xShapeProps.setPropertyValue( "HoriOrient", com.sun.star.text.HoriOrientation.NONE ) xShapeProps.setPropertyValue( "HoriOrientPosition", 500 ) xShapeProps.setPropertyValue( "VertOrientPosition", 500 ) xShapeText = writerShape mxDocText = oDoc.getText() mxDocText.insertTextContent( mxDocText.createTextCursor(), xTextContentShape,false ) xShapeText.setString( "SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT SOME RANDOM TEXT" ) 'xTextContentPropertySet.setPropertyValue("FrameHeightAbsolute", 15000 ) result = xTextContentPropertySet.getPropertyValue("FrameHeightAbsolute" ) msgbox "heightInteger " + result End Sub =================
Here is a workaround: you create a viewcursor and then get its y position then go to the end and then get the y postion again. // get the cursor XTextViewCursor xViewCursor = xViewCursorSupplier.getViewCursor(); xViewCursor.gotoRange( frameCursor, false ); Point pos = xViewCursor.getPosition(); int yPos1 = pos.Y; xViewCursor.gotoEnd( false ); pos = xViewCursor.getPosition(); int yPos2 = pos.Y; long actualHeight = yPos2 - yPos1;
.
this issue has been a big headache for us in terms of workarounds requirered, although it may be too late, we really would like to see this fixed in 2.0.3.# thanks
For OO2.0.3 it is already to late since already for some time now only showstopper get accepted for that target. For OOo 2.0.4 we need a new property sth. like "LayoutSize" that has the correct value. Of course as the name indicates this value will only be usefull if the document is already layouted.
Fixed in CWS tl21. There is now a property 'LayoutSize' of type css.awt.Size available for frames. It can be used to get the layouted size of the frame. It will be void if the frame is not yet layouted though. Files changed: sw: - inc/unomap.hxx - inc/unoprnms.hxx - source/core/unocore/unoframe.cxx - source/core/unocore/unomap.cxx - source/core/unocore/unoprnms.cxx offapi: - com/sun/star/text/BaseFrameProperties.idl
thanks a million for that. Is there any chance it will be released with 2.0.3? I will be very happy to test it, even in a release candidate build.
Created attachment 36700 [details] Sample document to test new property
No, since as mentioned now only showstoppers get accepted. It will take to much time in QA to check another CWS and would delay OOo 2.0.3 further. Just as example: A fully automated UI test takes several days! Also there is always the chance that there will be an unexpected side effect or minor mistake that may break something else. Unfortunately that kind of errors often happens to be discovered onyl by chance in an early or short phase. Thus it is better to not add any new feature (even if they are as little as this one) in this late stage. We better watch it for several developer builds and see if it works fine and serves you needs. We had some really bad experience with late/little features/bugfixes over the years. :-(
oh well, thanks again.
unfortunately the workaround I posted is really buggy. Do you know anyway that I could select the textframe and then get the height by using a command dispatcher, or any other way that I can get the actual height. The information is there in the ui in the status bar, I just have no idea how to access it. thanks.
. re-open issue and reassign to cn@openoffice.org
reassign to cn@openoffice.org
reset resolution to FIXED
sorry to pester, but does anyone have any idea when this might get incorporated into any type of build? For example a developer build. This is turning into a big showstopper for us. Because of this one property we have to put a lot of development on hold. We rely heavily on dynamically sized frames within tables so we are really stuck. thanks
tested in tl21
change target to 2.0.4
Alrighty thanks for this tl. I have tested this in src680_m178 (OOo-Dev 2.0), with tables and text, in the headers and normal text areas, and it works. I will test also images and frames larger than a page and report any problems, if there are any. One thing that is interesting, which is perhaps a bug, or perhaps a feature, but nevertheless should be documented is the following. If you insert content into the header and then you query the layoutsize it returns void. However as soon as you add content to the page, then it starts returning a value.
further to the LayoutSize of objects in the header area. I have just relealized that this may be a problem for us. Sorry to sound so demanding. We have a use case where we want to render just the elements in the header. So that means if there is no content in the body and I try to render the header elements, the LayoutSize will not be available. Hmm. Unless someone thinks this is a bug, or I am doing something wrong, I am going to create a feature requist. regards
ok in src680_m192