n#778836 fix DOCX import of right margin vs numbering and paragraph styles
The problem was that the left / first paragraph margin was defined in the numbering style, and that zeroed out the already inherited right margin. Change-Id: Ife521d1de4868a7be33de5f8d6af363d10cbc903
This commit is contained in:
@@ -1443,6 +1443,38 @@ void DomainMapper::lcl_sprm(Sprm & rSprm)
|
||||
sprmWithProps( rSprm, m_pImpl->GetTopContext() );
|
||||
}
|
||||
|
||||
sal_Int32 lcl_getCurrentNumberingProperty(uno::Reference<container::XIndexAccess> xNumberingRules, sal_Int32 nNumberingLevel, OUString aProp)
|
||||
{
|
||||
sal_Int32 nRet = 0;
|
||||
|
||||
try
|
||||
{
|
||||
if (nNumberingLevel < 0) // It seems it's valid to omit numbering level, and in that case it means zero.
|
||||
nNumberingLevel = 0;
|
||||
if (xNumberingRules.is())
|
||||
{
|
||||
uno::Sequence<beans::PropertyValue> aProps;
|
||||
xNumberingRules->getByIndex(nNumberingLevel) >>= aProps;
|
||||
for (int i = 0; i < aProps.getLength(); ++i)
|
||||
{
|
||||
const beans::PropertyValue& rProp = aProps[i];
|
||||
|
||||
if (rProp.Name == aProp)
|
||||
{
|
||||
rProp.Value >>= nRet;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( const uno::Exception& )
|
||||
{
|
||||
// This can happen when the doc contains some hand-crafted invalid list level.
|
||||
}
|
||||
|
||||
return nRet;
|
||||
}
|
||||
|
||||
void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext, SprmType eSprmType )
|
||||
{
|
||||
OSL_ENSURE(rContext.get(), "PropertyMap has to be valid!");
|
||||
@@ -2970,9 +3002,33 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext, SprmType
|
||||
const StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast<const StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : 0);
|
||||
|
||||
if( pStyleSheetProperties && pStyleSheetProperties->GetListId() >= 0 )
|
||||
{
|
||||
rContext->Insert( PROP_NUMBERING_STYLE_NAME, true, uno::makeAny(
|
||||
ListDef::GetStyleName( pStyleSheetProperties->GetListId( ) ) ), false);
|
||||
|
||||
// We're inheriting properties from a numbering style. Make sure a possible right margin is inherited from the base style.
|
||||
sal_Int32 nParaRightMargin = 0;
|
||||
if (!pEntry->sBaseStyleIdentifier.isEmpty())
|
||||
{
|
||||
const StyleSheetEntryPtr pParent = pStyleTable->FindStyleSheetByISTD(pEntry->sBaseStyleIdentifier);
|
||||
const StyleSheetPropertyMap* pParentProperties = dynamic_cast<const StyleSheetPropertyMap*>(pParent ? pParent->pProperties.get() : 0);
|
||||
if (pParentProperties->find( PropertyDefinition( PROP_PARA_RIGHT_MARGIN, true )) != pParentProperties->end())
|
||||
nParaRightMargin = pParentProperties->find( PropertyDefinition( PROP_PARA_RIGHT_MARGIN, true ))->second.get<sal_Int32>();
|
||||
}
|
||||
if (nParaRightMargin != 0)
|
||||
{
|
||||
// If we're setting the right margin, we should set the first / left margin as well from the numbering style.
|
||||
sal_Int32 nFirstLineIndent = lcl_getCurrentNumberingProperty(m_pImpl->GetCurrentNumberingRules(), pStyleSheetProperties->GetListLevel(), "FirstLineIndent");
|
||||
sal_Int32 nParaLeftMargin = lcl_getCurrentNumberingProperty(m_pImpl->GetCurrentNumberingRules(), pStyleSheetProperties->GetListLevel(), "IndentAt");
|
||||
if (nFirstLineIndent != 0)
|
||||
rContext->Insert(PROP_PARA_FIRST_LINE_INDENT, true, uno::makeAny(nFirstLineIndent));
|
||||
if (nParaLeftMargin != 0)
|
||||
rContext->Insert(PROP_PARA_LEFT_MARGIN, true, uno::makeAny(nParaLeftMargin));
|
||||
|
||||
rContext->Insert(PROP_PARA_RIGHT_MARGIN, true, uno::makeAny(nParaRightMargin));
|
||||
}
|
||||
}
|
||||
|
||||
if( pStyleSheetProperties && pStyleSheetProperties->GetListLevel() >= 0 )
|
||||
rContext->Insert( PROP_NUMBERING_LEVEL, true, uno::makeAny(pStyleSheetProperties->GetListLevel()), false);
|
||||
}
|
||||
|
@@ -3679,9 +3679,9 @@ void DomainMapper_Impl::ApplySettingsTable()
|
||||
}
|
||||
}
|
||||
|
||||
uno::Reference<beans::XPropertySet> DomainMapper_Impl::GetCurrentNumberingCharStyle()
|
||||
uno::Reference<container::XIndexAccess> DomainMapper_Impl::GetCurrentNumberingRules(sal_Int32* pListLevel)
|
||||
{
|
||||
uno::Reference<beans::XPropertySet> xRet;
|
||||
uno::Reference<container::XIndexAccess> xRet;
|
||||
try
|
||||
{
|
||||
OUString aStyle = GetCurrentParaStyleId();
|
||||
@@ -3692,18 +3692,35 @@ uno::Reference<beans::XPropertySet> DomainMapper_Impl::GetCurrentNumberingCharSt
|
||||
return xRet;
|
||||
const StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast<const StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : 0);
|
||||
sal_Int32 nListId = pStyleSheetProperties->GetListId();
|
||||
sal_Int32 nListLevel = pStyleSheetProperties->GetListLevel();
|
||||
if (nListId < 0 || nListLevel < 0)
|
||||
if (nListId < 0)
|
||||
return xRet;
|
||||
if (pListLevel)
|
||||
*pListLevel = pStyleSheetProperties->GetListLevel();
|
||||
|
||||
// So we are in a paragraph style and it has numbering. Look up the relevant character style.
|
||||
// So we are in a paragraph style and it has numbering. Look up the relevant numbering rules.
|
||||
OUString aListName = ListDef::GetStyleName(nListId);
|
||||
uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier(GetTextDocument(), uno::UNO_QUERY);
|
||||
uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
|
||||
uno::Reference<container::XNameAccess> xNumberingStyles;
|
||||
xStyleFamilies->getByName("NumberingStyles") >>= xNumberingStyles;
|
||||
uno::Reference<beans::XPropertySet> xStyle(xNumberingStyles->getByName(aListName), uno::UNO_QUERY);
|
||||
uno::Reference<container::XIndexAccess> xLevels(xStyle->getPropertyValue("NumberingRules"), uno::UNO_QUERY);
|
||||
xRet.set(xStyle->getPropertyValue("NumberingRules"), uno::UNO_QUERY);
|
||||
}
|
||||
catch( const uno::Exception& )
|
||||
{
|
||||
}
|
||||
return xRet;
|
||||
}
|
||||
|
||||
uno::Reference<beans::XPropertySet> DomainMapper_Impl::GetCurrentNumberingCharStyle()
|
||||
{
|
||||
uno::Reference<beans::XPropertySet> xRet;
|
||||
try
|
||||
{
|
||||
sal_Int32 nListLevel = -1;
|
||||
uno::Reference<container::XIndexAccess> xLevels = GetCurrentNumberingRules(&nListLevel);
|
||||
if (!xLevels.is())
|
||||
return xRet;
|
||||
uno::Sequence<beans::PropertyValue> aProps;
|
||||
xLevels->getByIndex(nListLevel) >>= aProps;
|
||||
for (int i = 0; i < aProps.getLength(); ++i)
|
||||
@@ -3715,6 +3732,8 @@ uno::Reference<beans::XPropertySet> DomainMapper_Impl::GetCurrentNumberingCharSt
|
||||
OUString aCharStyle;
|
||||
rProp.Value >>= aCharStyle;
|
||||
uno::Reference<container::XNameAccess> xCharacterStyles;
|
||||
uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier(GetTextDocument(), uno::UNO_QUERY);
|
||||
uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
|
||||
xStyleFamilies->getByName("CharacterStyles") >>= xCharacterStyles;
|
||||
xRet.set(xCharacterStyles->getByName(aCharStyle), uno::UNO_QUERY_THROW);
|
||||
break;
|
||||
|
@@ -629,8 +629,10 @@ public:
|
||||
|
||||
void ApplySettingsTable();
|
||||
SectionPropertyMap * GetSectionContext();
|
||||
/// If the current paragraph has a numbering style associated, this method returns its character style
|
||||
/// If the current paragraph has a numbering style associated, this method returns its character style (part of the numbering rules)
|
||||
com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> GetCurrentNumberingCharStyle();
|
||||
/// If the current paragraph has a numbering style associated, this method returns its numbering rules
|
||||
com::sun::star::uno::Reference<com::sun::star::container::XIndexAccess> GetCurrentNumberingRules(sal_Int32* pListLevel = 0);
|
||||
|
||||
/**
|
||||
Used for attributes/sprms which cannot be evaluated immediatelly (e.g. they depend
|
||||
|
Reference in New Issue
Block a user