Table Styles: add translatable UI names for default Calc table styles

The 60 default ECMA-376 table styles had only machine IDs like
"TableStyleLight1" as their names. For Online, generateJSON() sends
GetUIName() which fell back to the raw ID. Desktop was unaffected
because the sidebar/notebookbar .ui files have hardcoded display names.

Add TableStyleCategory enum and number to the TableStyle data struct
so assembleTableStyles() can compose translatable UI names like
"Table Style Light 1" using 3 new string resources. The UI name is
computed once at style generation time and stored in maUIName.

Also fix the Python generator to handle the "TableStyleLight14 "
trailing space bug from the OOXML spec XML, and force Unix line
endings on output.

Change-Id: Ia079a1f5f6e453cb729b5c26df4fe48c88642341
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/203045
Reviewed-by: Banobe Pascal <banobe.pascal@collabora.com>
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/176
Reviewed-by: Balázs Varga <balazs.varga@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit eaa07b76ba56b39b0346c0f7b7c28b86edcb7a9e)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204567
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
Balazs Varga
2026-04-29 16:19:45 +02:00
committed by Xisco Fauli
parent 55520b9595
commit 62e3aba4cd
5 changed files with 47 additions and 4 deletions
+9
View File
@@ -68,9 +68,18 @@ struct TableStyleElement
int nDxfId;
};
enum class TableStyleCategory
{
Light,
Medium,
Dark
};
struct TableStyle
{
const char* pName;
TableStyleCategory eCategory;
int nNumber;
size_t nElements;
int pTableStyleElementIds[9];
};
+5
View File
@@ -467,4 +467,9 @@
#define STR_AUTOCALC_OFF NC_("STR_AUTOCALC_OFF", "AutoCalculate: Off\nClick to enable.")
/* Table Styles */
#define STR_TABLE_STYLE_LIGHT NC_("STR_TABLE_STYLE_LIGHT", "Table Style Light")
#define STR_TABLE_STYLE_MEDIUM NC_("STR_TABLE_STYLE_MEDIUM", "Table Style Medium")
#define STR_TABLE_STYLE_DARK NC_("STR_TABLE_STYLE_DARK", "Table Style Dark")
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+20 -1
View File
@@ -22,6 +22,8 @@
#include <document.hxx>
#include <patattr.hxx>
#include <scresid.hxx>
#include <strings.hrc>
#include <tablestyle.hxx>
#include <sc.hrc>
@@ -296,6 +298,21 @@ buildDxfPatterns(ScDocument& rDoc, const std::vector<SvxBrushItem>& rFillItems,
return aDxfPatterns;
}
TranslateId getCategoryTranslateId(TableStyleCategory eCategory)
{
switch (eCategory)
{
case TableStyleCategory::Light:
return STR_TABLE_STYLE_LIGHT;
case TableStyleCategory::Medium:
return STR_TABLE_STYLE_MEDIUM;
case TableStyleCategory::Dark:
return STR_TABLE_STYLE_DARK;
}
SAL_WARN("sc", "getCategoryTranslateId: unknown TableStyleCategory");
return {};
}
void assembleTableStyles(ScTableStyles& rTableStyles,
const std::vector<std::unique_ptr<ScPatternAttr>>& rDxfPatterns)
{
@@ -303,8 +320,10 @@ void assembleTableStyles(ScTableStyles& rTableStyles,
for (size_t i = 0; i < nTableStyles; ++i)
{
const ::TableStyle& rStyleInfo = aTableStyles[i];
OUString aUIName = ScResId(getCategoryTranslateId(rStyleInfo.eCategory)) + " "
+ OUString::number(rStyleInfo.nNumber);
auto pStyle = std::make_unique<ScTableStyle>(OUString::createFromAscii(rStyleInfo.pName),
std::optional<OUString>());
std::optional<OUString>(aUIName));
pStyle->SetOOXMLDefault(true);
for (size_t j = 0; j < rStyleInfo.nElements; ++j)
File diff suppressed because one or more lines are too long
+12 -2
View File
@@ -1,3 +1,5 @@
import re
import click
import xml.etree.ElementTree as ET
from dataclasses import dataclass
@@ -303,6 +305,9 @@ def parse_table_style(style) -> TableStyle:
elif table_style_name == "TableStyleDark4 ":
# Trim unintended trailing space
table_style_name = "TableStyleDark4"
elif table_style_name == "TableStyleLight14 ":
# Trim unintended trailing space
table_style_name = "TableStyleLight14"
return TableStyle(table_style_name, [parse_table_style_element(element, style_defs) for element in list(tableStyle)])
@@ -559,14 +564,19 @@ def dump_table_styles(table_styles: list[TableStyle], output_path: str):
for table_style in sorted(table_styles):
table_style_element_ids = ", ".join([f"{table_style_element_map[element]}" for element in table_style.elements])
table_style_element_str = f"{{ {table_style_element_ids} }}"
output.append(f"{{ \"{table_style.name}\", {len(table_style.elements)}, {table_style_element_str} }}")
# Extract category and number from the style name (e.g. "TableStyleLight1" -> Light, 1)
m = re.match(r"^TableStyle(Light|Medium|Dark)(\d+)\s*$", table_style.name)
assert m, f"Unexpected table style name: {table_style.name}"
category = f"TableStyleCategory::{m.group(1)}"
number = m.group(2)
output.append(f"{{ \"{table_style.name}\", {category}, {number}, {len(table_style.elements)}, {table_style_element_str} }}")
output_str = ", ".join(output)
table_style_str = f"constexpr TableStyle aTableStyles[] = {{ {output_str} }};\n"
content.append(table_style_str)
content.append(footer)
with open(output_path, "w") as f:
with open(output_path, "w", newline="\n") as f:
f.write("\n".join(content))