|
Sub ImportImagesToFullScreenAndBreak |
|
Dim oDoc As Object |
|
Dim oDrawPages As Object |
|
Dim oNewPage As Object |
|
Dim oFolderPicker As Object |
|
Dim oSFA As Object |
|
Dim sFolderUrl As String |
|
Dim allFiles() As String |
|
Dim fileList() As String |
|
Dim fileCount As Long |
|
Dim i As Long, j As Long, k As Long |
|
Dim sTemp As String |
|
Dim oShape As Object |
|
Dim oSubShape As Object |
|
Dim aSize As New com.sun.star.awt.Size |
|
Dim aPosition As New com.sun.star.awt.Point |
|
|
|
Dim oFrame As Object |
|
Dim oDispatcher As Object |
|
Dim oController As Object |
|
Dim args(0) As New com.sun.star.beans.PropertyValue |
|
|
|
' Font update variables |
|
Dim bUpdateFont As Boolean |
|
Dim sFontName As String |
|
Dim iAns As Integer |
|
|
|
' ========================================== |
|
' CONFIGURATION & ADJUSTMENT VARIABLES |
|
' ========================================== |
|
Dim pxToUnit As Double |
|
Dim targetWidth As Long |
|
Dim targetHeight As Long |
|
Dim posX As Long |
|
Dim posY As Long |
|
|
|
pxToUnit = 1920 / 28000 |
|
targetWidth = 1920 / pxToUnit |
|
targetHeight = 1080 / pxToUnit |
|
posX = 0 |
|
posY = 0 |
|
' ========================================== |
|
|
|
oDoc = ThisComponent |
|
oDrawPages = oDoc.getDrawPages() |
|
oController = oDoc.getCurrentController() |
|
oFrame = oController.getFrame() |
|
oDispatcher = CreateUnoService("com.sun.star.frame.DispatchHelper") |
|
|
|
' 1. Ask user about Font updates |
|
bUpdateFont = False |
|
iAns = MsgBox("Do you want to update all fonts in the broken-apart SVGs?", 4 + 32, "Font Update Setup") |
|
If iAns = 6 Then ' 6 = Yes |
|
sFontName = InputBox("Enter target font name:", "Select Font", "Arial") |
|
If Trim(sFontName) <> "" Then |
|
bUpdateFont = True |
|
End If |
|
End If |
|
|
|
' 2. Open Folder Picker Dialog |
|
oFolderPicker = CreateUnoService("com.sun.star.ui.dialogs.FolderPicker") |
|
oFolderPicker.setDisplayDirectory(ConvertToURL(Environ("HOME") & "/Documents/")) |
|
|
|
If oFolderPicker.execute() = 1 Then |
|
sFolderUrl = oFolderPicker.getDirectory() & "/" |
|
Else |
|
Exit Sub |
|
End If |
|
|
|
' 3. Read directory using SimpleFileAccess |
|
oSFA = CreateUnoService("com.sun.star.ucb.SimpleFileAccess") |
|
allFiles = oSFA.getFolderContents(sFolderUrl, False) |
|
|
|
fileCount = 0 |
|
For i = LBound(allFiles) To UBound(allFiles) |
|
Dim sExt As String |
|
sExt = LCase(Right(allFiles(i), 4)) |
|
If sExt = ".svg" Or sExt = ".png" Then |
|
ReDim Preserve fileList(fileCount) |
|
fileList(fileCount) = allFiles(i) |
|
fileCount = fileCount + 1 |
|
End If |
|
Next i |
|
|
|
If fileCount = 0 Then |
|
MsgBox "No SVG or PNG files found in the selected directory.", 48, "Error" |
|
Exit Sub |
|
End If |
|
|
|
' 4. Alphabetically sort files (Bubble Sort) |
|
For i = 0 To fileCount - 2 |
|
For j = i + 1 To fileCount - 1 |
|
If StrComp(fileList(i), fileList(j), 1) > 0 Then |
|
sTemp = fileList(i) |
|
fileList(i) = fileList(j) |
|
fileList(j) = sTemp |
|
End If |
|
Next j |
|
Next i |
|
|
|
' 5. Process each file onto a new slide |
|
For i = 0 To fileCount - 1 |
|
' Create a new slide and explicitly set its layout to Blank |
|
oNewPage = oDrawPages.insertNewByIndex(oDrawPages.getCount()) |
|
oNewPage.Layout = 20 ' 20 represents the standard Blank Slide layout in LibreOffice Impress |
|
oController.setCurrentPage(oNewPage) |
|
|
|
If LCase(Right(fileList(i), 4)) = ".svg" Then |
|
' --- SVG IMPORT & BREAK --- |
|
args(0).Name = "FileName" |
|
args(0).Value = fileList(i) |
|
oDispatcher.executeDispatch(oFrame, ".uno:InsertGraphic", "", 0, args()) |
|
|
|
Wait 250 |
|
|
|
oShape = oNewPage.getByIndex(oNewPage.getCount() - 1) |
|
|
|
aSize.Width = targetWidth |
|
aSize.Height = targetHeight |
|
oShape.setSize(aSize) |
|
aPosition.X = posX |
|
aPosition.Y = posY |
|
oShape.setPosition(aPosition) |
|
|
|
oController.select(oShape) |
|
Wait 250 |
|
|
|
oDispatcher.executeDispatch(oFrame, ".uno:Break", "", 0, Array()) |
|
Wait 250 |
|
|
|
' --- OPTIONAL FONT UPDATE WORKER --- |
|
' Once broken apart, the original graphic becomes a shape Group Object |
|
If bUpdateFont Then |
|
Dim oPageShapes As Object |
|
Dim m As Long |
|
oPageShapes = oNewPage |
|
|
|
' Iterate backwards through all shapes created by the Break command |
|
For k = oPageShapes.getCount() - 1 To 0 Step -1 |
|
oSubShape = oPageShapes.getByIndex(k) |
|
|
|
' If it's a group shape generated by the break, check inside it |
|
If oSubShape.supportsService("com.sun.star.drawing.GroupShape") Then |
|
For m = 0 To oSubShape.getCount() - 1 |
|
Dim oChild As Object |
|
oChild = oSubShape.getByIndex(m) |
|
If oChild.PropertySetInfo.hasPropertyByName("CharFontName") Then |
|
oChild.CharFontName = sFontName |
|
End If |
|
Next m |
|
End If |
|
|
|
' Check if the base or un-grouped shape itself supports text font formatting |
|
If oSubShape.PropertySetInfo.hasPropertyByName("CharFontName") Then |
|
oSubShape.CharFontName = sFontName |
|
End If |
|
Next k |
|
End If |
|
Else |
|
' --- PNG STANDARD METHODS --- |
|
oShape = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape") |
|
oNewPage.add(oShape) |
|
oShape.GraphicURL = fileList(i) |
|
|
|
aSize.Width = targetWidth |
|
aSize.Height = targetHeight |
|
oShape.setSize(aSize) |
|
aPosition.X = posX |
|
aPosition.Y = posY |
|
oShape.setPosition(aPosition) |
|
End If |
|
Next i |
|
|
|
MsgBox "Successfully processed " & fileCount & " files!", 64, "Done" |
|
End Sub |