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("Fonts") End Property ' ScriptForge.SF_Platform.Fonts (get) +REM ----------------------------------------------------------------------------- +Property Get FormatLocale() As String +''' Returns the locale used for number and date formats, combining language-COUNTRY (la-CO) +''' Example: +''' MsgBox platform.FormatLocale + FormatLocale = _PropertyGet("FormatLocale") +End Property ' ScriptForge.SF_Platform.FormatLocale (get) + REM ----------------------------------------------------------------------------- Property Get Locale() As String -''' Returns the locale combining language-COUNTRY (la-CO) +''' Returns the locale of the operating system, combining language-COUNTRY (la-CO) ''' Example: ''' MsgBox platform.Locale Locale = _PropertyGet("Locale") @@ -104,6 +112,14 @@ Property Get ObjectType As String ObjectType = "SF_Platform" End Property ' ScriptForge.SF_Platform.ObjectType +REM ----------------------------------------------------------------------------- +Property Get OfficeLocale() As String +''' Returns the locale of the user interface, combining language-COUNTRY (la-CO) +''' Example: +''' MsgBox platform.OfficeLocale + OfficeLocale = _PropertyGet("OfficeLocale") +End Property ' ScriptForge.SF_Platform.OfficeLocale (get) + REM ----------------------------------------------------------------------------- Property Get OfficeVersion() As String ''' Returns the office software version in the form 'LibreOffice w.x.y.z (The Document Foundation)' @@ -175,6 +191,14 @@ Property Get ServiceName As String ServiceName = "ScriptForge.Platform" End Property ' ScriptForge.SF_Platform.ServiceName +REM ----------------------------------------------------------------------------- +Property Get SystemLocale() As String +''' Returns the locale of the operating system, combining language-COUNTRY (la-CO) +''' Example: +''' MsgBox platform.SystemLocale + SystemLocale = _PropertyGet("SystemLocale") +End Property ' ScriptForge.SF_Platform.SystemLocale (get) + REM ===================================================================== METHODS REM ----------------------------------------------------------------------------- @@ -228,8 +252,10 @@ Public Function Properties() As Variant , "CPUCount" _ , "CurrentUser" _ , "Fonts" _ + , "FormatLocale" _ , "Locale" _ , "Machine" _ + , "OfficeLocale" _ , "OfficeVersion" _ , "OSName" _ , "OSPlatform" _ @@ -238,6 +264,7 @@ Public Function Properties() As Variant , "Printers" _ , "Processor" _ , "PythonVersion" _ + , "SystemLocale" _ ) End Function ' ScriptForge.SF_Platform.Properties @@ -350,8 +377,11 @@ Const cstSubArgs = "" 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("SystemLocale") + Case "FormatLocale" + Set oLocale = SF_Utils._GetUNOService("FormatLocale") + _PropertyGet = oLocale.Language & "-" & oLocale.Country + Case "OfficeLocale" + Set oLocale = SF_Utils._GetUNOService("OfficeLocale") _PropertyGet = oLocale.Language & "-" & oLocale.Country Case "OfficeVersion" _PropertyGet = _GetProductName() @@ -371,6 +401,9 @@ Const cstSubArgs = "" _PropertyGet = sOSName Case "Printers" _PropertyGet = _GetPrinters() + Case "SystemLocale", "Locale" + Set oLocale = SF_Utils._GetUNOService("SystemLocale") + _PropertyGet = oLocale.Language & "-" & 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 ' com.sun.star.reflection.CoreReflection Private DispatchHelper As Object ' com.sun.star.frame.DispatchHelper Private TextSearch As Object ' com.sun.star.util.TextSearch Private SearchOptions As Object ' com.sun.star.util.SearchOptions -Private Locale As Object ' com.sun.star.lang.Locale +Private SystemLocale As Object ' com.sun.star.lang.Locale +Private OfficeLocale As Object ' com.sun.star.lang.Locale +Private FormatLocale As Object ' com.sun.star.lang.Locale Private PrinterServer As Object ' com.sun.star.awt.PrinterServer Private CharacterClass As Object ' com.sun.star.i18n.CharacterClassification Private FileAccess As Object ' 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 = "com.sun.star.configuration.ConfigurationUpdateAcce End Function ' ScriptForge.SF_Utils._GetRegistryKeyContent +REM ----------------------------------------------------------------------------- +Private Function _GetSetting(ByVal psPreference As String, psProperty As String) As Variant +''' Find in the configuration a specific setting based on its location in the +''' settings registry + +Dim oConfigProvider As Object ' com.sun.star.configuration.ConfigurationProvider +Dim vNodePath As Variant ' Array of com.sun.star.beans.PropertyValue + + ' Derived from the Tools library + Set oConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider") + vNodePath = Array(SF_Utils._MakePropertyValue("nodepath", psPreference)) + + _GetSetting = oConfigProvider.createInstanceWithArguments( _ + "com.sun.star.configuration.ConfigurationAccess", vNodePath()).getByName(psProperty) + +End Function ' 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 _ ''' pvArg: some services might require an argument Dim sLocale As String ' 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("com.sun.star.ui.dialogs.FolderPicker") End If Set _GetUNOService = .FolderPicker + Case "FormatLocale" + If IsEmpty(.FormatLocale) Or IsNull(.FormatLocale) Then + .FormatLocale = CreateUnoStruct("com.sun.star.lang.Locale") + ' 1st and 2nd chance + sLocale = SF_Utils._GetSetting("org.openoffice.Setup/L10N", "ooSetupSystemLocale") + If Len(sLocale) = 0 Then sLocale = SF_Utils._GetSetting("org.openoffice.System/L10N", "UILocale") + .FormatLocale.Language = Split(sLocale, "-")(0) ' Language is most often 2 chars long, but not always + .FormatLocale.Country = Right(sLocale, 2) + End If + Set _GetUNOService = .FormatLocale Case "FunctionAccess" If IsEmpty(.FunctionAccess) Or IsNull(.FunctionAccess) Then Set .FunctionAccess = CreateUnoService("com.sun.star.sheet.FunctionAccess") @@ -380,6 +405,16 @@ Dim vNodePath As Variant End If End If Set _GetUNOService = .MailService + Case "OfficeLocale" + If IsEmpty(.OfficeLocale) Or IsNull(.OfficeLocale) Then + .OfficeLocale = CreateUnoStruct("com.sun.star.lang.Locale") + ' 1st and 2nd chance + sLocale = SF_Utils._GetSetting("org.openoffice.Setup/L10N", "ooLocale") + If Len(sLocale) = 0 Then sLocale = SF_Utils._GetSetting("org.openoffice.System/L10N", "UILocale") + .OfficeLocale.Language = Split(sLocale, "-")(0) ' Language is most often 2 chars long, but not always + .OfficeLocale.Country = Right(sLocale, 2) + End If + Set _GetUNOService = .OfficeLocale Case "PathSettings" If IsEmpty(.PathSettings) Or IsNull(.PathSettings) Then Set .PathSettings = CreateUnoService("com.sun.star.util.PathSettings") @@ -417,18 +452,13 @@ Dim vNodePath As Variant End If Set _GetUNOService = .SearchOptions Case "SystemLocale", "Locale" - If IsEmpty(.Locale) Or IsNull(.Locale) Then - .Locale = CreateUnoStruct("com.sun.star.lang.Locale") - ' Derived from the Tools library - Set oConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider") - vNodePath = Array() : ReDim vNodePath(0) - vNodePath(0) = New com.sun.star.beans.PropertyValue - vNodePath(0).Name = "nodepath" : vNodePath(0).Value = "org.openoffice.System/L10N" - sLocale = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", vNodePath()).getByName("SystemLocale") - .Locale.Language = Split(sLocale, "-")(0) ' Language is most often 2 chars long, but not always - .Locale.Country = Right(sLocale, 2) + If IsEmpty(.SystemLocale) Or IsNull(.SystemLocale) Then + .SystemLocale = CreateUnoStruct("com.sun.star.lang.Locale") + sLocale = SF_Utils._GetSetting("org.openoffice.System/L10N", "SystemLocale") + .SystemLocale.Language = Split(sLocale, "-")(0) ' Language is most often 2 chars long, but not always + .SystemLocale.Country = Right(sLocale, 2) End If - Set _GetUNOService = .Locale + Set _GetUNOService = .SystemLocale Case "SystemShellExecute" If IsEmpty(.SystemShellExecute) Or IsNull(.SystemShellExecute) Then Set .SystemShellExecute = CreateUnoService("com.sun.star.system.SystemShellExecute") 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
