« Return to Thread: Embedded Image

Re: Embedded Image

by Fernand Vanrie :: Rate this Message:

Reply to Author | View in Thread

Ariel ,

You are a hero , it works like a charme
thanks for all  your time spended to make us (dummy's) smarter  ,)

Greetz Fernand

> Hello Fernand,
>
> On Tuesday 16 June 2009, 10:13, Fernand Vanrie wrote:
>  
>> Hallo Ariel ,
>>
>> the opengrok link is not working,
>>    
>
> change DEV300_m** by the most recent, like DEV300_m50
> http://svn.services.openoffice.org/opengrok/xref/DEV300_m50/odk/examples/java/Text/GraphicsInserter.java#155
>
>  
>> maybe you can write it down in basic? :-)
>>    
>
> here you have it :-)
>
> REM  *****  BASIC  *****
>
> Option Explicit
>
>
> Sub Writer_Demo
> Dim oDoc as Object
> oDoc = CreateNewDoc("writer")
>
> Dim sImage$
> sImage = getGalleryPath() & "/www-back/aqua.jpg"
> Dim oImage as Object
> oImage = CreateEmbeddedGraphicObject(oDoc, sImage)
> oImage.Width = 5000
> oImage.Height = 5000
>
> Dim oText as Object, oCursor as Object
> oText = oDoc.getText()
> oCursor = oText.createTextCursorByRange(oText.getStart())
> oText.insertTextContent(oCursor, oImage, False)
> End Sub
>
> Sub Draw_Demo
> Dim oDoc as Object
> oDoc = CreateNewDoc("draw")
>
> Dim oDrawPage as Object
> oDrawPage = oDoc.getDrawPages().getByIndex(0)
>
> Dim sImage$
> sImage = getGalleryPath() & "/www-back/aqua.jpg"
> Dim oImage as Object
> oImage = CreateEmbeddedGraphicObject(oDoc, sImage)
>
> Dim aSize as New com.sun.star.awt.Size
> aSize.Width = 5000
> aSize.Height = 5000
> Dim aPos as New com.sun.star.awt.Point
> aPos.X = CInt(oDrawPage.Width/2 - aSize.Width/2)
> aPos.Y = CInt(oDrawPage.Height/2 - aSize.Height/2)
>
> oImage.setSize(aSize)
> oImage.setPosition(aPos)
>
> oDrawPage.add(oImage)
> End Sub
>
>
> Function CreateNewDoc( sDocType as String, _
> Optional MediaDescriptor(), _
> Optional sFrame as String ) as Object
> On Error Resume Next
> If IsMissing(MediaDescriptor()) then MediaDescriptor() = Array()
> If IsMissing(sFrame) then sFrame = "_default"
> CreateNewDoc = StarDesktop.loadComponentFromURL(_
> "private:factory/s" & sDocType , _
> sFrame, 0, MediaDescriptor())
> End Function
>
>
> Function CreateEmbeddedGraphicObject( oDoc as Object, sURL as String ) as
> Object
> On Error Resume Next
> Dim sService as String
> If oDoc.supportsService("com.sun.star.text.TextDocument") Then
> sService = "com.sun.star.text.TextGraphicObject"
> Else
> sService = "com.sun.star.drawing.GraphicObjectShape"
> End If
>
> Dim oGraphicObject as Object
> oGraphicObject = oDoc.createInstance(sService)
> oGraphicObject.setPropertyValue("Graphic", getGraphicFromURL(sURL))
>
> CreateEmbeddedGraphicObject = oGraphicObject
> End Function
>
>
> Function getGraphicFromURL( sURL as String) as com.sun.star.graphic.XGraphic
> On Error Resume Next
> Dim oGraphicProvider as Object
> oGraphicProvider = createUnoservice("com.sun.star.graphic.GraphicProvider")
>
> Dim aMediaProperties(0) as New com.sun.star.beans.PropertyValue
> aMediaProperties(0).Name = "URL"
> aMediaProperties(0).Value = sURL
>
> getGraphicFromURL = oGraphicProvider.queryGraphic(aMediaProperties)
> End Function
>
>
> Function getGalleryPath() as String
> On Error Resume Next
> Dim oPathSettings as Object
> oPathSettings = createUNOService("com.sun.star.util.PathSettings")
>
> Dim sPath$
> sPath = oPathSettings.getPropertyValue("Gallery")
> If InStr(sPath, ";") Then
> Dim sPaths()
> sPaths = Split(sPath, ";")
> sPath = sPaths(0)
> End If
> getGalleryPath = sPath
> End Function
>
>
> Regards
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...

 « Return to Thread: Embedded Image