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 808c4969a8bb8a53fce2b4276e06f864671c982e Author: Miklos Vajna <[email protected]> AuthorDate: Fri May 24 12:06:55 2024 +0200 Commit: Mike Kaganski <[email protected]> CommitDate: Mon Feb 2 15:51:04 2026 +0500 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 <[email protected]> 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 36de1876bdd9..20caf0133c7e 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 8a7ec8d4ffe0..73e9f5b4ed4f 100644 --- a/sw/source/ui/frmdlg/frmpage.cxx +++ b/sw/source/ui/frmdlg/frmpage.cxx @@ -2167,7 +2167,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()) { @@ -2370,14 +2370,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 6f05ca1d651a..66c3f37910e6 100644 --- a/sw/source/uibase/inc/frmpage.hxx +++ b/sw/source/uibase/inc/frmpage.hxx @@ -43,6 +43,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;
