Bug 120527 - sw TextGraphicObject: handle XBitmap for GraphicURL - make it available in Draw and Impress
Summary: sw TextGraphicObject: handle XBitmap for GraphicURL - make it available in Dr...
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
6.1.1.2 release
Hardware: All All
: medium normal
Assignee: Miklos Vajna
URL:
Whiteboard: target:6.3.0 target:6.2.0.1 target:6.1.5
Keywords: regression
Depends on:
Blocks:
 
Reported: 2018-10-11 19:26 UTC by Klaus Blum
Modified: 2018-12-09 21:17 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Screenshot of LO Basic debugger (37.15 KB, image/png)
2018-10-12 17:44 UTC, Klaus Blum
Details
LilyPond-generated SVG file for testing (11.26 KB, image/svg+xml)
2018-11-14 16:10 UTC, Klaus Blum
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Klaus Blum 2018-10-11 19:26:36 UTC
Description:
Calling getByName() on the bitmap table and expecting that the result can be set as a value for the GraphicURL property was no more possible in 6.1.1.2 release.

This ability has been restored in 6.1.2.1 release:
https://gerrit.libreoffice.org/#/c/59850/2
but it seems that it is only fixed in LO Writer. 

It would be great if this would be also available in other LO components like Draw and Impress.

Steps to Reproduce:
http://document-foundation-mail-archive.969070.n3.nabble.com/API-CHANGE-dropping-string-properties-which-use-vnd-sun-star-GraphicObject-URL-tp4235349p4247610.html

Actual Results:
Calling getByName() on the bitmap table causes an "Incorrect property value" error in LO Draw and Impress

Expected Results:
restored compatibility for other components as it is already available for Writer


Reproducible: Always


User Profile Reset: No



Additional Info:
Comment 1 Miklos Vajna 2018-10-12 07:19:38 UTC
Could you please paste reproducer code for Impress? As far as I see the code from the link is for Writer. Thanks!
Comment 2 Klaus Blum 2018-10-12 08:38:39 UTC
Up to the line that causes the error, the code is exactly the same as for Writer. 
Here it is: 

Function ImportBitmapIntoDraw(sURL As String, Optional oGraphicShape) As Object
	' Imports a bitmap into Draw or Impress
	Dim oBitmaps As Object
	Dim sNewUrl
	Dim oDoc As Object

	oDoc = ThisComponent
	
	oBitmaps = oDoc.createInstance("com.sun.star.drawing.BitmapTable")
	If oBitmaps.hasByName( "OOoLilyPond" ) Then
		oBitmaps.removeByName( "OOoLilyPond" )
	End If
	oBitmaps.insertByName( "OOoLilyPond", ConvertToURL(sURL) )
	' sURL contains a valid path to a SVG graphic file

	' Here the "incorrect property value" error will occur: 
	sNewURL = oBitmaps.getByName( "OOoLilyPond" )

	' do some more stuff...
End Function
Comment 3 Miklos Vajna 2018-10-12 08:41:27 UTC
Could you please double-check this is indeed happening? My understand is that the problem happens when the URL would be used as a value for some Impress bitmap shape property. If you declare sNewUrl without a type, then it would be really surprising if you could not get your named bitmap from the bitmap table.

What is unclear to me (but you probably know it) is the Impress equivalent of

>        oTextGraphic = oDoc.createInstance("com.sun.star.text.GraphicObject")
>        oTextGraphic.GraphicURL = sNewURL
Comment 4 Klaus Blum 2018-10-12 17:44:28 UTC
Created attachment 145661 [details]
Screenshot of LO Basic debugger
Comment 5 Klaus Blum 2018-10-12 19:03:28 UTC
Yes, I can confirm this behaviour in the 6.1.2.1 release. 

In both functions (Writer and Draw/Impress), I've set a breakpoint on the line 
    sNewURL = oBitmaps.getByName( "OOoLilyPond" )
and observed the bitmap table (see attached). 
It looks exactly the same in Writer, Draw and Impress. It contains one element called "OOoLilyPond". That looks correct so far. 

Executing the next step (i.e. the line containing getByName) causes the "incorrect property value" error. 

I'm not sure what you are referring to with "Impress equivalent". If you are talking about 
    oDrawPage=oDocCtrl.getCurrentPage()
later in the non-shortened ImportBitmapIntoDraw function: I have no clue.  ;-)
That code wasn't written by me, I just took over the project when the original developer retired. But apparently it has worked so far.
Comment 6 Klaus Blum 2018-11-13 23:01:41 UTC
The problem with Draw and Impress persists in the 6.1.3.2 (x64) Release. 

Are there any further informations I could provide to help?
Comment 7 Miklos Vajna 2018-11-14 08:25:23 UTC
Yes; the question from comment 3 is still unanswered. :-) If you could please provide a simple macro which does the followings:

- create an Impress bitmap shape
- load an image into the bitmap table
- get the bitmap from the bitmap table and set it on the bitmap shape

and which works on 6.0.x, that would be great -- it would allow us to fix 6.1 and master relatively easily. I assume that your lilypond macro/extension does it already in some form. Thanks!
Comment 8 Klaus Blum 2018-11-14 16:08:15 UTC
Okay, now I know what is still missing. 

Here is a function for Draw and Impress that hopefully does what you need. 
It contains a path to a SVG file that you'd have to adjust to work on your machine. 
I'll attach a LilyPond-generated SVG file, but of course any graphics file should work. 

The following code works fine in 6.0.7.3, 
but fails in 6.1.0.3, 6.1.1.2, 6.1.2.1 and 6.1.3.2:

---------------------------------------------------------

Sub SVG_Test
	Dim oDrawPage As Object
	Dim oBitmaps As Object
	Dim sNewUrl
	Dim oSize As Object
	Dim oShape As Object
	Dim oDoc As Object
	Dim oDocCtrl As Object
	Dim oCrop As new com.sun.star.text.GraphicCrop

	oDoc = ThisComponent
	oDocCtrl = oDoc.getCurrentController
	
	oBitmaps = oDoc.createInstance("com.sun.star.drawing.BitmapTable")
	If oBitmaps.hasByName( "OOoLilyPond" ) Then
		oBitmaps.removeByName( "OOoLilyPond" )
	End If
	oBitmaps.insertByName( "OOoLilyPond", ConvertToURL("C:\Users\Admin\Desktop\Test.svg") )
	' Replace this by a valid path to a graphics file on your machine
	sNewURL = oBitmaps.getByName( "OOoLilyPond" )

	'Insert the Bitmap
	oDrawPage=oDocCtrl.getCurrentPage()
	oGraphicShape = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape")
	oGraphicShape.graphicURL=sNewURL   ' This line causes the error.
	oDrawPage.add(oGraphicShape)
		
	'Set the correct Size
	oSize = createUnoStruct( "com.sun.star.awt.Size" )
	oSize.width =  oGraphicShape.Graphic.Size100thMM.Width
	oSize.height = oGraphicShape.Graphic.Size100thMM.Height

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

	' refresh the view
	oDocCtrl.restoreViewData(oDocCtrl.getViewData)		
	
	oGraphicShape.setSize(oSize)							' apply size as calculated above
	oGraphicShape.setPropertyValue ("GraphicCrop", oCrop)	' overwrite old Crop settings
End Sub
Comment 9 Klaus Blum 2018-11-14 16:10:27 UTC
Created attachment 146621 [details]
LilyPond-generated SVG file for testing
Comment 10 Klaus Blum 2018-11-16 17:56:22 UTC
...just to be on the safe side: Is this test macro what you need? 
If anything is still missing, please let me know.
Comment 11 Miklos Vajna 2018-11-20 16:26:31 UTC
Right, confirmed the bug now.
Comment 12 Miklos Vajna 2018-11-20 18:33:48 UTC
I'll take care of this.
Comment 13 Commit Notification 2018-11-27 08:05:03 UTC
Miklos Vajna committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/+/e30f3e76a9350e2b027d99bba5a46aa0a0ff8256%5E%21

tdf#120527 svx GraphicObjectShape: handle XBitmap for GraphicURL

It will be available in 6.3.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 14 Klaus Blum 2018-11-30 08:15:28 UTC
It works!  :)

Tested with
libo-master64~2018-11-27_20.06.55_LibreOfficeDev_6.3.0.0.alpha0_Win_x64

I can confirm that the problem in Draw and Impress is fixed now. 
Thanks a lot!
Comment 15 Xisco Faulí 2018-12-02 13:46:09 UTC
Cherry-picked to 6-2 in https://gerrit.libreoffice.org/#/c/64427/

@Miklos, should it be cherry-picked to 6-1 and 6-1-4 as well ?
Thanks for fixing this!
Comment 16 Klaus Blum 2018-12-02 15:27:23 UTC
+1  :)

That would be great!
Comment 17 Commit Notification 2018-12-05 16:53:51 UTC
Miklos Vajna committed a patch related to this issue.
It has been pushed to "libreoffice-6-2":

https://git.libreoffice.org/core/+/07b098c126cdd01a2ce4335aeb4e1dad134c7f32%5E%21

tdf#120527 svx GraphicObjectShape: handle XBitmap for GraphicURL

It will be available in 6.2.0.1.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 18 Miklos Vajna 2018-12-05 17:01:58 UTC
(In reply to Xisco Faulí from comment #15)
> @Miklos, should it be cherry-picked to 6-1 and 6-1-4 as well ?

https://gerrit.libreoffice.org/64643

Feel free to cherry-pick it further to libreoffice-6-1-4.
Comment 19 Commit Notification 2018-12-09 21:17:36 UTC
Miklos Vajna committed a patch related to this issue.
It has been pushed to "libreoffice-6-1":

https://git.libreoffice.org/core/+/323d12f278d3b0a51c7c2b8d3a362a27a6a232d3%5E%21

tdf#120527 svx GraphicObjectShape: handle XBitmap for GraphicURL

It will be available in 6.1.5.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.