summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2021-09-28 17:37:36 +0200
committerJean-Pierre Ledure <jp@ledure.be>2021-09-28 19:11:00 +0200
commit0bcc4b55d723f73b2fb7a86fcfebeca49905079e (patch)
treeba462709b7b4e6d607db73ab0cf1cdb7ceeaf275 /wizards
parentdf37d83500f7fe94046afb8817d29bd4ee650635 (diff)
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@ledure.be> Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards')
-rw-r--r--wizards/source/scriptforge/SF_L10N.xba2
-rw-r--r--wizards/source/scriptforge/SF_Platform.xba28
-rw-r--r--wizards/source/scriptforge/SF_Root.xba2
-rw-r--r--wizards/source/scriptforge/SF_Utils.xba5
-rw-r--r--wizards/source/scriptforge/python/scriptforge.py2
5 files changed, 37 insertions, 2 deletions
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 &apos; 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
@@ -74,6 +74,15 @@ Property Get CurrentUser() As String
End Property &apos; ScriptForge.SF_Platform.CurrentUser (get)
REM -----------------------------------------------------------------------------
+Property Get Fonts() As Variant
+&apos;&apos;&apos; Returns the list of available fonts as an unsorted array of unique strings
+&apos;&apos;&apos; To get the list sorted, use SF_Array.Sort()
+&apos;&apos;&apos; Example:
+&apos;&apos;&apos; myFontsList = platform.Fonts
+ Fonts = _PropertyGet(&quot;Fonts&quot;)
+End Property &apos; ScriptForge.SF_Platform.Fonts (get)
+
+REM -----------------------------------------------------------------------------
Property Get Locale() As String
&apos;&apos;&apos; Returns the locale combining language-COUNTRY (la-CO)
&apos;&apos;&apos; Example:
@@ -218,6 +227,7 @@ Public Function Properties() As Variant
, &quot;ComputerName&quot; _
, &quot;CPUCount&quot; _
, &quot;CurrentUser&quot; _
+ , &quot;Fonts&quot; _
, &quot;Locale&quot; _
, &quot;Machine&quot; _
, &quot;OfficeVersion&quot; _
@@ -308,6 +318,12 @@ Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
Dim sOSName As String &apos; Operating system
Dim oLocale As Object &apos; com.sun.star.lang.Locale
Dim oPrinterServer As Object &apos; com.sun.star.awt.PrinterServer
+Dim oToolkit As Object &apos; com.sun.star.awt.Toolkit
+Dim oDevice As Object &apos; com.sun.star.awt.XDevice
+Dim oFontDescriptors As Variant &apos; Array of com.sun.star.awt.FontDescriptor
+Dim sFonts As String &apos; Comma-separated list of fonts
+Dim sFont As String &apos; A single font name
+Dim i As Long
Const cstPyHelper = &quot;$&quot; &amp; &quot;_SF_Platform&quot;
Dim cstThisSub As String
@@ -322,6 +338,18 @@ Const cstSubArgs = &quot;&quot;
With ScriptForge.SF_Session
_PropertyGet = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper &amp; cstPyHelper, psProperty)
End With
+ Case &quot;Fonts&quot;
+ Set oToolkit = SF_Utils._GetUnoService(&quot;Toolkit&quot;)
+ Set oDevice = oToolkit.createScreenCompatibleDevice(0, 0)
+ oFontDescriptors = oDevice.FontDescriptors()
+ sFonts = &quot;,&quot;
+ &apos; Select only not yet registered fonts
+ For i = 0 To UBound(oFontDescriptors)
+ sFont = oFontDescriptors(i).Name
+ If InStr(sFonts, &quot;,&quot; &amp; sFont &amp; &quot;,&quot;) = 0 Then sFonts = sFonts &amp; sFont &amp; &quot;,&quot;
+ Next i
+ &apos; Remove leading and trailing commas
+ If Len(sFonts) &gt; 1 Then _PropertyGet = Split(Mid(sFonts, 2, Len(sFonts) - 2), &quot;,&quot;) Else _PropertyGet = Array()
Case &quot;Locale&quot;
Set oLocale = SF_Utils._GetUNOService(&quot;Locale&quot;)
_PropertyGet = oLocale.Language &amp; &quot;-&quot; &amp; 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 &apos; com.sun.star.configuration.ConfigurationProvider
Private MailService As Object &apos; com.sun.star.system.SimpleCommandMail or com.sun.star.system.SimpleSystemMail
Private GraphicExportFilter As Object &apos; com.sun.star.drawing.GraphicExportFilter
+Private Toolkit As Object &apos; com.sun.star.awt.Toolkit
&apos; Specific persistent services objects or properties
Private FileSystemNaming As String &apos; If &quot;SYS&quot;, 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 = &quot;&quot;
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(&quot;com.sun.star.util.TextSearch&quot;)
End If
Set _GetUNOService = .TextSearch
+ Case &quot;Toolkit&quot;
+ If IsEmpty(.Toolkit) Or IsNull(.Toolkit) Then
+ Set .Toolkit = CreateUnoService(&quot;com.sun.star.awt.Toolkit&quot;)
+ End If
+ Set _GetUNOService = .Toolkit
Case &quot;URLTransformer&quot;
If IsEmpty(.URLTransformer) Or IsNull(.URLTransformer) Then
Set .URLTransformer = CreateUnoService(&quot;com.sun.star.util.URLTransformer&quot;)
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