summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-12-06 16:54:07 +0100
committerMiklos Vajna <vmiklos@collabora.com>2019-12-16 13:36:18 +0100
commit14b69981a3fe36e082852cb561251eb4fc43f6c5 (patch)
tree1ccbb10eb5f0253852d253d9930572d75b489932 /writerfilter
parent1ca0986bcc82e9fcfad055617359b619af53c794 (diff)
Related: tdf#115719 DOCX import: fix increased spacing vs left-aligned objects
Commit 8b73bafbc18acb4dd8911d2f2de8158d98eb6144 (tdf#115719 DOCX import: increase paragraph spacing for anchored objects, 2018-02-14) added an import-time tweak for a problem that has been confirmed to be a Word layout bug in the meantime (and the tweak makes Writer behave the same way if the document has been created by an affected Word version for layout compatiblity). Later, commit 4883da6fd25e4645a3b30cb58212a2f666dae75a (Related: tdf#124600 DOCX import: ignore left wrap on left-aligned shapes, 2018-02-14) fixed left spacing of anchored objects aligned to the left, to be in sync with what the DOC import does. This broke the previous fix in case the shapes are left-aligned. Fix the problem by tracking what is the in-file-format and logical left margin, so the final doc model has the value necessary for correct horizontal positioning and the importer has the value that's necessary for correct vertical positioning. (cherry picked from commit 814cb2433da6bd608e935fa5531d2a2b92867985) Change-Id: I8f16cbe7bad40e243111c902bdc1ab0e8141d6b9 Reviewed-on: https://gerrit.libreoffice.org/85207 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx14
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx15
-rw-r--r--writerfilter/source/dmapper/GraphicImport.cxx7
-rw-r--r--writerfilter/source/dmapper/GraphicImport.hxx1
-rw-r--r--writerfilter/source/dmapper/PropertyMap.cxx13
5 files changed, 38 insertions, 12 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 2ee8968467bf..d88776c63f46 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1679,7 +1679,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con
// Remember what objects are anchored to this paragraph.
// That list is only used for Word compat purposes, and
// it is only relevant for body text.
- AnchoredObjectInfo aInfo;
+ AnchoredObjectsInfo aInfo;
aInfo.m_xParagraph = xTextRange;
aInfo.m_aAnchoredObjects = rAppendContext.m_aAnchoredObjects;
m_aAnchoredObjectAnchors.push_back(aInfo);
@@ -6083,8 +6083,18 @@ void DomainMapper_Impl::ImportGraphic(const writerfilter::Reference< Properties
appendTextContent( xTextContent, uno::Sequence< beans::PropertyValue >() );
if (eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR && !m_aTextAppendStack.empty())
+ {
// Remember this object is anchored to the current paragraph.
- m_aTextAppendStack.top().m_aAnchoredObjects.push_back(xTextContent);
+ AnchoredObjectInfo aInfo;
+ aInfo.m_xAnchoredObject = xTextContent;
+ if (m_pGraphicImport)
+ {
+ // We still have the graphic import around, remember the original margin, so later
+ // SectionPropertyMap::HandleIncreasedAnchoredObjectSpacing() can use it.
+ aInfo.m_nLeftMargin = m_pGraphicImport->GetLeftMarginOrig();
+ }
+ m_aTextAppendStack.top().m_aAnchoredObjects.push_back(aInfo);
+ }
}
// Clear the reference, so in case the embedded object is inside a
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index dfba7c70f20f..9c0d2cfce854 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -226,7 +226,7 @@ struct TextAppendContext
* Objects anchored to the current paragraph, may affect the paragraph
* spacing.
*/
- std::vector<css::uno::Reference<css::text::XTextContent>> m_aAnchoredObjects;
+ std::vector<AnchoredObjectInfo> m_aAnchoredObjects;
TextAppendContext(const css::uno::Reference<css::text::XTextAppend>& xAppend, const css::uno::Reference<css::text::XTextCursor>& xCur)
: xTextAppend(xAppend)
@@ -387,11 +387,18 @@ struct FloatingTableInfo
css::uno::Any getPropertyValue(const OUString &propertyName);
};
-/// Stores info about objects anchored to a given paragraph.
+/// Stores original/in-file-format info about a single anchored object.
struct AnchoredObjectInfo
{
+ css::uno::Reference<css::text::XTextContent> m_xAnchoredObject;
+ sal_Int32 m_nLeftMargin = 0;
+};
+
+/// Stores info about objects anchored to a given paragraph.
+struct AnchoredObjectsInfo
+{
css::uno::Reference<css::text::XTextRange> m_xParagraph;
- std::vector<css::uno::Reference<css::text::XTextContent>> m_aAnchoredObjects;
+ std::vector<AnchoredObjectInfo> m_aAnchoredObjects;
};
struct SymbolData
@@ -992,7 +999,7 @@ public:
std::vector<FloatingTableInfo> m_aPendingFloatingTables;
/// Paragraphs with anchored objects in the current section.
- std::vector<AnchoredObjectInfo> m_aAnchoredObjectAnchors;
+ std::vector<AnchoredObjectsInfo> m_aAnchoredObjectAnchors;
/// Append a property to a sub-grabbag if necessary (e.g. 'lineRule', 'auto')
void appendGrabBag(std::vector<css::beans::PropertyValue>& rInteropGrabBag, const OUString& aKey, const OUString& aValue);
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 0d673cdc19bd..33275d9f0d55 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -204,6 +204,7 @@ public:
WrapPolygon::Pointer_t mpWrapPolygon;
sal_Int32 nLeftMargin;
+ sal_Int32 nLeftMarginOrig = 0;
sal_Int32 nRightMargin;
sal_Int32 nTopMargin;
sal_Int32 nBottomMargin;
@@ -979,6 +980,7 @@ void GraphicImport::ProcessShapeOptions(Value const & rValue)
{
case NS_ooxml::LN_CT_Anchor_distL:
m_pImpl->nLeftMargin = nIntValue / 360;
+ m_pImpl->nLeftMarginOrig = m_pImpl->nLeftMargin;
break;
case NS_ooxml::LN_CT_Anchor_distT:
//todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustULWrapForWordMargins()
@@ -1494,6 +1496,11 @@ bool GraphicImport::IsGraphic() const
return m_pImpl->bIsGraphic;
}
+sal_Int32 GraphicImport::GetLeftMarginOrig() const
+{
+ return m_pImpl->nLeftMarginOrig;
+}
+
}
}
diff --git a/writerfilter/source/dmapper/GraphicImport.hxx b/writerfilter/source/dmapper/GraphicImport.hxx
index a54a6980ef5f..d83f41cb161d 100644
--- a/writerfilter/source/dmapper/GraphicImport.hxx
+++ b/writerfilter/source/dmapper/GraphicImport.hxx
@@ -97,6 +97,7 @@ public:
css::uno::Reference<css::text::XTextContent> GetGraphicObject();
const css::uno::Reference<css::drawing::XShape>& GetXShapeObject() const { return m_xShape;}
bool IsGraphic() const;
+ sal_Int32 GetLeftMarginOrig() const;
private:
// Properties
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index 188b95634d62..3059d7fd9158 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -1225,7 +1225,7 @@ void SectionPropertyMap::HandleIncreasedAnchoredObjectSpacing(DomainMapper_Impl&
sal_Int32 nPageWidth = GetPageWidth();
sal_Int32 nTextAreaWidth = nPageWidth - GetLeftMargin() - GetRightMargin();
- std::vector<AnchoredObjectInfo>& rAnchoredObjectAnchors = rDM_Impl.m_aAnchoredObjectAnchors;
+ std::vector<AnchoredObjectsInfo>& rAnchoredObjectAnchors = rDM_Impl.m_aAnchoredObjectAnchors;
for (const auto& rAnchor : rAnchoredObjectAnchors)
{
// Ignore this paragraph when there are not enough shapes to trigger the Word bug we
@@ -1238,11 +1238,11 @@ void SectionPropertyMap::HandleIncreasedAnchoredObjectSpacing(DomainMapper_Impl&
sal_Int32 nShapesWidth = 0;
for (const auto& rAnchored : rAnchor.m_aAnchoredObjects)
{
- uno::Reference<drawing::XShape> xShape(rAnchored, uno::UNO_QUERY);
+ uno::Reference<drawing::XShape> xShape(rAnchored.m_xAnchoredObject, uno::UNO_QUERY);
if (!xShape.is())
continue;
- uno::Reference<beans::XPropertySet> xPropertySet(rAnchored, uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
if (!xPropertySet.is())
continue;
@@ -1252,8 +1252,9 @@ void SectionPropertyMap::HandleIncreasedAnchoredObjectSpacing(DomainMapper_Impl&
if (eWrap == text::WrapTextMode_THROUGH)
continue;
- sal_Int32 nLeftMargin = 0;
- xPropertySet->getPropertyValue("LeftMargin") >>= nLeftMargin;
+ // Use the original left margin, in case GraphicImport::lcl_sprm() reduced the doc model
+ // one to 0.
+ sal_Int32 nLeftMargin = rAnchored.m_nLeftMargin;
sal_Int32 nRightMargin = 0;
xPropertySet->getPropertyValue("RightMargin") >>= nRightMargin;
nShapesWidth += xShape->getSize().Width + nLeftMargin + nRightMargin;
@@ -1266,7 +1267,7 @@ void SectionPropertyMap::HandleIncreasedAnchoredObjectSpacing(DomainMapper_Impl&
sal_Int32 nHeight = 0;
for (const auto& rAnchored : rAnchor.m_aAnchoredObjects)
{
- uno::Reference<drawing::XShape> xShape(rAnchored, uno::UNO_QUERY);
+ uno::Reference<drawing::XShape> xShape(rAnchored.m_xAnchoredObject, uno::UNO_QUERY);
if (!xShape.is())
continue;