Bug 119519 - Basic: insert graphicobject via ThisComponent.createInstance("com.sun.star.text.GraphicObject") not working in 6.1.0.3
Summary: Basic: insert graphicobject via ThisComponent.createInstance("com.sun.star.te...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
6.1.0.3 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Regressions-imageHandling
  Show dependency treegraph
 
Reported: 2018-08-26 19:24 UTC by Kai Struck
Modified: 2024-02-03 03:15 UTC (History)
6 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kai Struck 2018-08-26 19:24:54 UTC
Description:
Tying to insert a linked graphicobject via ThisComponent.createInstance("com.sun.star.text.GraphicObject")
and 
oText.insertTextContent(oCursor, oGraph, False)
leads to an empty image frame (loading error)

Steps to Reproduce:
Customize the image url and run this Basic code:
Sub InsertGraphicObject
 Dim oDoc
 Dim sURL
 Dim oCursor
 Dim oGraph
 Dim oText
 
 sURL= ConvertToUrl("C:\Users\username\image.jpg")
 oDoc = ThisComponent
 oText = oDoc.getText()
 oCursor = oText.createTextCursor()
 oCursor.gotoStart(False)
 oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject")
 
 With oGraph
 .GraphicURL = sURL
 .Width = 6000
 .Height = 8000
 End With
 
 oText.insertTextContent(oCursor, oGraph, False)
End Sub

Actual Results:
An empty image frame appears saying "Loading Error"

Expected Results:
The image should be inserted correctly and appear.


Reproducible: Always


User Profile Reset: No



Additional Info:
Comment 1 Drew Jensen 2018-08-26 20:36:04 UTC
Confirmed with Ubuntu 18.04 and 
Version: 6.1.1.0.0+
Build ID: 30c178dcb3301527ad92bbd245d1525ab77e314e

The macro works as expected in 6.0.5 and 6.2Alpha
Comment 2 Drew Jensen 2018-08-26 20:42:31 UTC
This could be related to a resolved issue from the changes to how images are handled.

See: https://bugs.documentfoundation.org/show_bug.cgi?id=117427
Comment 3 Drew Jensen 2018-08-26 20:44:55 UTC
Will add Tomaž Vajngerl to CC, perhaps he would know on that.
Comment 4 Xisco Faulí 2018-08-27 14:23:55 UTC
@Raal, is it the same case you investigated with Miklos in the Hamburg Hackfest?
Comment 5 Xisco Faulí 2018-08-27 15:17:55 UTC
Kai Struck, Could you please read the comments in bug 117427 to help you adapt your code?
Comment 6 Kai Struck 2018-08-28 09:52:54 UTC
Xisco Faulí,

Ok, after reading it and using the function getGraphFromUrlAsLink
for oGraph.Graphic I can make the above example code work: 


Sub InsertGraphicObject
 Dim oDoc
 Dim sURL
 Dim oCursor
 Dim oGraph
 Dim oText
 
 sURL= ConvertToUrl("http://pmg.pmgroup.be/enews/deroulard/exploit1.jpg")
 oDoc = ThisComponent
 oText = oDoc.getText()
 oCursor = oText.createTextCursor()
 oCursor.gotoStart(False)
 oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject")
 oGraph.Graphic = getgraphfromurlaslink(sURL)  
 With oGraph
rem .GraphicURL = sURL
 .Width = 6000
 .Height = 8000
 End With
 
 oText.insertTextContent(oCursor, oGraph, False)

End Sub

function getGraphFromUrlAsLink(sFileUrl as String ) as Object 
  oProvider = createUnoService("com.sun.star.graphic.GraphicProvider") 
  Dim oPropsIN(1)as new com.sun.star.beans.PropertyValue 
  oPropsIN(0).Name  = "URL" 
  oPropsIN(0).Value = converttoURL(sFileUrl)
  oPropsIN(1).Name  = "LoadAsLink" 
  oPropsIN(1).Value = TRUE
  getGraphFromUrlAsLink = oProvider.queryGraphic(oPropsIN()) 
 end function


To get the URL of the image we now must use
oGraph.Graphic.OriginURL instead of oGraph.GraphicURL

If that means that all older code has to be adapted (possibly with a version check to make it compatible with older versions) then I'm not too happy about that.
Comment 7 Kai Struck 2018-08-28 10:10:01 UTC
With simple version check for compatibility for older Versions (just for info, still hoping not being forced to use it):
Sub InsertGraphicObject
 Dim oDoc
 Dim sURL
 Dim oCursor
 Dim oGraph
 Dim oText
 
 sURL= ConvertToUrl("http://pmg.pmgroup.be/enews/deroulard/exploit1.jpg")
 oDoc = ThisComponent
 oText = oDoc.getText()
 oCursor = oText.createTextCursor()
 oCursor.gotoStart(False)
 oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject")
 
if Officeversion="LibreOffice6.1" then 
oGraph.Graphic = getgraphfromurlaslink(sURL) 
else
oGraph.GraphicURL = sURL
end if 

 With oGraph
 .Width = 6000
 .Height = 8000
 End With
 
 oText.insertTextContent(oCursor, oGraph, False)
 
if Officeversion="LibreOffice6.1" then 
msgbox oGraph.Graphic.OriginURL
else
msgbox oGraph.GraphicURL
end if 

End Sub

function getGraphFromUrlAsLink(sFileUrl as String ) as Object 
  oProvider = createUnoService("com.sun.star.graphic.GraphicProvider") 
  Dim oPropsIN(1)as new com.sun.star.beans.PropertyValue 
  oPropsIN(0).Name  = "URL" 
  oPropsIN(0).Value = converttoURL(sFileUrl)
  oPropsIN(1).Name  = "LoadAsLink" 
  oPropsIN(1).Value = TRUE
  getGraphFromUrlAsLink = oProvider.queryGraphic(oPropsIN()) 
 end function

function Officeversion
GlobalScope.BasicLibraries.loadLibrary("Tools")
Officeversion =  GetProductName()
end function
Comment 8 Kai Struck 2018-08-30 12:36:15 UTC
Hallo,
will the api changes go into any version higher than 6.0.x.x?
If so then I would use a version check like:

if val(replace(Officeversion,"LibreOffice",""))>6 then
oGraph.Graphic = getgraphfromurlaslink(sURL) 
else
oGraph.GraphicURL = sURL
end if 

function Officeversion
If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then GlobalScope.BasicLibraries.LoadLibrary("Tools")
Officeversion =  GetProductName()
end function
Comment 9 Mike Kaganski 2019-03-06 08:29:49 UTC
I have just tested the code from comment 6, as is, in Apache OpenOffice 3.4.1. And it just works. The API used there should be working down to OOo 3.3.0 (in 3.2.0, neither that, nor previous code would work). So - what is the reason for version checks suggested in comments 7 and 8?
Comment 10 Mike Kaganski 2019-03-06 08:40:27 UTC
Ah, sorry - not "as is"; just with uncommented ".GraphicURL = sURL" line, which also doesn't give problems here with LO 6.2.2.1 (and could be wrapped into On Error Resume Next ... On Error Goto 0).
Comment 11 Kai Struck 2020-02-01 20:21:22 UTC
@ Mike Kaganski

The Code from Comment 6 only "seems" to work without problems in older LO versions and OO. But it doesn't link the image. the image will be embedded.
At least on all my tests here. 

Therefore the version checks.
Comment 12 Kai Struck 2020-02-02 20:58:12 UTC
Ah, ok , forget my previous answer, I misread your comment 10.

You are right! It should work for all versions (LO and OO) with this code:


Sub InsertGraphicObject
 Dim oDoc
 Dim sURL
 Dim oCursor
 Dim oGraph
 Dim oText
 
 sURL= ConvertToUrl("http://pmg.pmgroup.be/enews/deroulard/exploit1.jpg")
 oDoc = ThisComponent
 oText = oDoc.getText()
 oCursor = oText.createTextCursor()
 oCursor.gotoStart(False)
 oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject")
 oGraph.Graphic = getgraphfromurlaslink(sURL)  
 With oGraph
 .GraphicURL = sURL
 .Width = 6000
 .Height = 8000
 End With
 
 oText.insertTextContent(oCursor, oGraph, False)

End Sub

function getGraphFromUrlAsLink(sFileUrl as String ) as Object 
  oProvider = createUnoService("com.sun.star.graphic.GraphicProvider") 
  Dim oPropsIN(1)as new com.sun.star.beans.PropertyValue 
  oPropsIN(0).Name  = "URL" 
  oPropsIN(0).Value = converttoURL(sFileUrl)
  oPropsIN(1).Name  = "LoadAsLink" 
  oPropsIN(1).Value = TRUE
  getGraphFromUrlAsLink = oProvider.queryGraphic(oPropsIN()) 
 end function
Comment 13 QA Administrators 2022-02-02 03:40:19 UTC Comment hidden (obsolete)
Comment 14 QA Administrators 2024-02-03 03:15:43 UTC
Dear Kai Struck,

To make sure we're focusing on the bugs that affect our users today, LibreOffice QA is asking bug reporters and confirmers to retest open, confirmed bugs which have not been touched for over a year.

There have been thousands of bug fixes and commits since anyone checked on this bug report. During that time, it's possible that the bug has been fixed, or the details of the problem have changed. We'd really appreciate your help in getting confirmation that the bug is still present.

If you have time, please do the following:

Test to see if the bug is still present with the latest version of LibreOffice from https://www.libreoffice.org/download/

If the bug is present, please leave a comment that includes the information from Help - About LibreOffice.
 
If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a comment that includes the information from Help - About LibreOffice.

Please DO NOT

Update the version field
Reply via email (please reply directly on the bug tracker)
Set the bug's Status field to RESOLVED - FIXED (this status has a particular meaning that is not 
appropriate in this case)


If you want to do more to help you can test to see if your issue is a REGRESSION. To do so:
1. Download and install oldest version of LibreOffice (usually 3.3 unless your bug pertains to a feature added after 3.3) from https://downloadarchive.documentfoundation.org/libreoffice/old/

2. Test your bug
3. Leave a comment with your results.
4a. If the bug was present with 3.3 - set version to 'inherited from OOo';
4b. If the bug was not present in 3.3 - add 'regression' to keyword


Feel free to come ask questions or to say hello in our QA chat: https://web.libera.chat/?settings=#libreoffice-qa

Thank you for helping us make LibreOffice even better for everyone!

Warm Regards,
QA Team

MassPing-UntouchedBug