sw/qa/uitest/data/keep-aspect-ratio.odt |binary sw/qa/uitest/ui/frmdlg/frmdlg.py | 20 ++++++++++++++++++++ sw/source/ui/frmdlg/frmpage.cxx | 6 +++++- sw/source/uibase/inc/frmpage.hxx | 1 + 4 files changed, 26 insertions(+), 1 deletion(-)
New commits: commit a3150fc8a59662ce8630cfc64fec9cd083ac7d36 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri May 24 12:06:55 2024 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri May 24 13:58:07 2024 +0200 tdf#145972 sw image dialog: fix bad rel width w/ pt units and kept aspect ratio Regression from commit 02c435082058ecf7f9d4d73cb47d31d0218dc10d (sw keep aspect ratio: add filter for this setting, 2021-06-07), once UI units are set to poins (instead of cms), the image dialog for the bugdoc was showing 5% width instead of 48%. 48% is roughtly correct, visually the image is taking half of the body frame width. Previously the bad rel size didn't happen because we didn't save the "keep aspect ratio" to documents, so it was off by the time the dialog was initialized. Fix the problem by introducing a new flag, so we can differentiate between the user changine the width or height vs the dialog being initialized. RelSizeClickHdl() is meant to adjust the other axis in the user case, and this is not wanted in the init case. A higher level fix would be to make sure once aspect ratio is kept, that ratio is stored in documents explicitly, so we can say 50% wide with e.g. 4:3 ratio, that would avoid all this trouble by even looking at the calculated sizes when we want to work with percents. This storing of the aspect ratio is not done here. Change-Id: I901e7f6d5e6f7f1349d7beeb05985ddbf99a34a2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168015 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/uitest/data/keep-aspect-ratio.odt b/sw/qa/uitest/data/keep-aspect-ratio.odt new file mode 100644 index 000000000000..2545b34e91f7 Binary files /dev/null and b/sw/qa/uitest/data/keep-aspect-ratio.odt differ diff --git a/sw/qa/uitest/ui/frmdlg/frmdlg.py b/sw/qa/uitest/ui/frmdlg/frmdlg.py index aa2d4fba7aff..a37062c1d392 100644 --- a/sw/qa/uitest/ui/frmdlg/frmdlg.py +++ b/sw/qa/uitest/ui/frmdlg/frmdlg.py @@ -150,4 +150,24 @@ class Test(UITestCase): # complexity. self.assertEqual(visible, "false") + def test_keep_aspect_ratio_init(self): + # Change from inch to pt to hit the rounding error. 6 means Point, see + # officecfg/registry/schema/org/openoffice/Office/Writer.xcs. + with self.ui_test.set_config('/org.openoffice.Office.Writer/Layout/Other/MeasureUnit', 6): + # Given a document with an image, width is relative: + with self.ui_test.load_file(get_url_for_data_file("keep-aspect-ratio.odt")) as xComponent: + xComponent.CurrentController.select(xComponent.DrawPage[0]) + # Wait until SwTextShell is replaced with SwDrawShell after 120 ms, as set in the SwView + # ctor. + time.sleep(0.2) + # When opening the image properties dialog: + with self.ui_test.execute_dialog_through_command(".uno:FrameDialog") as xDialog: + xWidth = xDialog.getChild("width") + frame_width = get_state_as_dict(xWidth)["Value"] + # Then make sure the width is 48%: + # Without the accompanying fix in place, this test would have failed with: + # AssertionError: '5' != '48' + # i.e. the reported size was close to zero instead of ~half of the page width. + self.assertEqual(frame_width, "48") + # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sw/source/ui/frmdlg/frmpage.cxx b/sw/source/ui/frmdlg/frmpage.cxx index 589af7dbb0a0..bd58f2ab7246 100644 --- a/sw/source/ui/frmdlg/frmpage.cxx +++ b/sw/source/ui/frmdlg/frmpage.cxx @@ -2182,7 +2182,7 @@ IMPL_LINK( SwFramePage, ModifyHdl, weld::MetricSpinButton&, rEdit, void ) { SwTwips nWidth = static_cast< SwTwips >(m_xWidthED->DenormalizePercent(m_xWidthED->get_value(FieldUnit::TWIP))); SwTwips nHeight = static_cast< SwTwips >(m_xHeightED->DenormalizePercent(m_xHeightED->get_value(FieldUnit::TWIP))); - if (m_xFixedRatioCB->get_active()) + if (m_xFixedRatioCB->get_active() && !m_bIgnoreFixedRatio) { if (&rEdit == m_xWidthED->get()) { @@ -2385,14 +2385,18 @@ void SwFramePage::Init(const SfxItemSet& rSet) !m_xRelWidthCB->get_active()) { m_xRelWidthCB->set_active(true); + m_bIgnoreFixedRatio = true; RelSizeClickHdl(*m_xRelWidthCB); + m_bIgnoreFixedRatio = false; m_xWidthED->set_value(rSize.GetWidthPercent(), FieldUnit::PERCENT); } if (rSize.GetHeightPercent() && rSize.GetHeightPercent() != SwFormatFrameSize::SYNCED && !m_xRelHeightCB->get_active()) { m_xRelHeightCB->set_active(true); + m_bIgnoreFixedRatio = true; RelSizeClickHdl(*m_xRelHeightCB); + m_bIgnoreFixedRatio = false; m_xHeightED->set_value(rSize.GetHeightPercent(), FieldUnit::PERCENT); } m_xRelWidthCB->save_state(); diff --git a/sw/source/uibase/inc/frmpage.hxx b/sw/source/uibase/inc/frmpage.hxx index 46e9bfdb5125..f04fb4297e8c 100644 --- a/sw/source/uibase/inc/frmpage.hxx +++ b/sw/source/uibase/inc/frmpage.hxx @@ -44,6 +44,7 @@ class SwFramePage final : public SfxTabPage bool m_bFormat; bool m_bNew; bool m_bNoModifyHdl; + bool m_bIgnoreFixedRatio = false; bool m_bIsVerticalFrame; //current frame is in vertical environment - strings are exchanged // #mongolianlayout# bool m_bIsVerticalL2R;