Issue 63211 - API: Impossible to Ascertain the Actual Size of a TextFrame
Summary: API: Impossible to Ascertain the Actual Size of a TextFrame
Status: CLOSED FIXED
Alias: None
Product: App Dev
Classification: Unclassified
Component: api (show other issues)
Version: 3.3.0 or older (OOo)
Hardware: All All
: P3 Trivial
Target Milestone: ---
Assignee: chne
QA Contact: issues@api
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-15 13:32 UTC by rkentgibson
Modified: 2013-02-24 21:08 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
Sample document to test new property (8.54 KB, application/octet-stream)
2006-05-24 13:08 UTC, thomas.lange
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description rkentgibson 2006-03-15 13:32:15 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);
Comment 1 michael.ruess 2006-03-15 14:27:29 UTC
MRU->CN: this looks like an API problem. Please correct me if I am wrong.
Comment 2 chne 2006-03-15 15:09:46 UTC
cn->rkentgibson: This is not a P1 issue, please take a look at here:
http://www.openoffice.org/scdocs/ddIssues_EnterModify.html#priority
Comment 3 chne 2006-03-15 15:38:12 UTC
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()", ...?
Comment 4 rkentgibson 2006-03-15 16:49:28 UTC
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.
Comment 5 chne 2006-03-16 12:47:41 UTC
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
Comment 6 thomas.lange 2006-04-18 13:37:31 UTC
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
=================

Comment 7 rkentgibson 2006-05-08 07:09:21 UTC
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;
Comment 8 thomas.lange 2006-05-12 08:34:24 UTC
.
Comment 9 rkentgibson 2006-05-18 09:47:14 UTC
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
Comment 10 thomas.lange 2006-05-19 10:37:23 UTC
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.
Comment 11 thomas.lange 2006-05-24 12:51:35 UTC
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



Comment 12 rkentgibson 2006-05-24 13:05:18 UTC
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.
Comment 13 thomas.lange 2006-05-24 13:08:34 UTC
Created attachment 36700 [details]
Sample document to test new property
Comment 14 thomas.lange 2006-05-24 13:31:58 UTC
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. :-(
Comment 15 rkentgibson 2006-05-24 15:00:50 UTC
oh well, thanks again.
Comment 16 rkentgibson 2006-05-26 19:43:51 UTC
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.
Comment 17 thomas.lange 2006-06-16 09:19:42 UTC
.

re-open issue and reassign to cn@openoffice.org
Comment 18 thomas.lange 2006-06-16 09:19:46 UTC
reassign to cn@openoffice.org
Comment 19 thomas.lange 2006-06-16 09:19:50 UTC
reset resolution to FIXED
Comment 20 rkentgibson 2006-06-16 10:03:42 UTC
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
Comment 21 chne 2006-07-13 19:06:57 UTC
tested in tl21
Comment 22 chne 2006-07-14 07:56:38 UTC
change target to 2.0.4
Comment 23 rkentgibson 2006-07-28 13:03:21 UTC
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. 

Comment 24 rkentgibson 2006-07-28 14:06:59 UTC
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

Comment 25 chne 2006-11-09 16:38:06 UTC
ok in src680_m192