sw/inc/unostyle.hxx                                  |    2 
 sw/inc/unoxstyle.hxx                                 |    6 +
 sw/source/core/unocore/unostyle.cxx                  |   62 +++++++++++++++++++
 sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx |   49 +++++++--------
 4 files changed, 96 insertions(+), 23 deletions(-)

New commits:
commit 4a42fe00169c3a7d46db2e1a09d4b58b56dfccba
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Aug 13 11:51:08 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Aug 14 10:52:00 2024 +0200

    tdf#158556 bypass some logic for toggle properties
    
    hardcode a direct route through most of the logic in SwXStyle.
    Shaves 20% off the load time.
    
    Change-Id: I52ae8b4e870e07893195ce2eaedcf9069dbcae8a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171815
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/unostyle.hxx b/sw/inc/unostyle.hxx
index a1e232939aa9..0ae5a914cda2 100644
--- a/sw/inc/unostyle.hxx
+++ b/sw/inc/unostyle.hxx
@@ -454,6 +454,8 @@ public:
 
     rtl::Reference<SwXBaseStyle> getStyleByName(const OUString& rName);
     rtl::Reference<SwXPageStyle> getPageStyleByName(const OUString& rName);
+    rtl::Reference<SwXStyle> getCharacterStyleByName(const OUString& rName);
+    rtl::Reference<SwXStyle> getParagraphStyleByName(const OUString& rName);
     void insertStyleByName(const OUString& Name, const 
rtl::Reference<SwXStyle>& Element);
 private:
     void insertStyleByNameImpl(const rtl::Reference<SwXStyle>& Element, const 
OUString& sStyleName);
diff --git a/sw/inc/unoxstyle.hxx b/sw/inc/unoxstyle.hxx
index a51305651741..6ccade4592ad 100644
--- a/sw/inc/unoxstyle.hxx
+++ b/sw/inc/unoxstyle.hxx
@@ -21,6 +21,7 @@
 #include <rtl/ref.hxx>
 #include <svl/listener.hxx>
 #include <svl/style.hxx>
+#include <com/sun/star/awt/FontSlant.hpp>
 #include <com/sun/star/style/XStyle.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/beans/XPropertyState.hpp>
@@ -196,6 +197,11 @@ public:
     void PutItemToSet(const SvxSetItem* pSetItem, const SfxItemPropertySet& 
rPropSet,
                       const SfxItemPropertyMapEntry& rEntry, const 
css::uno::Any& rVal,
                       SwStyleBase_Impl& rBaseImpl);
+    SW_DLLPUBLIC void getToggleAttributes(
+        float& rfCharStyleBold, float& rfCharStyleBoldComplex,
+        css::awt::FontSlant& reCharStylePosture, css::awt::FontSlant& 
reCharStylePostureComplex,
+        sal_Int16& rnCharStyleCaseMap, sal_Int16& rnCharStyleRelief, bool& 
rbCharStyleContoured,
+        bool& rbCharStyleShadowed, sal_Int16& rnCharStyleStrikeThrough, bool& 
rbCharStyleHidden);
 };
 
 typedef cppu::ImplInheritanceHelper<SwXStyle, css::document::XEventsSupplier> 
SwXFrameStyle_Base;
diff --git a/sw/source/core/unocore/unostyle.cxx 
b/sw/source/core/unocore/unostyle.cxx
index 9be86396be79..9e968849a85d 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -933,6 +933,22 @@ rtl::Reference<SwXPageStyle> 
SwXStyleFamily::getPageStyleByName(const OUString&
     return xPageStyle;
 }
 
+rtl::Reference<SwXStyle> SwXStyleFamily::getCharacterStyleByName(const 
OUString& rName)
+{
+    rtl::Reference<SwXBaseStyle> xStyle = getStyleByName(rName);
+    rtl::Reference<SwXStyle> xCharStyle = 
dynamic_cast<SwXStyle*>(xStyle.get());
+    assert(bool(xStyle) == bool(xCharStyle));
+    return xCharStyle;
+}
+
+rtl::Reference<SwXStyle> SwXStyleFamily::getParagraphStyleByName(const 
OUString& rName)
+{
+    rtl::Reference<SwXBaseStyle> xStyle = getStyleByName(rName);
+    rtl::Reference<SwXStyle> xCharStyle = 
dynamic_cast<SwXStyle*>(xStyle.get());
+    assert(bool(xStyle) == bool(xCharStyle));
+    return xCharStyle;
+}
+
 rtl::Reference<SwXBaseStyle> SwXStyleFamily::getStyleByName(const OUString& 
rName)
 {
     SolarMutexGuard aGuard;
@@ -2384,6 +2400,52 @@ uno::Any SwXStyle::getPropertyValue(const OUString& 
rPropertyName)
     return GetPropertyValue_Impl(pPropSet, aBase, rPropertyName);
 }
 
+void SwXStyle::getToggleAttributes(
+            float& rfCharStyleBold,
+            float& rfCharStyleBoldComplex,
+            css::awt::FontSlant& reCharStylePosture,
+            css::awt::FontSlant& reCharStylePostureComplex,
+            sal_Int16& rnCharStyleCaseMap,
+            sal_Int16& rnCharStyleRelief,
+            bool& rbCharStyleContoured,
+            bool& rbCharStyleShadowed,
+            sal_Int16& rnCharStyleStrikeThrough,
+            bool& rbCharStyleHidden)
+{
+    SolarMutexGuard aGuard;
+    assert(m_pDoc);
+    assert(m_pBasePool || m_bIsDescriptor);
+    sal_uInt16 nPropSetId = m_bIsConditional ? 
PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType();
+    const SfxItemPropertySet* pPropSet = 
aSwMapProvider.GetPropertySet(nPropSetId);
+    SwStyleBase_Impl aBase(*m_pDoc, m_sStyleName, 
&m_pDoc->GetDfltTextFormatColl()->GetAttrSet()); // add pDfltTextFormatColl as 
parent
+    const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
+    assert(m_pBasePool);
+    PrepareStyleBase(aBase);
+    SfxItemSet& rSet = aBase.GetItemSet();
+
+    uno::Any aResult;
+    SfxItemPropertySet::getPropertyValue(*rMap.getByName(u"CharWeight"_ustr), 
rSet, aResult);
+    aResult >>= rfCharStyleBold;
+    
SfxItemPropertySet::getPropertyValue(*rMap.getByName(u"CharWeightComplex"_ustr),
 rSet, aResult);
+    aResult >>= rfCharStyleBoldComplex;
+    SfxItemPropertySet::getPropertyValue(*rMap.getByName(u"CharPosture"_ustr), 
rSet, aResult);
+    aResult >>= reCharStylePosture;
+    
SfxItemPropertySet::getPropertyValue(*rMap.getByName(u"CharPostureComplex"_ustr),
 rSet, aResult);
+    aResult >>= reCharStylePostureComplex;
+    SfxItemPropertySet::getPropertyValue(*rMap.getByName(u"CharCaseMap"_ustr), 
rSet, aResult);
+    aResult >>= rnCharStyleCaseMap;
+    SfxItemPropertySet::getPropertyValue(*rMap.getByName(u"CharRelief"_ustr), 
rSet, aResult);
+    aResult >>= rnCharStyleRelief;
+    
SfxItemPropertySet::getPropertyValue(*rMap.getByName(u"CharContoured"_ustr), 
rSet, aResult);
+    aResult >>= rbCharStyleContoured;
+    
SfxItemPropertySet::getPropertyValue(*rMap.getByName(u"CharShadowed"_ustr), 
rSet, aResult);
+    aResult >>= rbCharStyleShadowed;
+    
SfxItemPropertySet::getPropertyValue(*rMap.getByName(u"CharStrikeout"_ustr), 
rSet, aResult);
+    aResult >>= rnCharStyleStrikeThrough;
+    SfxItemPropertySet::getPropertyValue(*rMap.getByName(u"CharHidden"_ustr), 
rSet, aResult);
+    aResult >>= rbCharStyleHidden;
+}
+
 uno::Sequence<uno::Any> SwXStyle::getPropertyValues(const 
uno::Sequence<OUString>& rPropertyNames)
 {
     SolarMutexGuard aGuard;
diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
index 2895c4cdd167..8f871c2a19df 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
@@ -3096,23 +3096,25 @@ void DomainMapper_Impl::applyToggleAttributes(const 
PropertyMapPtr& pPropertyMap
         sal_Int16 nCharStyleStrikeThrough = awt::FontStrikeout::NONE;
         bool bCharStyleHidden = false;
 
-        rtl::Reference<SwXBaseStyle> xCharStylePropertySet = 
GetCharacterStyles()->getStyleByName(sCharStyleName);
-        
xCharStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_WEIGHT)) >>= 
fCharStyleBold;
-        
xCharStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_WEIGHT_COMPLEX))
 >>= fCharStyleBoldComplex;
-        
xCharStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_POSTURE)) >>= 
eCharStylePosture;
-        
xCharStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_POSTURE_COMPLEX))
 >>= eCharStylePostureComplex;
-        
xCharStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_CASE_MAP)) 
>>= nCharStyleCaseMap;
-        
xCharStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_RELIEF)) >>= 
nCharStyleRelief;
-        
xCharStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_CONTOURED)) 
>>= bCharStyleContoured;
-        
xCharStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_SHADOWED)) 
>>= bCharStyleShadowed;
-        
xCharStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_STRIKEOUT)) 
>>= nCharStyleStrikeThrough;
-        
xCharStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_HIDDEN)) >>= 
bCharStyleHidden;
+        rtl::Reference<SwXStyle> xCharStylePropertySet = 
GetCharacterStyles()->getCharacterStyleByName(sCharStyleName);
+        xCharStylePropertySet->getToggleAttributes(
+                fCharStyleBold,
+                fCharStyleBoldComplex,
+                eCharStylePosture,
+                eCharStylePostureComplex,
+                nCharStyleCaseMap,
+                nCharStyleRelief,
+                bCharStyleContoured,
+                bCharStyleShadowed,
+                nCharStyleStrikeThrough,
+                bCharStyleHidden);
+
         if (fCharStyleBold > css::awt::FontWeight::NORMAL || eCharStylePosture 
!= css::awt::FontSlant_NONE|| nCharStyleCaseMap != css::style::CaseMap::NONE ||
             nCharStyleRelief != css::awt::FontRelief::NONE || 
bCharStyleContoured || bCharStyleShadowed ||
             nCharStyleStrikeThrough == awt::FontStrikeout::SINGLE || 
bCharStyleHidden)
         {
-            rtl::Reference<SwXBaseStyle> const xParaStylePropertySet =
-                
GetParagraphStyles()->getStyleByName(m_StreamStateStack.top().sCurrentParaStyleName);
+            rtl::Reference<SwXStyle> const xParaStylePropertySet =
+                
GetParagraphStyles()->getParagraphStyleByName(m_StreamStateStack.top().sCurrentParaStyleName);
             float fParaStyleBold = css::awt::FontWeight::NORMAL;
             float fParaStyleBoldComplex = css::awt::FontWeight::NORMAL;
             css::awt::FontSlant eParaStylePosture = css::awt::FontSlant_NONE;
@@ -3123,16 +3125,17 @@ void DomainMapper_Impl::applyToggleAttributes(const 
PropertyMapPtr& pPropertyMap
             bool bParaStyleShadowed = false;
             sal_Int16 nParaStyleStrikeThrough = awt::FontStrikeout::NONE;
             bool bParaStyleHidden = false;
-            
xParaStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_WEIGHT)) >>= 
fParaStyleBold;
-            
xParaStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_WEIGHT_COMPLEX))
 >>= fParaStyleBoldComplex;
-            
xParaStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_POSTURE)) >>= 
eParaStylePosture;
-            
xParaStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_POSTURE_COMPLEX))
 >>= eParaStylePostureComplex;
-            
xParaStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_CASE_MAP)) 
>>= nParaStyleCaseMap;
-            
xParaStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_RELIEF)) >>= 
nParaStyleRelief;
-            
xParaStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_SHADOWED)) 
>>= bParaStyleShadowed;
-            
xParaStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_CONTOURED)) 
>>= bParaStyleContoured;
-            
xParaStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_STRIKEOUT)) 
>>= nParaStyleStrikeThrough;
-            
xParaStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_HIDDEN)) >>= 
bParaStyleHidden;
+            xParaStylePropertySet->getToggleAttributes(
+                    fParaStyleBold,
+                    fParaStyleBoldComplex,
+                    eParaStylePosture,
+                    eParaStylePostureComplex,
+                    nParaStyleCaseMap,
+                    nParaStyleRelief,
+                    bParaStyleContoured,
+                    bParaStyleShadowed,
+                    nParaStyleStrikeThrough,
+                    bParaStyleHidden);
             if (fCharStyleBold > css::awt::FontWeight::NORMAL && 
fParaStyleBold > css::awt::FontWeight::NORMAL)
             {
                 std::optional<PropertyMap::Property> charBoldProperty = 
pPropertyMap->getProperty(PROP_CHAR_WEIGHT);

Reply via email to