Kaydet (Commit) 8d62b79f authored tarafından Patrick Jaap's avatar Patrick Jaap Kaydeden (comit) Miklos Vajna

tdf#112443 disable off-page content positioning

Disable the positioning for objects that are completely off-page.
During import, LO writer forces content always back to the page
and causes unwanted content on the page in constrast to MSO.

To achive this the top/left position of the content is compared to the bottom/right border of the clipping region.

A new compatibility flag OFF_PAGE_POSITIONING is introduced for
legacy rendering of legacy documents.

A unit test demonstrates the issue.

It resolves tdf#112443.

Change-Id: I263c129f9f09ed909ad777a34f8b9ffc84d871e4
Reviewed-on: https://gerrit.libreoffice.org/43313Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 4b941b7b
...@@ -81,6 +81,8 @@ enum class DocumentSettingId ...@@ -81,6 +81,8 @@ enum class DocumentSettingId
SURROUND_TEXT_WRAP_SMALL, SURROUND_TEXT_WRAP_SMALL,
PROP_LINE_SPACING_SHRINKS_FIRST_LINE, PROP_LINE_SPACING_SHRINKS_FIRST_LINE,
SUBTRACT_FLYS, SUBTRACT_FLYS,
// tdf#112443 disable off-page content positioning
DISABLE_OFF_PAGE_POSITIONING,
// COMPATIBILITY FLAGS END // COMPATIBILITY FLAGS END
BROWSE_MODE, BROWSE_MODE,
HTML_MODE, HTML_MODE,
......
...@@ -118,7 +118,6 @@ public: ...@@ -118,7 +118,6 @@ public:
} }
}; };
DECLARE_OOXMLIMPORT_TEST(testImageHyperlink, "image-hyperlink.docx") DECLARE_OOXMLIMPORT_TEST(testImageHyperlink, "image-hyperlink.docx")
{ {
OUString URL = getProperty<OUString>(getShape(1), "HyperLinkURL"); OUString URL = getProperty<OUString>(getShape(1), "HyperLinkURL");
...@@ -1559,6 +1558,15 @@ DECLARE_OOXMLIMPORT_TEST(testTdf43017, "tdf43017.docx") ...@@ -1559,6 +1558,15 @@ DECLARE_OOXMLIMPORT_TEST(testTdf43017, "tdf43017.docx")
sal_Int32(-1), getProperty<sal_Int32>(xText, "CharColor")); sal_Int32(-1), getProperty<sal_Int32>(xText, "CharColor"));
} }
DECLARE_OOXMLIMPORT_TEST(testTdf112443, "tdf112443.docx")
{
// the position of the flying text frame should be off page
// 30624 below its anchor
OUString aTop = parseDump("//fly[1]/infos/bounds", "top");
CPPUNIT_ASSERT_EQUAL( OUString("30624"), aTop );
}
// tests should only be added to ooxmlIMPORT *if* they fail round-tripping in ooxmlEXPORT // tests should only be added to ooxmlIMPORT *if* they fail round-tripping in ooxmlEXPORT
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
...@@ -87,7 +87,8 @@ sw::DocumentSettingManager::DocumentSettingManager(SwDoc &rDoc) ...@@ -87,7 +87,8 @@ sw::DocumentSettingManager::DocumentSettingManager(SwDoc &rDoc)
mbPropLineSpacingShrinksFirstLine(true), mbPropLineSpacingShrinksFirstLine(true),
mbSubtractFlys(false), mbSubtractFlys(false),
mApplyParagraphMarkFormatToNumbering(false), mApplyParagraphMarkFormatToNumbering(false),
mbLastBrowseMode( false ) mbLastBrowseMode( false ),
mbDisableOffPagePositioning ( false )
// COMPATIBILITY FLAGS END // COMPATIBILITY FLAGS END
{ {
...@@ -202,6 +203,7 @@ bool sw::DocumentSettingManager::get(/*[in]*/ DocumentSettingId id) const ...@@ -202,6 +203,7 @@ bool sw::DocumentSettingManager::get(/*[in]*/ DocumentSettingId id) const
case DocumentSettingId::EMBED_FONTS: return mEmbedFonts; case DocumentSettingId::EMBED_FONTS: return mEmbedFonts;
case DocumentSettingId::EMBED_SYSTEM_FONTS: return mEmbedSystemFonts; case DocumentSettingId::EMBED_SYSTEM_FONTS: return mEmbedSystemFonts;
case DocumentSettingId::APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING: return mApplyParagraphMarkFormatToNumbering; case DocumentSettingId::APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING: return mApplyParagraphMarkFormatToNumbering;
case DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING: return mbDisableOffPagePositioning;
default: default:
OSL_FAIL("Invalid setting id"); OSL_FAIL("Invalid setting id");
} }
...@@ -416,6 +418,9 @@ void sw::DocumentSettingManager::set(/*[in]*/ DocumentSettingId id, /*[in]*/ boo ...@@ -416,6 +418,9 @@ void sw::DocumentSettingManager::set(/*[in]*/ DocumentSettingId id, /*[in]*/ boo
case DocumentSettingId::APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING: case DocumentSettingId::APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING:
mApplyParagraphMarkFormatToNumbering = value; mApplyParagraphMarkFormatToNumbering = value;
break; break;
case DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING:
mbDisableOffPagePositioning = value;
break;
default: default:
OSL_FAIL("Invalid setting id"); OSL_FAIL("Invalid setting id");
} }
......
...@@ -154,6 +154,7 @@ class DocumentSettingManager : ...@@ -154,6 +154,7 @@ class DocumentSettingManager :
bool mApplyParagraphMarkFormatToNumbering; bool mApplyParagraphMarkFormatToNumbering;
bool mbLastBrowseMode : 1; bool mbLastBrowseMode : 1;
bool mbDisableOffPagePositioning; // tdf#112443
public: public:
......
...@@ -495,6 +495,9 @@ void SwFlyFreeFrame::CheckClip( const SwFormatFrameSize &rSz ) ...@@ -495,6 +495,9 @@ void SwFlyFreeFrame::CheckClip( const SwFormatFrameSize &rSz )
{ {
const long nOld = getFrameArea().Top(); const long nOld = getFrameArea().Top();
// tdf#112443 disable positioning if content is completely off page
bool bDisableOffPagePositioning = GetFormat()->getIDocumentSettingAccess().get(DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING);
if ( !bDisableOffPagePositioning || nOld <= nClipBot)
{ {
SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this); SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
aFrm.Pos().Y() = std::max( aClip.Top(), nClipBot - aFrm.Height() ); aFrm.Pos().Y() = std::max( aClip.Top(), nClipBot - aFrm.Height() );
...@@ -512,6 +515,9 @@ void SwFlyFreeFrame::CheckClip( const SwFormatFrameSize &rSz ) ...@@ -512,6 +515,9 @@ void SwFlyFreeFrame::CheckClip( const SwFormatFrameSize &rSz )
{ {
const long nOld = getFrameArea().Left(); const long nOld = getFrameArea().Left();
// tdf#112443 disable positioning if content is completely off page
bool bDisableOffPagePositioning = GetFormat()->getIDocumentSettingAccess().get(DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING);
if ( !bDisableOffPagePositioning || nOld <= nClipRig )
{ {
SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this); SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
aFrm.Pos().X() = std::max( aClip.Left(), nClipRig - aFrm.Width() ); aFrm.Pos().X() = std::max( aClip.Left(), nClipRig - aFrm.Width() );
......
...@@ -455,6 +455,15 @@ SwTwips SwAnchoredObjectPosition::ImplAdjustVertRelPos( const SwTwips nTopOfAnch ...@@ -455,6 +455,15 @@ SwTwips SwAnchoredObjectPosition::ImplAdjustVertRelPos( const SwTwips nTopOfAnch
} }
else else
{ {
/// tdf#112443 if position is completely off-page
// return the proposed position and do not adjust it.
bool bDisablePositioning = mpFrameFormat->getIDocumentSettingAccess().get(DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING);
if ( bDisablePositioning && nTopOfAnch + nAdjustedRelPosY > aPgAlignArea.Right() )
{
return nProposedRelPosY;
}
if ( bCheckBottom && if ( bCheckBottom &&
nTopOfAnch + nAdjustedRelPosY + aObjSize.Width() > nTopOfAnch + nAdjustedRelPosY + aObjSize.Width() >
aPgAlignArea.Right() ) aPgAlignArea.Right() )
...@@ -471,6 +480,15 @@ SwTwips SwAnchoredObjectPosition::ImplAdjustVertRelPos( const SwTwips nTopOfAnch ...@@ -471,6 +480,15 @@ SwTwips SwAnchoredObjectPosition::ImplAdjustVertRelPos( const SwTwips nTopOfAnch
} }
else else
{ {
// tdf#112443 if position is completely off-page
// return the proposed position and do not adjust it.
bool bDisablePositioning = mpFrameFormat->getIDocumentSettingAccess().get(DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING);
if ( bDisablePositioning && nTopOfAnch + nAdjustedRelPosY > aPgAlignArea.Bottom() )
{
return nProposedRelPosY;
}
// #i31805# - consider value of <bCheckBottom> // #i31805# - consider value of <bCheckBottom>
if ( bCheckBottom && if ( bCheckBottom &&
nTopOfAnch + nAdjustedRelPosY + aObjSize.Height() > nTopOfAnch + nAdjustedRelPosY + aObjSize.Height() >
......
...@@ -1105,6 +1105,7 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC ...@@ -1105,6 +1105,7 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
aExcludeWhenNotLoadingUserSettings.insert("TabOverMargin"); aExcludeWhenNotLoadingUserSettings.insert("TabOverMargin");
aExcludeWhenNotLoadingUserSettings.insert("PropLineSpacingShrinksFirstLine"); aExcludeWhenNotLoadingUserSettings.insert("PropLineSpacingShrinksFirstLine");
aExcludeWhenNotLoadingUserSettings.insert("SubtractFlysAnchoredAtFlys"); aExcludeWhenNotLoadingUserSettings.insert("SubtractFlysAnchoredAtFlys");
aExcludeWhenNotLoadingUserSettings.insert("DisableOffPagePositioning");
sal_Int32 nCount = aConfigProps.getLength(); sal_Int32 nCount = aConfigProps.getLength();
const PropertyValue* pValues = aConfigProps.getConstArray(); const PropertyValue* pValues = aConfigProps.getConstArray();
...@@ -1138,6 +1139,7 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC ...@@ -1138,6 +1139,7 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
bool bTabOverMargin = false; bool bTabOverMargin = false;
bool bPropLineSpacingShrinksFirstLine = false; bool bPropLineSpacingShrinksFirstLine = false;
bool bSubtractFlysAnchoredAtFlys = false; bool bSubtractFlysAnchoredAtFlys = false;
bool bDisableOffPagePositioning = false;
const PropertyValue* currentDatabaseDataSource = nullptr; const PropertyValue* currentDatabaseDataSource = nullptr;
const PropertyValue* currentDatabaseCommand = nullptr; const PropertyValue* currentDatabaseCommand = nullptr;
...@@ -1230,6 +1232,8 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC ...@@ -1230,6 +1232,8 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
bPropLineSpacingShrinksFirstLine = true; bPropLineSpacingShrinksFirstLine = true;
else if (pValues->Name == "SubtractFlysAnchoredAtFlys") else if (pValues->Name == "SubtractFlysAnchoredAtFlys")
bSubtractFlysAnchoredAtFlys = true; bSubtractFlysAnchoredAtFlys = true;
else if (pValues->Name == "DisableOffPagePositioning")
bDisableOffPagePositioning = true;
} }
catch( Exception& ) catch( Exception& )
{ {
...@@ -1390,6 +1394,9 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC ...@@ -1390,6 +1394,9 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
if (!bSubtractFlysAnchoredAtFlys) if (!bSubtractFlysAnchoredAtFlys)
xProps->setPropertyValue("SubtractFlysAnchoredAtFlys", makeAny(true)); xProps->setPropertyValue("SubtractFlysAnchoredAtFlys", makeAny(true));
if ( !bDisableOffPagePositioning )
xProps->setPropertyValue("DisableOffPagePositioning", makeAny(true));
SwDoc *pDoc = getDoc(); SwDoc *pDoc = getDoc();
SfxPrinter *pPrinter = pDoc->getIDocumentDeviceAccess().getPrinter( false ); SfxPrinter *pPrinter = pDoc->getIDocumentDeviceAccess().getPrinter( false );
if( pPrinter ) if( pPrinter )
......
...@@ -134,6 +134,7 @@ enum SwDocumentSettingsPropertyHandles ...@@ -134,6 +134,7 @@ enum SwDocumentSettingsPropertyHandles
HANDLE_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING, HANDLE_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING,
HANDLE_PROP_LINE_SPACING_SHRINKS_FIRST_LINE, HANDLE_PROP_LINE_SPACING_SHRINKS_FIRST_LINE,
HANDLE_SUBTRACT_FLYS, HANDLE_SUBTRACT_FLYS,
HANDLE_DISABLE_OFF_PAGE_POSITIONING,
}; };
static MasterPropertySetInfo * lcl_createSettingsInfo() static MasterPropertySetInfo * lcl_createSettingsInfo()
...@@ -210,6 +211,7 @@ static MasterPropertySetInfo * lcl_createSettingsInfo() ...@@ -210,6 +211,7 @@ static MasterPropertySetInfo * lcl_createSettingsInfo()
{ OUString("ApplyParagraphMarkFormatToNumbering"), HANDLE_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING, cppu::UnoType<bool>::get(), 0}, { OUString("ApplyParagraphMarkFormatToNumbering"), HANDLE_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING, cppu::UnoType<bool>::get(), 0},
{ OUString("PropLineSpacingShrinksFirstLine"), HANDLE_PROP_LINE_SPACING_SHRINKS_FIRST_LINE, cppu::UnoType<bool>::get(), 0}, { OUString("PropLineSpacingShrinksFirstLine"), HANDLE_PROP_LINE_SPACING_SHRINKS_FIRST_LINE, cppu::UnoType<bool>::get(), 0},
{ OUString("SubtractFlysAnchoredAtFlys"), HANDLE_SUBTRACT_FLYS, cppu::UnoType<bool>::get(), 0}, { OUString("SubtractFlysAnchoredAtFlys"), HANDLE_SUBTRACT_FLYS, cppu::UnoType<bool>::get(), 0},
{ OUString("DisableOffPagePositioning"), HANDLE_DISABLE_OFF_PAGE_POSITIONING, cppu::UnoType<bool>::get(), 0},
/* /*
* As OS said, we don't have a view when we need to set this, so I have to * As OS said, we don't have a view when we need to set this, so I have to
* find another solution before adding them to this property set - MTG * find another solution before adding them to this property set - MTG
...@@ -855,6 +857,16 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf ...@@ -855,6 +857,16 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf
} }
} }
break; break;
case HANDLE_DISABLE_OFF_PAGE_POSITIONING:
{
bool bTmp;
if (rValue >>= bTmp)
{
mpDoc->getIDocumentSettingAccess().set(
DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING, bTmp);
}
}
break;
default: default:
throw UnknownPropertyException(); throw UnknownPropertyException();
} }
...@@ -1269,6 +1281,11 @@ void SwXDocumentSettings::_getSingleValue( const comphelper::PropertyInfo & rInf ...@@ -1269,6 +1281,11 @@ void SwXDocumentSettings::_getSingleValue( const comphelper::PropertyInfo & rInf
rValue <<= mpDoc->getIDocumentSettingAccess().get(DocumentSettingId::SUBTRACT_FLYS); rValue <<= mpDoc->getIDocumentSettingAccess().get(DocumentSettingId::SUBTRACT_FLYS);
} }
break; break;
case HANDLE_DISABLE_OFF_PAGE_POSITIONING:
{
rValue <<= mpDoc->getIDocumentSettingAccess().get(DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING);
}
break;
default: default:
throw UnknownPropertyException(); throw UnknownPropertyException();
} }
......
...@@ -266,7 +266,6 @@ sal_Bool WriterFilter::filter(const uno::Sequence< beans::PropertyValue >& rDesc ...@@ -266,7 +266,6 @@ sal_Bool WriterFilter::filter(const uno::Sequence< beans::PropertyValue >& rDesc
return false; return false;
} }
void WriterFilter::cancel() void WriterFilter::cancel()
{ {
} }
...@@ -303,6 +302,7 @@ void WriterFilter::setTargetDocument(const uno::Reference< lang::XComponent >& x ...@@ -303,6 +302,7 @@ void WriterFilter::setTargetDocument(const uno::Reference< lang::XComponent >& x
xSettings->setPropertyValue("TreatSingleColumnBreakAsPageBreak", uno::makeAny(true)); xSettings->setPropertyValue("TreatSingleColumnBreakAsPageBreak", uno::makeAny(true));
xSettings->setPropertyValue("PropLineSpacingShrinksFirstLine", uno::makeAny(true)); xSettings->setPropertyValue("PropLineSpacingShrinksFirstLine", uno::makeAny(true));
xSettings->setPropertyValue("DoNotCaptureDrawObjsOnPage", uno::makeAny(true)); xSettings->setPropertyValue("DoNotCaptureDrawObjsOnPage", uno::makeAny(true));
xSettings->setPropertyValue("DisableOffPagePositioning", uno::makeAny(true));
} }
void WriterFilter::setSourceDocument(const uno::Reference< lang::XComponent >& xDoc) void WriterFilter::setSourceDocument(const uno::Reference< lang::XComponent >& xDoc)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment