summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBalazs Varga <balazs.varga.extern@allotropia.de>2024-03-28 17:17:47 +0100
committerThorsten Behrens <thorsten.behrens@allotropia.de>2024-04-30 15:10:43 +0200
commit3f888706ee76a5da302bd2790c85d8fcb16d91ed (patch)
treed7ca427fcfd0c7e74d90762fd857b62c528ad609
parent0a062632c754f5d03f1b649efdabb716f9a2e0e2 (diff)
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). cherry-picked from commit: f31a8ff9ea15ad81aeac265fce6eafe6342a68b7 Change-Id: I4fb5c3d80b7889935d198e70fb49e2c68108b235 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165500 Tested-by: Jenkins Tested-by: Gabor Kelemen <gabor.kelemen.extern@allotropia.de> Reviewed-by: Balazs Varga <balazs.varga.extern@allotropia.de>
-rw-r--r--chart2/source/view/main/PropertyMapper.cxx3
-rw-r--r--chart2/source/view/main/ShapeFactory.cxx74
-rw-r--r--oox/inc/drawingml/textcharacterproperties.hxx8
-rw-r--r--oox/source/drawingml/chart/titleconverter.cxx11
-rw-r--r--oox/source/drawingml/textcharacterpropertiescontext.cxx3
5 files changed, 72 insertions, 27 deletions
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 f9efceb676a5..1384372cda33 100644
--- a/chart2/source/view/main/ShapeFactory.cxx
+++ b/chart2/source/view/main/ShapeFactory.cxx
@@ -2177,7 +2177,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;
@@ -2226,18 +2227,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 : std::as_const(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('\r');
+ 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;
@@ -2249,23 +2264,34 @@ rtl::Reference<SvxShapeText>
}
else
{
- for( const uno::Reference< chart2::XFormattedString >& rxFS : std::as_const(xFormattedString) )
+ 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 );