chart2/source/view/main/PropertyMapper.cxx              |    3 
 chart2/source/view/main/ShapeFactory.cxx                |   72 ++++++++++------
 oox/inc/drawingml/textcharacterproperties.hxx           |    8 +
 oox/source/drawingml/chart/titleconverter.cxx           |   11 ++
 oox/source/drawingml/textcharacterpropertiescontext.cxx |    3 
 5 files changed, 71 insertions(+), 26 deletions(-)

New commits:
commit f31a8ff9ea15ad81aeac265fce6eafe6342a68b7
Author:     Balazs Varga <balazs.varga.ext...@allotropia.de>
AuthorDate: Thu Mar 28 17:17:47 2024 +0100
Commit:     Balazs Varga <balazs.varga.ext...@allotropia.de>
CommitDate: Tue Apr 2 23:26:13 2024 +0200

    tdf#78027 - Fix Chart OOXML Import with non-uniform formatted titles
    
    Character formats are disappeared from Chart Title textobjects if they were
    formatted non-uniform. In this patch only the OOXML import and the chartview
    part will be fixed which make it visible after the import.
    
    (Note: next patch will contain the chart controller part where the 
characters
    can be formatted during title editing).
    
    Change-Id: I4fb5c3d80b7889935d198e70fb49e2c68108b235
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165500
    Tested-by: Jenkins
    Tested-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
    Reviewed-by: Balazs Varga <balazs.varga.ext...@allotropia.de>

diff --git a/chart2/source/view/main/PropertyMapper.cxx 
b/chart2/source/view/main/PropertyMapper.cxx
index c3241049057a..79206624f436 100644
--- a/chart2/source/view/main/PropertyMapper.cxx
+++ b/chart2/source/view/main/PropertyMapper.cxx
@@ -268,7 +268,8 @@ const tPropertyNameMap& 
PropertyMapper::getPropertyNameMapForCharacterProperties
         {"CharColor",                "CharColor"},
         {"CharContoured",            "CharContoured"},
         {"CharEmphasis",             "CharEmphasis"},//the service 
style::CharacterProperties  describes a property called 'CharEmphasize' which 
is nowhere implemented
-
+        {"CharEscapement",           "CharEscapement"},
+        {"CharEscapementHeight",     "CharEscapementHeight"},
         {"CharFontFamily",           "CharFontFamily"},
         {"CharFontFamilyAsian",      "CharFontFamilyAsian"},
         {"CharFontFamilyComplex",    "CharFontFamilyComplex"},
diff --git a/chart2/source/view/main/ShapeFactory.cxx 
b/chart2/source/view/main/ShapeFactory.cxx
index 0e572a7e8dcb..c681c581a7b3 100644
--- a/chart2/source/view/main/ShapeFactory.cxx
+++ b/chart2/source/view/main/ShapeFactory.cxx
@@ -2183,7 +2183,8 @@ rtl::Reference<SvxShapeText>
 
         //set text and text properties
         uno::Reference< text::XTextCursor > xTextCursor( 
xShape->createTextCursor() );
-        if( !xTextCursor.is() )
+        uno::Reference< text::XTextCursor > xSelectionCursor( 
xShape->createTextCursor() );
+        if( !xTextCursor.is() || !xSelectionCursor.is() )
             return xShape;
 
         tPropertyNameValueMap aValueMap;
@@ -2232,18 +2233,32 @@ rtl::Reference<SvxShapeText>
             //if the characters should be stacked we use only the first 
character properties for code simplicity
             if( xFormattedString.hasElements() )
             {
-                OUString aLabel;
-                for (const auto& i : xFormattedString)
-                    aLabel += i->getString();
-                aLabel = ShapeFactory::getStackedString( aLabel, 
bStackCharacters );
-
-                xTextCursor->gotoEnd(false);
-                xShape->insertString( xTextCursor, aLabel, false );
-                xTextCursor->gotoEnd(true);
-                uno::Reference< beans::XPropertySet > xSourceProps( 
xFormattedString[0], uno::UNO_QUERY );
-
-                PropertyMapper::setMappedProperties( *xShape, xSourceProps
-                        , 
PropertyMapper::getPropertyNameMapForCharacterProperties() );
+                size_t nLBreaks = xFormattedString.size() - 1;
+                uno::Reference< beans::XPropertySet > 
xSelectionProp(xSelectionCursor, uno::UNO_QUERY);
+                for (const uno::Reference<chart2::XFormattedString>& rxFS : 
xFormattedString)
+                {
+                    if (!rxFS->getString().isEmpty())
+                    {
+                        xTextCursor->gotoEnd(false);
+                        xSelectionCursor->gotoEnd(false);
+                        OUString aLabel = 
ShapeFactory::getStackedString(rxFS->getString(), bStackCharacters);
+                        if (nLBreaks-- > 0)
+                            aLabel += OUStringChar(' ');
+                        xShape->insertString(xTextCursor, aLabel, false);
+                        xSelectionCursor->gotoEnd(true); // select current 
paragraph
+                        uno::Reference< beans::XPropertySet > 
xSourceProps(rxFS, uno::UNO_QUERY);
+                        if (xFormattedString.size() > 1 && xSelectionProp.is())
+                        {
+                            
PropertyMapper::setMappedProperties(xSelectionProp, xSourceProps,
+                                
PropertyMapper::getPropertyNameMapForTextShapeProperties());
+                        }
+                        else
+                        {
+                            PropertyMapper::setMappedProperties(*xShape, 
xSourceProps,
+                                
PropertyMapper::getPropertyNameMapForTextShapeProperties());
+                        }
+                    }
+                }
 
                 // adapt font size according to page size
                 awt::Size aOldRefSize;
@@ -2255,23 +2270,34 @@ rtl::Reference<SvxShapeText>
         }
         else
         {
+            uno::Reference< beans::XPropertySet > 
xSelectionProp(xSelectionCursor, uno::UNO_QUERY);
             for (const uno::Reference<chart2::XFormattedString>& rxFS : 
xFormattedString)
             {
-                xTextCursor->gotoEnd(false);
-                xShape->insertString( xTextCursor, rxFS->getString(), false );
-                xTextCursor->gotoEnd(true);
+                if (!rxFS->getString().isEmpty())
+                {
+                    xTextCursor->gotoEnd(false);
+                    xSelectionCursor->gotoEnd(false);
+                    xShape->insertString(xTextCursor, rxFS->getString(), 
false);
+                    xSelectionCursor->gotoEnd(true); // select current 
paragraph
+                    uno::Reference< beans::XPropertySet > xSourceProps(rxFS, 
uno::UNO_QUERY);
+                    if (xFormattedString.size() > 1 && xSelectionProp.is())
+                    {
+                        PropertyMapper::setMappedProperties(xSelectionProp, 
xSourceProps,
+                            
PropertyMapper::getPropertyNameMapForTextShapeProperties());
+                    }
+                    else
+                    {
+                        PropertyMapper::setMappedProperties(*xShape, 
xSourceProps,
+                            
PropertyMapper::getPropertyNameMapForTextShapeProperties());
+                    }
+                }
             }
-            awt::Size aOldRefSize;
-            bool bHasRefPageSize =
-                ( xTextProperties->getPropertyValue( "ReferencePageSize") >>= 
aOldRefSize );
 
             if( xFormattedString.hasElements() )
             {
-                uno::Reference< beans::XPropertySet > xSourceProps( 
xFormattedString[0], uno::UNO_QUERY );
-                PropertyMapper::setMappedProperties( *xShape, xSourceProps, 
PropertyMapper::getPropertyNameMapForCharacterProperties() );
-
                 // adapt font size according to page size
-                if( bHasRefPageSize )
+                awt::Size aOldRefSize;
+                if( xTextProperties->getPropertyValue("ReferencePageSize") >>= 
aOldRefSize )
                 {
                     RelativeSizeHelper::adaptFontSizes( *xShape, aOldRefSize, 
rSize );
                 }
diff --git a/oox/inc/drawingml/textcharacterproperties.hxx 
b/oox/inc/drawingml/textcharacterproperties.hxx
index 40842585d10a..9750407b817c 100644
--- a/oox/inc/drawingml/textcharacterproperties.hxx
+++ b/oox/inc/drawingml/textcharacterproperties.hxx
@@ -64,6 +64,12 @@ struct TextCharacterProperties
     /// Set if there was a property set that alters run visually during import
     bool mbHasVisualRunProperties;
 
+    /// Set if there was an empty paragraph property set during import
+    /// <a:pPr><a:defRPr/></a:pPr>
+    /// In that case we use the default paragraph properties from the
+    /// <c:txPr><a:p><a:pPr><a:defRPr>...</a:defRPr>
+    bool mbHasEmptyParaProperties;
+
     std::vector<css::beans::PropertyValue> maTextEffectsProperties;
 
     /** Overwrites all members that are explicitly set in rSourceProps. */
@@ -84,7 +90,7 @@ struct TextCharacterProperties
                             PropertySet& rPropSet,
                             const ::oox::core::XmlFilterBase& rFilter ) const;
 
-    TextCharacterProperties() : mbHasVisualRunProperties(false) {}
+    TextCharacterProperties() : mbHasVisualRunProperties(false), 
mbHasEmptyParaProperties(false) {}
 };
 
 
diff --git a/oox/source/drawingml/chart/titleconverter.cxx 
b/oox/source/drawingml/chart/titleconverter.cxx
index 91684393c627..e09108f6a171 100644
--- a/oox/source/drawingml/chart/titleconverter.cxx
+++ b/oox/source/drawingml/chart/titleconverter.cxx
@@ -90,7 +90,16 @@ Sequence< Reference< XFormattedString > > 
TextConverter::createStringSequence(
                 bool bAddNewLine = ((aRIt + 1 == aREnd) && (aPIt + 1 != 
aPEnd)) || rTextRun.isLineBreak();
                 Reference< XFormattedString > xFmtStr = appendFormattedString( 
aStringVec, rTextRun.getText(), bAddNewLine );
                 PropertySet aPropSet( xFmtStr );
-                TextCharacterProperties aRunProps( rParaProps );
+                TextCharacterProperties aRunProps;
+                if (rParaProps.mbHasEmptyParaProperties && rxTextProp.is() && 
rxTextProp->hasParagraphProperties())
+                {
+                    const TextParagraphVector rDefTextParas = 
rxTextProp->getParagraphs();
+                    TextParagraphVector::const_iterator aDefPIt = 
rDefTextParas.begin();
+                    const TextParagraph& rDefTextPara = **aDefPIt;
+                    aRunProps = 
rDefTextPara.getProperties().getTextCharacterProperties();
+                }
+                else
+                    aRunProps = rParaProps;
                 aRunProps.assignUsed( rTextRun.getTextCharacterProperties() );
                 getFormatter().convertTextFormatting( aPropSet, aRunProps, 
eObjType );
             }
diff --git a/oox/source/drawingml/textcharacterpropertiescontext.cxx 
b/oox/source/drawingml/textcharacterpropertiescontext.cxx
index fb4390e4c7a7..4935e8a75a68 100644
--- a/oox/source/drawingml/textcharacterpropertiescontext.cxx
+++ b/oox/source/drawingml/textcharacterpropertiescontext.cxx
@@ -50,6 +50,9 @@ 
TextCharacterPropertiesContext::TextCharacterPropertiesContext(
     int nVisualTokenAmount = sax_fastparser::castToFastAttributeList(
                 rAttribs.getFastAttributeList() 
).getFastAttributeTokens().size();
 
+    if (nVisualTokenAmount == 0)
+        mrTextCharacterProperties.mbHasEmptyParaProperties = true;
+
     if ( rAttribs.hasAttribute( XML_lang ) )
     {
         mrTextCharacterProperties.moLang = rAttribs.getString( XML_lang );

Reply via email to