[Libreoffice-commits] core.git: wizards/source

Jean-Pierre Ledure (via logerrit) logerrit at kemper.freedesktop.org
Tue Sep 28 17:11:38 UTC 2021


 wizards/source/scriptforge/SF_L10N.xba           |    2 -
 wizards/source/scriptforge/SF_Platform.xba       |   28 +++++++++++++++++++++++
 wizards/source/scriptforge/SF_Root.xba           |    2 +
 wizards/source/scriptforge/SF_Utils.xba          |    5 ++++
 wizards/source/scriptforge/python/scriptforge.py |    2 -
 5 files changed, 37 insertions(+), 2 deletions(-)

New commits:
commit 0bcc4b55d723f73b2fb7a86fcfebeca49905079e
Author:     Jean-Pierre Ledure <jp at ledure.be>
AuthorDate: Tue Sep 28 17:37:36 2021 +0200
Commit:     Jean-Pierre Ledure <jp at ledure.be>
CommitDate: Tue Sep 28 19:11:00 2021 +0200

    ScriptForge - (SF_Platform) new Fonts property
    
    The Fonts property returns the list of available fonts
    as an unsorted array of unique font names
    
    The size of the array being potentially huge, the choice
    has been made to not sort the list at each invocation
    of the property.
    To get it sorted, use the SF_Array.Sort() method.
    
    The property is available both from Basic and Python scripts.
    It is read-only.
    
    Change-Id: I49233d279dc7257d3b97e5a17be0bc8807f18d67
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122780
    Tested-by: Jean-Pierre Ledure <jp at ledure.be>
    Tested-by: Jenkins
    Reviewed-by: Jean-Pierre Ledure <jp at ledure.be>

diff --git a/wizards/source/scriptforge/SF_L10N.xba b/wizards/source/scriptforge/SF_L10N.xba
index 8b09d85db437..859f67386ba4 100644
--- a/wizards/source/scriptforge/SF_L10N.xba
+++ b/wizards/source/scriptforge/SF_L10N.xba
@@ -818,4 +818,4 @@ Private Function _Repr() As String
 End Function	'	ScriptForge.SF_L10N._Repr
 
 REM ============================================ END OF SCRIPTFORGE.SF_L10N
-</script:module>
+</script:module>
\ No newline at end of file
diff --git a/wizards/source/scriptforge/SF_Platform.xba b/wizards/source/scriptforge/SF_Platform.xba
index 5c2970823d05..703ae195b942 100644
--- a/wizards/source/scriptforge/SF_Platform.xba
+++ b/wizards/source/scriptforge/SF_Platform.xba
@@ -73,6 +73,15 @@ Property Get CurrentUser() As String
 	CurrentUser = _PropertyGet("CurrentUser")
 End Property	'	ScriptForge.SF_Platform.CurrentUser (get)
 
+REM -----------------------------------------------------------------------------
+Property Get Fonts() As Variant
+'''	Returns the list of available fonts as an unsorted array of unique strings
+'''	To get the list sorted, use SF_Array.Sort()
+'''	Example:
+'''		myFontsList = platform.Fonts
+	Fonts = _PropertyGet("Fonts")
+End Property	'	ScriptForge.SF_Platform.Fonts (get)
+
 REM -----------------------------------------------------------------------------
 Property Get Locale() As String
 '''	Returns the locale combining language-COUNTRY (la-CO)
@@ -218,6 +227,7 @@ Public Function Properties() As Variant
 					, "ComputerName" _
 					, "CPUCount" _
 					, "CurrentUser" _
+					, "Fonts" _
 					, "Locale" _
 					, "Machine" _
 					, "OfficeVersion" _
@@ -308,6 +318,12 @@ Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
 Dim sOSName As String			'	Operating system
 Dim oLocale As Object			'	com.sun.star.lang.Locale
 Dim oPrinterServer As Object	'	com.sun.star.awt.PrinterServer
+Dim oToolkit As Object			'	com.sun.star.awt.Toolkit
+Dim oDevice As Object			'	com.sun.star.awt.XDevice
+Dim oFontDescriptors As Variant	'	Array of com.sun.star.awt.FontDescriptor
+Dim sFonts As String			'	Comma-separated list of fonts
+Dim sFont As String				'	A single font name
+Dim i As Long
 
 Const cstPyHelper = "$" & "_SF_Platform"
 Dim cstThisSub As String
@@ -322,6 +338,18 @@ Const cstSubArgs = ""
 			With ScriptForge.SF_Session
 				_PropertyGet = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper & cstPyHelper, psProperty)
 			End With
+		Case "Fonts"
+			Set oToolkit = SF_Utils._GetUnoService("Toolkit")
+			Set oDevice = oToolkit.createScreenCompatibleDevice(0, 0)
+			oFontDescriptors = oDevice.FontDescriptors()
+			sFonts = ","
+			'	Select only not yet registered fonts
+			For i = 0 To UBound(oFontDescriptors)
+				sFont = oFontDescriptors(i).Name
+				If InStr(sFonts, "," & sFont & ",") = 0  Then sFonts = sFonts & sFont & ","
+			Next i
+			'	Remove leading and trailing commas
+			If Len(sFonts) > 1 Then _PropertyGet = Split(Mid(sFonts, 2, Len(sFonts) - 2), ",") Else _PropertyGet = Array()
 		Case "Locale"
 			Set oLocale = SF_Utils._GetUNOService("Locale")
 			_PropertyGet = oLocale.Language & "-" & oLocale.Country
diff --git a/wizards/source/scriptforge/SF_Root.xba b/wizards/source/scriptforge/SF_Root.xba
index 7d9132caf205..258eea4bde2f 100644
--- a/wizards/source/scriptforge/SF_Root.xba
+++ b/wizards/source/scriptforge/SF_Root.xba
@@ -73,6 +73,7 @@ Private ConfigurationProvider _
 							As Object	' com.sun.star.configuration.ConfigurationProvider
 Private MailService			As Object	' com.sun.star.system.SimpleCommandMail or com.sun.star.system.SimpleSystemMail
 Private GraphicExportFilter	As Object	' com.sun.star.drawing.GraphicExportFilter
+Private Toolkit				As Object	' com.sun.star.awt.Toolkit
 
 '	Specific persistent services objects or properties
 Private FileSystemNaming	As String	' If "SYS", file and folder naming is based on operating system notation
@@ -135,6 +136,7 @@ Private Sub Class_Initialize()
 	Set ConfigurationProvider = Nothing
 	Set MailService = Nothing
 	Set GraphicExportFilter = Nothing
+	Set Toolkit = Nothing
 	OSName = ""
 	SFDialogs = Empty
 	SFForms = Empty
diff --git a/wizards/source/scriptforge/SF_Utils.xba b/wizards/source/scriptforge/SF_Utils.xba
index 1505e4cfd308..b18a42781bab 100644
--- a/wizards/source/scriptforge/SF_Utils.xba
+++ b/wizards/source/scriptforge/SF_Utils.xba
@@ -439,6 +439,11 @@ Dim vNodePath As Variant
 					Set .TextSearch = CreateUnoService("com.sun.star.util.TextSearch")
 				End If
 				Set _GetUNOService = .TextSearch
+			Case "Toolkit"
+				If IsEmpty(.Toolkit) Or IsNull(.Toolkit) Then
+					Set .Toolkit = CreateUnoService("com.sun.star.awt.Toolkit")
+				End If
+				Set _GetUNOService = .Toolkit
 			Case "URLTransformer"
 				If IsEmpty(.URLTransformer) Or IsNull(.URLTransformer) Then
 					Set .URLTransformer = CreateUnoService("com.sun.star.util.URLTransformer")
diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py
index 12039b1d923d..29825e4ccece 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -1209,7 +1209,7 @@ class SFScriptForge:
         servicename = 'ScriptForge.Platform'
         servicesynonyms = ('platform', 'scriptforge.platform')
         serviceproperties = dict(Architecture = False, ComputerName = False, CPUCount = False, CurrentUser = False,
-                                 Locale = False, Machine = False, OfficeVersion = False, OSName = False,
+                                 Fonts = False, Locale = False, Machine = False, OfficeVersion = False, OSName = False,
                                  OSPlatform = False, OSRelease = False, OSVersion = False, Printers = False,
                                  Processor = False, PythonVersion = False)
         # Python helper functions


More information about the Libreoffice-commits mailing list