summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorRegényi Balázs <regenyi.balazs+gerrit@gmail.com>2020-06-10 14:27:32 +0200
committerLászló Németh <nemeth@numbertext.org>2020-07-01 18:33:59 +0200
commitd63321d949563759ee2ada96fdc2e0f8728941b2 (patch)
treed94ebb64e18839b430760dba525a885b10ae8093 /sw/source
parentb8db739c20f7a174702bab34eb9373ee3d0a9d02 (diff)
tdf#133863 tdf#133864 DOCX shape import: width relative to inside
and outside margins. See commit 43d7f4e3640c5e370fd1204739c2b0c7eb5f40e4 (offapi: document the 4 new properties which are no longer read-only). commit b46f4bc9760267ac5e45d43b77b5d2721ee4c386 (tdf#133070 DOCX import: fix shape height relative to bottom page margin) commit 330ed8120e9881656716d70d87b9f49f861f0bfa (tdf#133670 DOCX import: fix shape width relative to right margin) commit 7380905abc0833d9e4c4fe731d76174db8a8724c (tdf#132976 DOCX import: fix shape width relative to left margin) Co-authored-by: Szabolcs Tóth Change-Id: If81b7c80732141be1491ca82770cf6eee99f5656 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97627 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/layout/anchoreddrawobject.cxx36
1 files changed, 34 insertions, 2 deletions
diff --git a/sw/source/core/layout/anchoreddrawobject.cxx b/sw/source/core/layout/anchoreddrawobject.cxx
index 9b4bce8e44ef..1af32ed2fa80 100644
--- a/sw/source/core/layout/anchoreddrawobject.cxx
+++ b/sw/source/core/layout/anchoreddrawobject.cxx
@@ -620,6 +620,26 @@ SwRect SwAnchoredDrawObject::GetObjRect() const
return GetDrawObj()->GetSnapRect();
}
+namespace
+{
+ // Imagine an open book, inside margin is the one that is at the inner side of the pages, at the center of the book,
+ // outside margin is at the two opposite edges of the book.
+ // outside --text-- inside | inside --text-- outside
+ // With mirrored margins, when relating the size of an object from the inside margin for example, on the
+ // first page we calculate the new size of the object using the size of the right margin,
+ // on second page the left margin, third page right margin, etc.
+ long getInsideOutsideRelativeWidth(bool isOutside, const SwPageFrame* const pPageFrame)
+ {
+ // Alternating between the only two possible cases: inside and outside.
+ // Inside = false, Outside = true.
+ auto nPageNum = pPageFrame->GetPhyPageNum();
+ if (nPageNum % 2 == (isOutside ? 0 : 1))
+ return pPageFrame->GetRightMargin();
+ else
+ return pPageFrame->GetLeftMargin();
+ }
+}
+
// --> #i70122#
SwRect SwAnchoredDrawObject::GetObjBoundRect() const
{
@@ -640,10 +660,22 @@ SwRect SwAnchoredDrawObject::GetObjBoundRect() const
// The size of the shape's width is going to be relative to the size of the left margin.
// E.g.: (left margin = 8 && relative size = 150%) -> width of some shape = 12.
else if (GetDrawObj()->GetRelativeWidthRelation() == text::RelOrientation::PAGE_LEFT)
- nWidth = GetPageFrame()->GetLeftMargin();
+ {
+ if (GetPageFrame()->GetPageDesc()->GetUseOn() == UseOnPage::Mirror)
+ // We want to get the width of whatever is going through here using the size of the
+ // outside margin.
+ nWidth = getInsideOutsideRelativeWidth(true, GetPageFrame());
+ else
+ nWidth = GetPageFrame()->GetLeftMargin();
+ }
// Same as the left margin above.
else if (GetDrawObj()->GetRelativeWidthRelation() == text::RelOrientation::PAGE_RIGHT)
- nWidth = GetPageFrame()->GetRightMargin();
+ if (GetPageFrame()->GetPageDesc()->GetUseOn() == UseOnPage::Mirror)
+ // We want to get the width of whatever is going through here using the size of the
+ // inside margin.
+ nWidth = getInsideOutsideRelativeWidth(false, GetPageFrame());
+ else
+ nWidth = GetPageFrame()->GetRightMargin();
else
nWidth = GetPageFrame( )->GetBoundRect( GetPageFrame()->getRootFrame()->GetCurrShell()->GetOut() ).SVRect().GetWidth();
nTargetWidth = nWidth * (*GetDrawObj( )->GetRelativeWidth());