Issue 85105 - ActualSize of is not initialized if pic inserted programmatically.
Summary: ActualSize of is not initialized if pic i...
Alias: None
Product: Writer
Classification: Application
Component: code (show other issues)
Version: OOo 2.3.1
Hardware: All All
: P3 Trivial with 4 votes (vote)
Target Milestone: 3.4.0
Assignee: michael.ruess
QA Contact: issues@sw
Keywords: regression
: 95730 (view as issue list)
Depends on:
Reported: 2008-01-09 12:52 UTC by villeroy
Modified: 2017-05-20 10:30 UTC (History)
5 users (show)

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


Note You need to log in before you can comment on or make changes to this issue.
Description villeroy 2008-01-09 12:52:48 UTC
After manual insertion of a graphic (Insert>Picture>From file...) I have a
TextGraphicObject with a read-only property "ActualSize".
This propertie's struct is unset (Height=0, Width=0) if I do the same thing via API.
Basic code from
Edit the graphicUrl and run with a Writer document as thisComponent.

Sub Main
graphicUrl = "file:///home/andreas/Documents/Bilder/sott_religion1024x768.jpg"
graphic = thisComponent.createInstance("")
graphic.GraphicURL = graphicUrl
xTextRange = thisComponent.CurrentSelection.getByIndex(0)
xTextRange.getText().insertTextContent(xTextRange.getEnd(), graphic, false)

sz = graphic.ActualSize
print sz.Width, sz.Height ' prints 0, 0
End Sub
Comment 1 jsc 2008-01-14 08:44:43 UTC
jsc -> tl:seems to be one for you
Comment 2 thomas.lange 2008-03-14 13:14:34 UTC
Comment 3 andrew 2008-12-16 00:05:26 UTC
Although issue 97291 is different, they may have related solutions:
Comment 4 kpalagin 2008-12-16 04:45:20 UTC
*** Issue 95730 has been marked as a duplicate of this issue. ***
Comment 5 kpalagin 2008-12-16 04:48:32 UTC
added assignee from 95730 to CC
Comment 6 Oliver Specht 2008-12-16 06:31:42 UTC
Reassigned to od
->od: The property is queried from SwGrfNode::GetTwipSize().
Comment 7 kpalagin 2008-12-16 11:54:28 UTC
thanks a lot!

As 2.1 does not have this bug I set keyword regression.
Comment 8 kpalagin 2009-02-16 07:41:02 UTC
any chance to fix this issue for 3.2?

Thanks a lot for your attention.
Comment 9 Oliver-Rainer Wittmann 2009-02-26 11:17:48 UTC
Investigation reveals the following:
The graphic is inserted as a link. Thus, the intrinsic graphic is loaded
asynchronous in a background thread - issue 73788. Until the graphic is
completely loaded its "ActualSize" attribute is not initialized.
Unfortunately, the "ActualSize" attribute is requested before the graphic is
completely loaded.

Possible solutions:
A: Perform something like "busy-waiting" on accessing the "ActualSize" attribute
- loop of access; check, if set; if set then go on else wait a moment and
perform loop-body again.
B: Trigger a synchronous load of a linked graphic on request its "ActualSize"

I vote for solution A. Otherwise the advantages of the asynchronous load of
linked graphics are partly lost - see issue 73788

OD->villeroy, kpalagin:
What is your opinion?
Comment 10 villeroy 2009-02-28 10:44:59 UTC
Option C could be a remark in the documentation that certain properties, such as
ActualSize, are availlable after the picture has been loaded completely.
I vote for option A.
Comment 11 michael.ruess 2009-03-13 16:48:52 UTC
*** Issue 100157 has been marked as a duplicate of this issue. ***
Comment 12 samuha76 2009-06-18 23:08:53 UTC
I also experienced problems with the property "ActualSize" of a
TextGraphicObject. And I am sure that the bug it is not just due to the
asynchronous loading of the image in the background. The proposed solution A
does not work for me. My basic macro looped forever if I did not trigger by some
other means the update of the ActualSize property. I have found that watching
the contents of the TextGraphic object in the OOo Basic IDE updates the field
ActualSize. Also using XRay ( to inspect the
object updates the ActualSize field. I then identified the line in the XRay
macro which triggers the update. The field is updated when the property
"IsPixelContour" is read:

I am now using this in my routine to update an existing graphic or create a new
graphic. The code is the following:

Function ImportBitmapIntoWriter(sFile As String, Optional oTextGraphic) As Object
	' Imports a bitmap into Writer
	Dim oDoc As Object
	Dim oBitmaps As Object
	Dim sNewUrl As String
	Dim oCursor As Object
	Dim oText As Object
	Const INCH = 2540

	oDoc = ThisComponent

	' Load the image into the internal bitmap table
	oBitmaps = oDoc.createInstance("")
	oBitmaps.insertByName( "OOoLilyPond", ConvertToURL(sFile) )
	sNewURL = oBitmaps.getByName( "OOoLilyPond" )
	' Create a new TextGraphic Object, if needed
	If IsMissing(oTextGraphic) Then
		oText = oCursor.getText()
		oTextGraphic = oDoc.createInstance("")
		oTextGraphic.GraphicURL = sNewURL
		oTextGraphic.AnchorType =
		oText.insertTextContent( oCursor, oTextGraphic, False )
	End If

	' remove the Bitmap from the table
	' (otherwise the Bitmaps of deleted Objects will still be referenced and saved)
	oBitmaps.removeByName( "OOoLilyPond" )

	' this triggers the updating of the property "ActualSize"
	' see
	' set the original graphic size

'	oTextGraphic	
	' select the object

	'return the TextGraphic object
	ImportBitmapIntoWriter = oTextGraphic	
End Function

If reading "IsPixelContour" triggers the update of "ActualSize". It should be
implemented that reading "ActualSize" also triggers the same action. Or
alternatively if there is really a time delay due to the asynchronous loading of
the image there should be a property "GraphicIsLoaded" and a method

Comment 13 Mathias_Bauer 2011-02-09 11:03:09 UTC
Please don't implement option "A" - this is a can of worms. Switching to
synchronous loading is better. 
Comment 14 villeroy 2011-02-09 15:42:40 UTC
I revoke my vote for option A and vote for B now. I believe that mba is more
knowledgeable than me.
Comment 15 Oliver-Rainer Wittmann 2011-03-11 14:19:20 UTC
fixed in cws sw34bf05 - changed files:
change set
Comment 16 Oliver-Rainer Wittmann 2011-03-11 14:20:46 UTC
forgot to adjust status
Comment 17 Oliver-Rainer Wittmann 2011-03-14 09:53:41 UTC
reviewed code to fix this issue with OS
Comment 18 Oliver-Rainer Wittmann 2011-03-21 09:26:16 UTC
od->mru: Checked in internal installation set of cws sw34bf05 - please verify.
Comment 19 michael.ruess 2011-03-22 13:04:00 UTC
Verified fix in CWS sw34bf05.