From 42cdc47554fa746baa863860143fc81fe8bb1c80 Mon Sep 17 00:00:00 2001 From: Paolo Benvenuto Date: Thu, 23 Apr 2026 14:13:12 +0200 Subject: [PATCH] tdf#92144 Enable relative font sizes in Calc cell styles Writer paragraph styles already support percentage-based (80%, 115%) and point-relative (+2pt, -4pt) font sizes for child styles inheriting from a parent. Calc cell styles lacked this despite using the same underlying SvxCharNamePage and FontSizeBox widgets. The root cause was that Calc's ScStyleDlg::PageCreated() did not pass the SVX_RELATIVE_MODE flag when creating the font tab page, so FontSizeBox::EnableRelativeMode() and EnablePtRelativeMode() were never called. The fix adds a single SfxUInt32Item(SID_FLAG_TYPE, SVX_RELATIVE_MODE) to the item set passed to the font page, matching what Writer's SwTemplateDlgController already does. No changes are needed in the core: SvxFontHeightItem::SetHeight() already pre-calculates absolute values from relative ones, and ScPatternAttr works correctly with these pre-calculated values. Fix found with the help of Claude Sonnet 4.6 extended. Change-Id: I3d759c028564a4722f96b325499ea0bfe8e4ba07 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200885 Tested-by: Jakub Trzebiatowski Tested-by: Jenkins Reviewed-by: Jakub Trzebiatowski --- sc/Module_sc.mk | 1 + sc/UITest_sc_styleui.mk | 19 ++++ sc/qa/uitest/styleui/tdf92144.py | 167 ++++++++++++++++++++++++++++++ sc/source/ui/styleui/styledlg.cxx | 5 +- 4 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 sc/UITest_sc_styleui.mk create mode 100644 sc/qa/uitest/styleui/tdf92144.py diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk index ec14b7faef51..8611b1e01ab2 100644 --- a/sc/Module_sc.mk +++ b/sc/Module_sc.mk @@ -304,6 +304,7 @@ $(eval $(call gb_Module_add_uicheck_targets,sc,\ UITest_calc_tests9 \ UITest_function_wizard \ UITest_manual_tests \ + UITest_sc_styleui \ )) ifneq ($(or $(ENABLE_LPSOLVE),$(ENABLE_COINMP)),) diff --git a/sc/UITest_sc_styleui.mk b/sc/UITest_sc_styleui.mk new file mode 100644 index 000000000000..408560d0d39a --- /dev/null +++ b/sc/UITest_sc_styleui.mk @@ -0,0 +1,19 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_UITest_UITest,sc_styleui)) +$(eval $(call gb_UITest_add_modules,sc_styleui,$(SRCDIR)/sc/qa/uitest,\ + styleui/ \ +)) +$(eval $(call gb_UITest_set_defs,sc_styleui, \ + TDOC="$(SRCDIR)/sc/qa/uitest/data" \ +)) +$(eval $(call gb_UITest_avoid_oneprocess,sc_styleui)) + +# vim: set noet sw=4 ts=4: diff --git a/sc/qa/uitest/styleui/tdf92144.py b/sc/qa/uitest/styleui/tdf92144.py new file mode 100644 index 000000000000..3756af55c4a0 --- /dev/null +++ b/sc/qa/uitest/styleui/tdf92144.py @@ -0,0 +1,167 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +"""Tests for tdf#92144 - relative font sizes in Calc cell styles.""" + +from uitest.framework import UITestCase +from uitest.uihelper.common import get_state_as_dict +from uitest.uihelper.common import select_pos +from uitest.uihelper.common import type_text +from libreoffice.uno.propertyvalue import mkPropertyValues + + +class tdf92144(UITestCase): + + def test_percentage_font_size_in_cell_style(self): + """Test that percentage font size is preserved in cell style.""" + with self.ui_test.create_doc_in_start_center("calc"): + + # Create a new cell style + with self.ui_test.execute_dialog_through_command( + ".uno:StyleNewByExample") as xDialog: + xStyleName = xDialog.getChild("stylename") + xStyleName.executeAction("CLEAR", tuple()) + type_text(xStyleName, "Test Percent Size") + + # Edit the style and set 80% + with self.ui_test.execute_blocking_action( + self.xUITest.executeCommandWithParameters, + args=(".uno:EditStyle", + mkPropertyValues({"Param": "Test Percent Size", + "Family": "CellStyles"}))) as xDialog: + + # Go to Font tab + xTabs = xDialog.getChild("tabcontrol") + select_pos(xTabs, "2") + # Set percentage + xSizeField = xDialog.getChild("cbWestSize") + xSizeField.executeAction("CLEAR", tuple()) + type_text(xSizeField, "80%") + + # Reopen the style and verify it's still 80% + with self.ui_test.execute_blocking_action( + self.xUITest.executeCommandWithParameters, + args=(".uno:EditStyle", + mkPropertyValues({"Param": "Test Percent Size", + "Family": "CellStyles"}))) as xDialog: + + # Go to Font tab + xTabs = xDialog.getChild("tabcontrol") + select_pos(xTabs, "2") + # Read the value + xSizeField = xDialog.getChild("cbWestSize") + displayed_value = get_state_as_dict(xSizeField)["Text"] + + # Verify it's still 80% (not converted to absolute value) + self.assertEqual(displayed_value, "80%", + "Percentage value was not preserved") + + def test_point_relative_font_size_in_cell_style(self): + """Test that +2pt font size is preserved in cell style.""" + with self.ui_test.create_doc_in_start_center("calc"): + + # Create a new cell style + with self.ui_test.execute_dialog_through_command( + ".uno:StyleNewByExample") as xDialog: + xStyleName = xDialog.getChild("stylename") + xStyleName.executeAction("CLEAR", tuple()) + type_text(xStyleName, "Test PtRelative Size") + + # Edit the style and set +2pt + with self.ui_test.execute_blocking_action( + self.xUITest.executeCommandWithParameters, + args=(".uno:EditStyle", + mkPropertyValues({"Param": "Test PtRelative Size", + "Family": "CellStyles"}))) as xDialog: + + # Go to Font tab + xTabs = xDialog.getChild("tabcontrol") + select_pos(xTabs, "2") + # Set +2pt + xSizeField = xDialog.getChild("cbWestSize") + xSizeField.executeAction("CLEAR", tuple()) + type_text(xSizeField, "+2pt") + + # Reopen and verify + with self.ui_test.execute_blocking_action( + self.xUITest.executeCommandWithParameters, + args=(".uno:EditStyle", + mkPropertyValues({"Param": "Test PtRelative Size", + "Family": "CellStyles"}))) as xDialog: + + # Go to Font tab + xTabs = xDialog.getChild("tabcontrol") + select_pos(xTabs, "2") + # Read the value + xSizeField = xDialog.getChild("cbWestSize") + displayed_value = get_state_as_dict(xSizeField)["Text"] + + # Verify it's still +2pt (accept both "+2pt" and "+2 pt") + self.assertIn(displayed_value.replace(" ", ""), ["+2pt"], + f"Expected '+2pt' or '+2 pt', got '{displayed_value}'") + + def test_negative_point_relative_font_size(self): + """Test that -2pt font size is preserved in cell style.""" + with self.ui_test.create_doc_in_start_center("calc"): + + # Create a new cell style + with self.ui_test.execute_dialog_through_command( + ".uno:StyleNewByExample") as xDialog: + xStyleName = xDialog.getChild("stylename") + xStyleName.executeAction("CLEAR", tuple()) + type_text(xStyleName, "Test NegRelative Size") + + # Edit the style and set -2pt + with self.ui_test.execute_blocking_action( + self.xUITest.executeCommandWithParameters, + args=(".uno:EditStyle", + mkPropertyValues({"Param": "Test NegRelative Size", + "Family": "CellStyles"}))) as xDialog: + + # Go to Font tab + xTabs = xDialog.getChild("tabcontrol") + select_pos(xTabs, "2") + # Set -2pt + xSizeField = xDialog.getChild("cbWestSize") + xSizeField.executeAction("CLEAR", tuple()) + type_text(xSizeField, "-2pt") + + # Reopen and verify + with self.ui_test.execute_blocking_action( + self.xUITest.executeCommandWithParameters, + args=(".uno:EditStyle", + mkPropertyValues({"Param": "Test NegRelative Size", + "Family": "CellStyles"}))) as xDialog: + + # Go to Font tab + xTabs = xDialog.getChild("tabcontrol") + select_pos(xTabs, "2") + # Read the value + xSizeField = xDialog.getChild("cbWestSize") + displayed_value = get_state_as_dict(xSizeField)["Text"] + + # Verify it's still -2pt (accept both "-2pt" and "-2 pt") + self.assertIn(displayed_value.replace(" ", ""), ["-2pt"], + f"Expected '-2pt' or '-2 pt', got '{displayed_value}'") + + def test_edit_root_style_relative_font_size_no_crash(self): + """Test that setting a relative font size on root Default style (no parent) does not crash.""" + with self.ui_test.create_doc_in_start_center("calc"): + with self.ui_test.execute_blocking_action( + self.xUITest.executeCommandWithParameters, + args=(".uno:EditStyle", + mkPropertyValues({"Param": "Default", + "Family": "CellStyles"}))) as xDialog: + xTabs = xDialog.getChild("tabcontrol") + select_pos(xTabs, "2") + xSizeField = xDialog.getChild("cbWestSize") + xSizeField.executeAction("CLEAR", tuple()) + type_text(xSizeField, "80%") + + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sc/source/ui/styleui/styledlg.cxx b/sc/source/ui/styleui/styledlg.cxx index bccc706c5374..2ec7734c7858 100644 --- a/sc/source/ui/styleui/styledlg.cxx +++ b/sc/source/ui/styleui/styledlg.cxx @@ -20,6 +20,7 @@ #undef SC_DLLIMPLEMENTATION #include +#include #include #include #include @@ -135,7 +136,9 @@ void ScStyleDlg::PageCreated(const OUString& rPageId, SfxTabPage& rTabPage) assert(pInfoItem && "FontListItem not found!"); - aSet.Put (SvxFontListItem(pInfoItem->GetFontList(), SID_ATTR_CHAR_FONTLIST)); + aSet.Put(SvxFontListItem(pInfoItem->GetFontList(), SID_ATTR_CHAR_FONTLIST)); + if (rTabPage.GetItemSet().GetParent()) + aSet.Put(SfxUInt32Item(SID_FLAG_TYPE, SVX_RELATIVE_MODE)); rTabPage.PageCreated(aSet); } else if (rPageId == "background")