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
SURROUND_TEXT_WRAP_SMALL,
PROP_LINE_SPACING_SHRINKS_FIRST_LINE,
SUBTRACT_FLYS,
// tdf#112443 disable off-page content positioning
DISABLE_OFF_PAGE_POSITIONING,
// COMPATIBILITY FLAGS END
BROWSE_MODE,
HTML_MODE,
......
......@@ -118,7 +118,6 @@ public:
}
};
DECLARE_OOXMLIMPORT_TEST(testImageHyperlink, "image-hyperlink.docx")
{
OUString URL = getProperty<OUString>(getShape(1), "HyperLinkURL");
......@@ -1559,6 +1558,15 @@ DECLARE_OOXMLIMPORT_TEST(testTdf43017, "tdf43017.docx")
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
CPPUNIT_PLUGIN_IMPLEMENT();
......
......@@ -87,7 +87,8 @@ sw::DocumentSettingManager::DocumentSettingManager(SwDoc &rDoc)
mbPropLineSpacingShrinksFirstLine(true),
mbSubtractFlys(false),
mApplyParagraphMarkFormatToNumbering(false),
mbLastBrowseMode( false )
mbLastBrowseMode( false ),
mbDisableOffPagePositioning ( false )
// COMPATIBILITY FLAGS END
{
......@@ -202,6 +203,7 @@ bool sw::DocumentSettingManager::get(/*[in]*/ DocumentSettingId id) const
case DocumentSettingId::EMBED_FONTS: return mEmbedFonts;
case DocumentSettingId::EMBED_SYSTEM_FONTS: return mEmbedSystemFonts;
case DocumentSettingId::APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING: return mApplyParagraphMarkFormatToNumbering;
case DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING: return mbDisableOffPagePositioning;
default:
OSL_FAIL("Invalid setting id");
}
......@@ -416,6 +418,9 @@ void sw::DocumentSettingManager::set(/*[in]*/ DocumentSettingId id, /*[in]*/ boo
case DocumentSettingId::APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING:
mApplyParagraphMarkFormatToNumbering = value;
break;
case DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING:
mbDisableOffPagePositioning = value;
break;
default:
OSL_FAIL("Invalid setting id");
}
......
......@@ -154,6 +154,7 @@ class DocumentSettingManager :
bool mApplyParagraphMarkFormatToNumbering;
bool mbLastBrowseMode : 1;
bool mbDisableOffPagePositioning; // tdf#112443
public:
......
......@@ -495,6 +495,9 @@ void SwFlyFreeFrame::CheckClip( const SwFormatFrameSize &rSz )
{
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);
aFrm.Pos().Y() = std::max( aClip.Top(), nClipBot - aFrm.Height() );
......@@ -512,6 +515,9 @@ void SwFlyFreeFrame::CheckClip( const SwFormatFrameSize &rSz )
{
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);
aFrm.Pos().X() = std::max( aClip.Left(), nClipRig - aFrm.Width() );
......
......@@ -455,6 +455,15 @@ SwTwips SwAnchoredObjectPosition::ImplAdjustVertRelPos( const SwTwips nTopOfAnch
}
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 &&
nTopOfAnch + nAdjustedRelPosY + aObjSize.Width() >
aPgAlignArea.Right() )
......@@ -471,6 +480,15 @@ SwTwips SwAnchoredObjectPosition::ImplAdjustVertRelPos( const SwTwips nTopOfAnch
}
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>
if ( bCheckBottom &&
nTopOfAnch + nAdjustedRelPosY + aObjSize.Height() >
......
......@@ -1105,6 +1105,7 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
aExcludeWhenNotLoadingUserSettings.insert("TabOverMargin");
aExcludeWhenNotLoadingUserSettings.insert("PropLineSpacingShrinksFirstLine");
aExcludeWhenNotLoadingUserSettings.insert("SubtractFlysAnchoredAtFlys");
aExcludeWhenNotLoadingUserSettings.insert("DisableOffPagePositioning");
sal_Int32 nCount = aConfigProps.getLength();
const PropertyValue* pValues = aConfigProps.getConstArray();
......@@ -1138,6 +1139,7 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
bool bTabOverMargin = false;
bool bPropLineSpacingShrinksFirstLine = false;
bool bSubtractFlysAnchoredAtFlys = false;
bool bDisableOffPagePositioning = false;
const PropertyValue* currentDatabaseDataSource = nullptr;
const PropertyValue* currentDatabaseCommand = nullptr;
......@@ -1230,6 +1232,8 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
bPropLineSpacingShrinksFirstLine = true;
else if (pValues->Name == "SubtractFlysAnchoredAtFlys")
bSubtractFlysAnchoredAtFlys = true;
else if (pValues->Name == "DisableOffPagePositioning")
bDisableOffPagePositioning = true;
}
catch( Exception& )
{
......@@ -1390,6 +1394,9 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
if (!bSubtractFlysAnchoredAtFlys)
xProps->setPropertyValue("SubtractFlysAnchoredAtFlys", makeAny(true));
if ( !bDisableOffPagePositioning )
xProps->setPropertyValue("DisableOffPagePositioning", makeAny(true));
SwDoc *pDoc = getDoc();
SfxPrinter *pPrinter = pDoc->getIDocumentDeviceAccess().getPrinter( false );
if( pPrinter )
......
......@@ -134,6 +134,7 @@ enum SwDocumentSettingsPropertyHandles
HANDLE_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING,
HANDLE_PROP_LINE_SPACING_SHRINKS_FIRST_LINE,
HANDLE_SUBTRACT_FLYS,
HANDLE_DISABLE_OFF_PAGE_POSITIONING,
};
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("PropLineSpacingShrinksFirstLine"), HANDLE_PROP_LINE_SPACING_SHRINKS_FIRST_LINE, 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
* find another solution before adding them to this property set - MTG
......@@ -855,6 +857,16 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf
}
}
break;
case HANDLE_DISABLE_OFF_PAGE_POSITIONING:
{
bool bTmp;
if (rValue >>= bTmp)
{
mpDoc->getIDocumentSettingAccess().set(
DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING, bTmp);
}
}
break;
default:
throw UnknownPropertyException();
}
......@@ -1269,6 +1281,11 @@ void SwXDocumentSettings::_getSingleValue( const comphelper::PropertyInfo & rInf
rValue <<= mpDoc->getIDocumentSettingAccess().get(DocumentSettingId::SUBTRACT_FLYS);
}
break;
case HANDLE_DISABLE_OFF_PAGE_POSITIONING:
{
rValue <<= mpDoc->getIDocumentSettingAccess().get(DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING);
}
break;
default:
throw UnknownPropertyException();
}
......
......@@ -266,7 +266,6 @@ sal_Bool WriterFilter::filter(const uno::Sequence< beans::PropertyValue >& rDesc
return false;
}
void WriterFilter::cancel()
{
}
......@@ -303,6 +302,7 @@ void WriterFilter::setTargetDocument(const uno::Reference< lang::XComponent >& x
xSettings->setPropertyValue("TreatSingleColumnBreakAsPageBreak", uno::makeAny(true));
xSettings->setPropertyValue("PropLineSpacingShrinksFirstLine", uno::makeAny(true));
xSettings->setPropertyValue("DoNotCaptureDrawObjsOnPage", uno::makeAny(true));
xSettings->setPropertyValue("DisableOffPagePositioning", uno::makeAny(true));
}
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