cui/source/options/optlanguagetool.cxx |   35 ++++++++++++++++++++-------------
 svgio/inc/SvgNumber.hxx                |    4 +--
 svgio/inc/svgnode.hxx                  |    4 ---
 svgio/qa/cppunit/SvgImportTest.cxx     |   14 ++++++++++++-
 svgio/qa/cppunit/SvgNumberTest.cxx     |    2 -
 svgio/source/svgreader/SvgNumber.cxx   |    2 -
 svgio/source/svgreader/svgnode.cxx     |   21 +++----------------
 7 files changed, 44 insertions(+), 38 deletions(-)

New commits:
commit dd7a4b519e5dcc6943f0c49c1e04b88a2c282969
Author:     Leonid Ryzhov <leoryz...@gmail.com>
AuthorDate: Wed Mar 20 23:21:18 2024 +0300
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Mon Apr 22 08:28:28 2024 +0200

    tdf#159395-LanguageTool use correct default URL when username/APIkey set
    
    Change-Id: I31e1c2f1dfd96d87f60b6be1e5abce4837827a76
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165079
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit 155a6af93a8ac90cab15968f5dd499ab77ad9f72)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166097
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/cui/source/options/optlanguagetool.cxx 
b/cui/source/options/optlanguagetool.cxx
index 8c56a40e728f..3979b42c0521 100644
--- a/cui/source/options/optlanguagetool.cxx
+++ b/cui/source/options/optlanguagetool.cxx
@@ -25,6 +25,7 @@
 
 using LanguageToolCfg = 
officecfg::Office::Linguistic::GrammarChecking::LanguageTool;
 constexpr OUString LANGUAGETOOL_DEFAULT_URL = 
u"https://api.languagetool.org/v2"_ustr;
+constexpr OUString LANGUAGETOOLPLUS_DEFAULT_URL = 
u"https://api.languagetoolplus.com/v2"_ustr;
 
 OptLanguageToolTabPage::OptLanguageToolTabPage(weld::Container* pPage,
                                                weld::DialogController* 
pController,
@@ -81,20 +82,21 @@ IMPL_LINK_NOARG(OptLanguageToolTabPage, CheckHdl, 
weld::Toggleable&, void)
 void OptLanguageToolTabPage::Reset(const SfxItemSet*)
 {
     // tdf#150494 If no URL has been set, use the default URL
-    OUString aBaseURL = LanguageToolCfg::BaseURL::get().value_or("");
-    if (aBaseURL.isEmpty())
-        m_xBaseURLED->set_text(LANGUAGETOOL_DEFAULT_URL);
-    else
-        m_xBaseURLED->set_text(aBaseURL);
+    OUString aUsername = LanguageToolCfg::Username::get().value_or("");
+    OUString aApiKey = LanguageToolCfg::ApiKey::get().value_or("");
+    OUString aBaseURL = LanguageToolCfg::BaseURL::get().value_or(
+        (aUsername.isEmpty() && aApiKey.isEmpty()) ? LANGUAGETOOL_DEFAULT_URL
+                                                   : 
LANGUAGETOOLPLUS_DEFAULT_URL);
 
+    m_xBaseURLED->set_text(aBaseURL);
     m_xBaseURLED->set_sensitive(!LanguageToolCfg::BaseURL::isReadOnly());
     m_xBaseURLImg->set_visible(LanguageToolCfg::BaseURL::isReadOnly());
 
-    m_xUsernameED->set_text(LanguageToolCfg::Username::get().value_or(""));
+    m_xUsernameED->set_text(aUsername);
     m_xUsernameED->set_sensitive(!LanguageToolCfg::Username::isReadOnly());
     m_xUsernameImg->set_visible(LanguageToolCfg::Username::isReadOnly());
 
-    m_xApiKeyED->set_text(LanguageToolCfg::ApiKey::get().value_or(""));
+    m_xApiKeyED->set_text(aApiKey);
     m_xApiKeyED->set_sensitive(!LanguageToolCfg::ApiKey::isReadOnly());
     m_xApiKeyImg->set_visible(LanguageToolCfg::ApiKey::isReadOnly());
 
@@ -139,14 +141,21 @@ bool OptLanguageToolTabPage::FillItemSet(SfxItemSet*)
     auto batch(comphelper::ConfigurationChanges::create());
 
     // tdf#150494 If no URL has been set, then save the default URL
+    // tdf#159395 If Username and ApiKey are set, then save the default URL 
for paid service
     OUString aBaseURL = m_xBaseURLED->get_text();
-    if (aBaseURL.isEmpty())
-        LanguageToolCfg::BaseURL::set(LANGUAGETOOL_DEFAULT_URL, batch);
-    else
-        LanguageToolCfg::BaseURL::set(aBaseURL, batch);
+    OUString aUsername = m_xUsernameED->get_text();
+    OUString aApiKey = m_xApiKeyED->get_text();
 
-    LanguageToolCfg::Username::set(m_xUsernameED->get_text(), batch);
-    LanguageToolCfg::ApiKey::set(m_xApiKeyED->get_text(), batch);
+    if (aBaseURL.isEmpty()
+        || (aUsername.isEmpty() && aApiKey.isEmpty() && aBaseURL == 
LANGUAGETOOLPLUS_DEFAULT_URL))
+        aBaseURL = LANGUAGETOOL_DEFAULT_URL;
+
+    if (!aUsername.isEmpty() && !aApiKey.isEmpty() && aBaseURL == 
LANGUAGETOOL_DEFAULT_URL)
+        aBaseURL = LANGUAGETOOLPLUS_DEFAULT_URL;
+
+    LanguageToolCfg::BaseURL::set(aBaseURL, batch);
+    LanguageToolCfg::Username::set(aUsername, batch);
+    LanguageToolCfg::ApiKey::set(aApiKey, batch);
     LanguageToolCfg::RestProtocol::set(m_xRestProtocol->get_text(), batch);
     
LanguageToolCfg::SSLCertVerify::set(!m_xSSLDisableVerificationBox->get_active(),
 batch);
     batch->commit();
commit 6cb6c3f5ffaa2f769e47a30afbdcf844ab291885
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Apr 9 16:04:40 2024 +0500
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Mon Apr 22 08:28:28 2024 +0200

    tdf#160717: fix ex handling
    
    Same as in commit e27572686130df43d1d65c574b0c34f39fc0d1a9
    (tdf#160593: make sure to use current element's font size for em unit,
    2024-04-18) for em.
    
    Change-Id: Id9003c0426a6b373456da1aa1550f7ff07f766a3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166235
    Tested-by: Mike Kaganski <mike.kagan...@collabora.com>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit edef46e82e7e54a27004f9ee6e99108390736d12)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166216
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/svgio/inc/SvgNumber.hxx b/svgio/inc/SvgNumber.hxx
index fe4ab8e2683e..c62576c2b082 100644
--- a/svgio/inc/SvgNumber.hxx
+++ b/svgio/inc/SvgNumber.hxx
@@ -39,8 +39,8 @@ public:
     virtual basegfx::B2DRange getCurrentViewPort() const = 0;
     /// return font size of node, either set here or inherited from parents
     virtual double getCurrentFontSize() const = 0;
-    /// return xheight of node inherited from parents
-    virtual double getCurrentXHeightInherited() const = 0;
+    /// return xheight of node, either set here or inherited from parents
+    virtual double getCurrentXHeight() const = 0;
 };
 
 enum class SvgUnit
diff --git a/svgio/inc/svgnode.hxx b/svgio/inc/svgnode.hxx
index 98a444cba5fc..5231635d6261 100644
--- a/svgio/inc/svgnode.hxx
+++ b/svgio/inc/svgnode.hxx
@@ -164,9 +164,7 @@ namespace svgio::svgreader
             /// InfoProvider support for %, em and ex values
             virtual basegfx::B2DRange getCurrentViewPort() const override;
             virtual double getCurrentFontSize() const override;
-            virtual double getCurrentXHeightInherited() const override;
-
-            double getCurrentXHeight() const;
+            virtual double getCurrentXHeight() const override;
 
             /// Id access
             std::optional<OUString> const & getId() const { return mpId; }
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx 
b/svgio/qa/cppunit/SvgImportTest.cxx
index cfc83d425bb7..bfd5f8c1dfce 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -2103,11 +2103,12 @@ CPPUNIT_TEST_FIXTURE(Test, testDyInEms)
 
 CPPUNIT_TEST_FIXTURE(Test, testExs)
 {
-    // tdf#160594 given an SVG file with <tspan dy="3ex" 
style="font-size:1ex">:
+    // tdf#160594, tdf#160717 given an SVG file with <tspan dy="3ex" 
style="font-size:1ex">:
     xmlDocUniquePtr pDocument = 
dumpAndParseSvg(u"/svgio/qa/cppunit/data/dy_in_exs.svg");
 
     assertXPath(pDocument, "//textsimpleportion"_ostr, 2);
     assertXPath(pDocument, "//textsimpleportion[1]"_ostr, "height"_ostr, 
u"16"_ustr);
+    assertXPath(pDocument, "//textsimpleportion[1]"_ostr, "y"_ostr, 
u"20"_ustr);
 
     sal_Int32 nSize = getXPath(pDocument, "//textsimpleportion[2]"_ostr, 
"height"_ostr).toInt32();
     // Without the accompanying fix in place, this test would have failed with:
@@ -2115,6 +2116,17 @@ CPPUNIT_TEST_FIXTURE(Test, testExs)
     // - Actual  : 16
     // i.e. the parent font-size was used, instead of its x-size.
     CPPUNIT_ASSERT_LESS(sal_Int32(16), nSize);
+
+    sal_Int32 nYPos = getXPath(pDocument, "//textsimpleportion[2]"_ostr, 
"y"_ostr).toInt32();
+    // Then make sure that the vertical offset is based on x-size of tspan, 
not of its parent.
+    // Given the tspan's font-size is nSize, its x-size is less than nSize, 
and the expected
+    // vertical offset is less than 3 * nSize, which means that the resulting 
y is expected
+    // to be strictly less than 20 + 3 * nSize.
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected less than: 44
+    // - Actual  : 44
+    // i.e. the parent x-size (or current font-size) was used, instead of 
current x-size.
+    CPPUNIT_ASSERT_LESS(sal_Int32(20 + 3 * nSize), nYPos);
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/svgio/qa/cppunit/SvgNumberTest.cxx 
b/svgio/qa/cppunit/SvgNumberTest.cxx
index 9b12e52bf956..49e1394bcef2 100644
--- a/svgio/qa/cppunit/SvgNumberTest.cxx
+++ b/svgio/qa/cppunit/SvgNumberTest.cxx
@@ -40,7 +40,7 @@ public:
 
     double getCurrentFontSize() const override { return 12.0; }
 
-    double getCurrentXHeightInherited() const override { return 5.0; }
+    double getCurrentXHeight() const override { return 5.0; }
 };
 
 void TestNumber::testSetting()
diff --git a/svgio/source/svgreader/SvgNumber.cxx 
b/svgio/source/svgreader/SvgNumber.cxx
index 4a48ffbfb4e9..72a44dbdd032 100644
--- a/svgio/source/svgreader/SvgNumber.cxx
+++ b/svgio/source/svgreader/SvgNumber.cxx
@@ -39,7 +39,7 @@ double SvgNumber::solveNonPercentage(const InfoProvider& 
rInfoProvider) const
         case SvgUnit::em:
             return mfNumber * rInfoProvider.getCurrentFontSize();
         case SvgUnit::ex:
-            return mfNumber * rInfoProvider.getCurrentXHeightInherited() * 0.5;
+            return mfNumber * rInfoProvider.getCurrentXHeight();
         case SvgUnit::px:
             return mfNumber;
         case SvgUnit::pt:
diff --git a/svgio/source/svgreader/svgnode.cxx 
b/svgio/source/svgreader/svgnode.cxx
index b881830a77a3..8fdc29eab72f 100644
--- a/svgio/source/svgreader/svgnode.cxx
+++ b/svgio/source/svgreader/svgnode.cxx
@@ -702,25 +702,12 @@ namespace {
             return 0.0;
         }
 
-        double SvgNode::getCurrentXHeightInherited() const
-        {
-            if(getParent())
-            {
-                return getParent()->getCurrentXHeight();
-            }
-            else
-            {
-                return 0.0;
-            }
-        }
-
         double SvgNode::getCurrentXHeight() const
         {
-            if(getSvgStyleAttributes())
-                // for XHeight, use FontSize currently
-                return 
getSvgStyleAttributes()->getFontSizeNumber().solve(*this, 
NumberType::ycoordinate);
-
-            return getCurrentXHeightInherited();
+            // https://drafts.csswg.org/css-values-4/#ex
+            // for XHeight, use 0.5em fallback currently
+            // FIXME: use "x-height of the first available font"
+            return getCurrentFontSize() * 0.5;
         }
 
         void SvgNode::setId(OUString const & rId)

Reply via email to