sd/qa/unit/PNGExportTests.cxx                    |   66 +++++++++++++++++++++++
 sd/qa/unit/data/odp/tdf105998.odp                |binary
 wizards/source/scriptforge/SF_Platform.xba       |   39 ++++++++++++-
 wizards/source/scriptforge/SF_Root.xba           |    8 ++
 wizards/source/scriptforge/SF_Utils.xba          |   56 ++++++++++++++-----
 wizards/source/scriptforge/python/scriptforge.py |    7 +-
 6 files changed, 155 insertions(+), 21 deletions(-)

New commits:
commit 50696923190add8131f8a2de63ba0ae8e9688d85
Author:     Jean-Pierre Ledure <[email protected]>
AuthorDate: Tue Feb 1 17:30:01 2022 +0100
Commit:     Jean-Pierre Ledure <[email protected]>
CommitDate: Tue Feb 1 19:26:49 2022 +0100

    ScriptForge - (SF_Platform) refine locales
    
    So far, only SF_Platform.Locale was supported, returning
    the locale of the operating system.
    
    Now, 3 different locales may be considered:
    
    - SystemLocale: identical to Locale (still supported)
    - OfficeLocale: the locale associated with the LibreOffice
      installation
    - FormatLocale: the locale associated with how numbers and
      dates are formatted.
    
    Of course, in many cases all locales are identical. Anyway
    a distinction can be made.
    
    All these properties are read-only.
    
    Those properties are supported in Basic and Python evenly.
    
    Change-Id: I0792d49a052b1441a30ac231d61eda997dc4216a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129297
    Tested-by: Jean-Pierre Ledure <[email protected]>
    Tested-by: Jenkins
    Reviewed-by: Jean-Pierre Ledure <[email protected]>

diff --git a/wizards/source/scriptforge/SF_Platform.xba 
b/wizards/source/scriptforge/SF_Platform.xba
index a19ee2bc7a6c..8bd7b5cad35f 100644
--- a/wizards/source/scriptforge/SF_Platform.xba
+++ b/wizards/source/scriptforge/SF_Platform.xba
@@ -82,9 +82,17 @@ Property Get Fonts() As Variant
        Fonts = _PropertyGet(&quot;Fonts&quot;)
 End Property   &apos;  ScriptForge.SF_Platform.Fonts (get)
 
+REM 
-----------------------------------------------------------------------------
+Property Get FormatLocale() As String
+&apos;&apos;&apos;     Returns the locale used for number and date formats, 
combining language-COUNTRY (la-CO)
+&apos;&apos;&apos;     Example:
+&apos;&apos;&apos;             MsgBox platform.FormatLocale
+       FormatLocale = _PropertyGet(&quot;FormatLocale&quot;)
+End Property   &apos;  ScriptForge.SF_Platform.FormatLocale (get)
+
 REM 
-----------------------------------------------------------------------------
 Property Get Locale() As String
-&apos;&apos;&apos;     Returns the locale combining language-COUNTRY (la-CO)
+&apos;&apos;&apos;     Returns the locale of the operating system, combining 
language-COUNTRY (la-CO)
 &apos;&apos;&apos;     Example:
 &apos;&apos;&apos;             MsgBox platform.Locale
        Locale = _PropertyGet(&quot;Locale&quot;)
@@ -104,6 +112,14 @@ Property Get ObjectType As String
        ObjectType = &quot;SF_Platform&quot;
 End Property   &apos;  ScriptForge.SF_Platform.ObjectType
 
+REM 
-----------------------------------------------------------------------------
+Property Get OfficeLocale() As String
+&apos;&apos;&apos;     Returns the locale of the user interface, combining 
language-COUNTRY (la-CO)
+&apos;&apos;&apos;     Example:
+&apos;&apos;&apos;             MsgBox platform.OfficeLocale
+       OfficeLocale = _PropertyGet(&quot;OfficeLocale&quot;)
+End Property   &apos;  ScriptForge.SF_Platform.OfficeLocale (get)
+
 REM 
-----------------------------------------------------------------------------
 Property Get OfficeVersion() As String
 &apos;&apos;&apos;     Returns the office software version in the form 
&apos;LibreOffice w.x.y.z (The Document Foundation)&apos;
@@ -175,6 +191,14 @@ Property Get ServiceName As String
        ServiceName = &quot;ScriptForge.Platform&quot;
 End Property   &apos;  ScriptForge.SF_Platform.ServiceName
 
+REM 
-----------------------------------------------------------------------------
+Property Get SystemLocale() As String
+&apos;&apos;&apos;     Returns the locale of the operating system, combining 
language-COUNTRY (la-CO)
+&apos;&apos;&apos;     Example:
+&apos;&apos;&apos;             MsgBox platform.SystemLocale
+       SystemLocale = _PropertyGet(&quot;SystemLocale&quot;)
+End Property   &apos;  ScriptForge.SF_Platform.SystemLocale (get)
+
 REM ===================================================================== 
METHODS
 
 REM 
-----------------------------------------------------------------------------
@@ -228,8 +252,10 @@ Public Function Properties() As Variant
                                        , &quot;CPUCount&quot; _
                                        , &quot;CurrentUser&quot; _
                                        , &quot;Fonts&quot; _
+                                       , &quot;FormatLocale&quot; _
                                        , &quot;Locale&quot; _
                                        , &quot;Machine&quot; _
+                                       , &quot;OfficeLocale&quot; _
                                        , &quot;OfficeVersion&quot; _
                                        , &quot;OSName&quot; _
                                        , &quot;OSPlatform&quot; _
@@ -238,6 +264,7 @@ Public Function Properties() As Variant
                                        , &quot;Printers&quot; _
                                        , &quot;Processor&quot; _
                                        , &quot;PythonVersion&quot; _
+                                       , &quot;SystemLocale&quot; _
                                        )
 
 End Function   &apos;  ScriptForge.SF_Platform.Properties
@@ -350,8 +377,11 @@ Const cstSubArgs = &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;SystemLocale&quot;)
+               Case &quot;FormatLocale&quot;
+                       Set oLocale = 
SF_Utils._GetUNOService(&quot;FormatLocale&quot;)
+                       _PropertyGet = oLocale.Language &amp; &quot;-&quot; 
&amp; oLocale.Country
+               Case &quot;OfficeLocale&quot;
+                       Set oLocale = 
SF_Utils._GetUNOService(&quot;OfficeLocale&quot;)
                        _PropertyGet = oLocale.Language &amp; &quot;-&quot; 
&amp; oLocale.Country
                Case &quot;OfficeVersion&quot;
                        _PropertyGet = _GetProductName()
@@ -371,6 +401,9 @@ Const cstSubArgs = &quot;&quot;
                        _PropertyGet = sOSName
                Case &quot;Printers&quot;
                        _PropertyGet = _GetPrinters()
+               Case &quot;SystemLocale&quot;, &quot;Locale&quot;
+                       Set oLocale = 
SF_Utils._GetUNOService(&quot;SystemLocale&quot;)
+                       _PropertyGet = oLocale.Language &amp; &quot;-&quot; 
&amp; oLocale.Country
                Case Else
                        _PropertyGet = Null
        End Select
diff --git a/wizards/source/scriptforge/SF_Root.xba 
b/wizards/source/scriptforge/SF_Root.xba
index 9d03fcd6f160..d14e121173cd 100644
--- a/wizards/source/scriptforge/SF_Root.xba
+++ b/wizards/source/scriptforge/SF_Root.xba
@@ -58,7 +58,9 @@ Private CoreReflection                As Object       &apos; 
com.sun.star.reflection.CoreReflection
 Private DispatchHelper         As Object       &apos; 
com.sun.star.frame.DispatchHelper
 Private TextSearch                     As Object       &apos; 
com.sun.star.util.TextSearch
 Private SearchOptions          As Object       &apos; 
com.sun.star.util.SearchOptions
-Private Locale                         As Object       &apos; 
com.sun.star.lang.Locale
+Private SystemLocale           As Object       &apos; com.sun.star.lang.Locale
+Private OfficeLocale           As Object       &apos; com.sun.star.lang.Locale
+Private FormatLocale           As Object       &apos; com.sun.star.lang.Locale
 Private PrinterServer          As Object       &apos; 
com.sun.star.awt.PrinterServer
 Private CharacterClass         As Object       &apos; 
com.sun.star.i18n.CharacterClassification
 Private FileAccess                     As Object       &apos; 
com.sun.star.ucb.SimpleFileAccess
@@ -118,7 +120,9 @@ Private Sub Class_Initialize()
        Set DispatchHelper = Nothing
        Set TextSearch = Nothing
        Set SearchOptions = Nothing
-       Set Locale = Nothing
+       Set OfficeLocale = Nothing
+       Set FormatLocale = Nothing
+       Set SystemLocale = Nothing
        Set PrinterServer = Nothing
        Set CharacterClass = Nothing
        Set FileAccess = Nothing
diff --git a/wizards/source/scriptforge/SF_Utils.xba 
b/wizards/source/scriptforge/SF_Utils.xba
index c0d63bcc6b36..cbe07ce2b0ae 100644
--- a/wizards/source/scriptforge/SF_Utils.xba
+++ b/wizards/source/scriptforge/SF_Utils.xba
@@ -287,6 +287,23 @@ Const cstConfigUpdate      = 
&quot;com.sun.star.configuration.ConfigurationUpdateAcce
 
 End Function   &apos;  ScriptForge.SF_Utils._GetRegistryKeyContent
 
+REM 
-----------------------------------------------------------------------------
+Private Function _GetSetting(ByVal psPreference As String, psProperty As 
String) As Variant
+&apos;&apos;&apos;     Find in the configuration a specific setting based on 
its location in the
+&apos;&apos;&apos;     settings registry
+
+Dim oConfigProvider As Object          &apos;  
com.sun.star.configuration.ConfigurationProvider
+Dim vNodePath As Variant                       &apos;  Array of 
com.sun.star.beans.PropertyValue
+
+       &apos;  Derived from the Tools library
+       Set oConfigProvider = 
createUnoService(&quot;com.sun.star.configuration.ConfigurationProvider&quot;)
+       vNodePath = Array(SF_Utils._MakePropertyValue(&quot;nodepath&quot;, 
psPreference))
+
+       _GetSetting = oConfigProvider.createInstanceWithArguments( _
+                                       
&quot;com.sun.star.configuration.ConfigurationAccess&quot;, 
vNodePath()).getByName(psProperty)
+
+End Function   &apos;  ScriptForge.SF_Utils._GetSetting
+
 REM 
-----------------------------------------------------------------------------
 Public Function _GetUNOService(ByVal psService As String _
                                                                        , 
Optional ByVal pvArg As Variant _
@@ -298,9 +315,7 @@ Public Function _GetUNOService(ByVal psService As String _
 &apos;&apos;&apos;             pvArg: some services might require an argument
 
 Dim sLocale As String                  &apos;  fr-BE f.i.
-Dim oConfigProvider As Object
 Dim oDefaultContext As Object
-Dim vNodePath As Variant
 
        Set _GetUNOService = Nothing
        With _SF_
@@ -353,6 +368,16 @@ Dim vNodePath As Variant
                                        Set .FolderPicker = 
CreateUnoService(&quot;com.sun.star.ui.dialogs.FolderPicker&quot;)
                                End If
                                Set _GetUNOService = .FolderPicker
+                       Case &quot;FormatLocale&quot;
+                               If IsEmpty(.FormatLocale) Or 
IsNull(.FormatLocale) Then
+                                       .FormatLocale = 
CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
+                                       &apos;  1st and 2nd chance
+                                       sLocale = 
SF_Utils._GetSetting(&quot;org.openoffice.Setup/L10N&quot;, 
&quot;ooSetupSystemLocale&quot;)
+                                       If Len(sLocale) = 0 Then sLocale = 
SF_Utils._GetSetting(&quot;org.openoffice.System/L10N&quot;, 
&quot;UILocale&quot;)
+                                       .FormatLocale.Language = Split(sLocale, 
&quot;-&quot;)(0)       &apos;  Language is most often 2 chars long, but not 
always
+                                       .FormatLocale.Country = Right(sLocale, 
2)
+                               End If
+                               Set _GetUNOService = .FormatLocale
                        Case &quot;FunctionAccess&quot;
                                If IsEmpty(.FunctionAccess) Or 
IsNull(.FunctionAccess) Then
                                        Set .FunctionAccess = 
CreateUnoService(&quot;com.sun.star.sheet.FunctionAccess&quot;)
@@ -380,6 +405,16 @@ Dim vNodePath As Variant
                                        End If
                                End If
                                Set _GetUNOService = .MailService
+                       Case &quot;OfficeLocale&quot;
+                               If IsEmpty(.OfficeLocale) Or 
IsNull(.OfficeLocale) Then
+                                       .OfficeLocale = 
CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
+                                       &apos;  1st and 2nd chance
+                                       sLocale = 
SF_Utils._GetSetting(&quot;org.openoffice.Setup/L10N&quot;, 
&quot;ooLocale&quot;)
+                                       If Len(sLocale) = 0 Then sLocale = 
SF_Utils._GetSetting(&quot;org.openoffice.System/L10N&quot;, 
&quot;UILocale&quot;)
+                                       .OfficeLocale.Language = Split(sLocale, 
&quot;-&quot;)(0)       &apos;  Language is most often 2 chars long, but not 
always
+                                       .OfficeLocale.Country = Right(sLocale, 
2)
+                               End If
+                               Set _GetUNOService = .OfficeLocale
                        Case &quot;PathSettings&quot;
                                If IsEmpty(.PathSettings) Or 
IsNull(.PathSettings) Then
                                        Set .PathSettings = 
CreateUnoService(&quot;com.sun.star.util.PathSettings&quot;)
@@ -417,18 +452,13 @@ Dim vNodePath As Variant
                                End If
                                Set _GetUNOService = .SearchOptions
                        Case &quot;SystemLocale&quot;, &quot;Locale&quot;
-                               If IsEmpty(.Locale) Or IsNull(.Locale) Then
-                                       .Locale = 
CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
-                                       &apos;  Derived from the Tools library
-                                       Set oConfigProvider = 
createUnoService(&quot;com.sun.star.configuration.ConfigurationProvider&quot;)
-                                       vNodePath = Array()     :       ReDim 
vNodePath(0)
-                                       vNodePath(0) = New 
com.sun.star.beans.PropertyValue
-                                       vNodePath(0).Name = 
&quot;nodepath&quot;        :       vNodePath(0).Value = 
&quot;org.openoffice.System/L10N&quot;
-                                       sLocale = 
oConfigProvider.createInstanceWithArguments(&quot;com.sun.star.configuration.ConfigurationAccess&quot;,
 vNodePath()).getByName(&quot;SystemLocale&quot;)
-                                       .Locale.Language = Split(sLocale, 
&quot;-&quot;)(0)     &apos;  Language is most often 2 chars long, but not 
always
-                                       .Locale.Country = Right(sLocale, 2)
+                               If IsEmpty(.SystemLocale) Or 
IsNull(.SystemLocale) Then
+                                       .SystemLocale = 
CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
+                                       sLocale = 
SF_Utils._GetSetting(&quot;org.openoffice.System/L10N&quot;, 
&quot;SystemLocale&quot;)
+                                       .SystemLocale.Language = Split(sLocale, 
&quot;-&quot;)(0)       &apos;  Language is most often 2 chars long, but not 
always
+                                       .SystemLocale.Country = Right(sLocale, 
2)
                                End If
-                               Set _GetUNOService = .Locale
+                               Set _GetUNOService = .SystemLocale
                        Case &quot;SystemShellExecute&quot;
                                If IsEmpty(.SystemShellExecute) Or 
IsNull(.SystemShellExecute) Then
                                        Set .SystemShellExecute = 
CreateUnoService(&quot;com.sun.star.system.SystemShellExecute&quot;)
diff --git a/wizards/source/scriptforge/python/scriptforge.py 
b/wizards/source/scriptforge/python/scriptforge.py
index 858a3ec77a71..94d5a3de7d58 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -1218,9 +1218,10 @@ class SFScriptForge:
         servicename = 'ScriptForge.Platform'
         servicesynonyms = ('platform', 'scriptforge.platform')
         serviceproperties = dict(Architecture = False, ComputerName = False, 
CPUCount = False, CurrentUser = False,
-                                 Fonts = False, Locale = False, Machine = 
False, OfficeVersion = False, OSName = False,
-                                 OSPlatform = False, OSRelease = False, 
OSVersion = False, Printers = False,
-                                 Processor = False, PythonVersion = False)
+                                 Fonts = False, FormatLocale = False, Locale = 
False, Machine = False,
+                                 OfficeLocale = False, OfficeVersion = False, 
OSName = False, OSPlatform = False,
+                                 OSRelease = False, OSVersion = False, 
Printers = False, Processor = False,
+                                 PythonVersion = False, SystemLocale = False)
         # Python helper functions
         py = ScriptForge.pythonhelpermodule + '$' + '_SF_Platform'
 
commit 5d05abcc7cb53fd7f7d7ed700e3c65e9da3e5dea
Author:     Xisco Fauli <[email protected]>
AuthorDate: Tue Feb 1 10:56:23 2022 +0100
Commit:     Xisco Fauli <[email protected]>
CommitDate: Tue Feb 1 19:26:38 2022 +0100

    tdf#105998: sd_png_export_tests: Add unittest
    
    Change-Id: I4a32d815b085f10ab9be1b861bdfdeb128ec242e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129275
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/sd/qa/unit/PNGExportTests.cxx b/sd/qa/unit/PNGExportTests.cxx
index 0bc829ffaf78..cf75ac4172d7 100644
--- a/sd/qa/unit/PNGExportTests.cxx
+++ b/sd/qa/unit/PNGExportTests.cxx
@@ -47,6 +47,72 @@ void SdPNGExportTest::tearDown()
     test::BootstrapFixture::tearDown();
 }
 
+CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf105998)
+{
+    mxComponent
+        = 
loadFromDesktop(m_directories.getURLFromSrc(u"/sd/qa/unit/data/odp/tdf105998.odp"));
+    uno::Reference<uno::XComponentContext> xContext = getComponentContext();
+    CPPUNIT_ASSERT(xContext.is());
+    uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter
+        = drawing::GraphicExportFilter::create(xContext);
+
+    utl::TempFile aTempFile;
+    aTempFile.EnableKillingFile();
+
+    uno::Sequence<beans::PropertyValue> aDescriptor{
+        comphelper::makePropertyValue("URL", aTempFile.GetURL()),
+        comphelper::makePropertyValue("FilterName", OUString("PNG"))
+    };
+
+    uno::Reference<drawing::XDrawPagesSupplier> 
xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> 
xPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+                                             uno::UNO_QUERY);
+    uno::Reference<lang::XComponent> xShape(xPage->getByIndex(0), 
uno::UNO_QUERY);
+    xGraphicExporter->setSourceDocument(xShape);
+    xGraphicExporter->filter(aDescriptor);
+
+    SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ);
+    vcl::PngImageReader aPNGReader(aFileStream);
+    BitmapEx aBMPEx = aPNGReader.read();
+
+    // make sure only the shape is exported
+    Size aSize = aBMPEx.GetSizePixel();
+    CPPUNIT_ASSERT_EQUAL(Size(192, 192), aSize);
+
+    // Check all borders are red
+    Bitmap aBMP = aBMPEx.GetBitmap();
+    {
+        Bitmap::ScopedReadAccess pReadAccess(aBMP);
+        for (tools::Long nX = 1; nX < aSize.Width() - 1; ++nX)
+        {
+            const Color aColorTop = pReadAccess->GetColor(nX, 0);
+            const Color aColorBottom = pReadAccess->GetColor(nX, 
aSize.Height() - 1);
+
+            CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aColorTop);
+
+            // Without the fix in place, this test would have failed with
+            // - Expected: Color: R:255 G:0 B:0 A:0
+            // - Actual  : Color: R:9 G:9 B:9 A:0
+            CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aColorBottom);
+        }
+
+        for (tools::Long nY = 1; nY < aSize.Height() - 1; ++nY)
+        {
+            const Color aColorLeft = pReadAccess->GetColor(0, nY);
+            CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aColorLeft);
+
+#if !defined(MACOSX)
+            // FIXME: Jenkins fails on mac with
+            // - Expected: Color: R:255 G:0 B:0 A:0
+            // - Actual  : Color: R:255 G:2 B:2 A:0
+
+            const Color aColorRight = pReadAccess->GetColor(aSize.Width() - 1, 
nY);
+            CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aColorRight);
+#endif
+        }
+    }
+}
+
 CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf113163)
 {
     mxComponent
diff --git a/sd/qa/unit/data/odp/tdf105998.odp 
b/sd/qa/unit/data/odp/tdf105998.odp
new file mode 100644
index 000000000000..dca83afd14d5
Binary files /dev/null and b/sd/qa/unit/data/odp/tdf105998.odp differ

Reply via email to