From b0c76b3396f32b2f1b53781a5caea084cadd94d3 Mon Sep 17 00:00:00 2001 From: John McNamara Date: Sat, 3 Feb 2024 23:42:54 +0000 Subject: [PATCH] format: fix identation and alignment property mismatch Fix issue where a horizontal alignment format was ignored if the indentation was also set. --- src/styles.c | 13 +++++--- test/functional/src/test_format24.c | 37 +++++++++++++++++++++++ test/functional/test_formatting.py | 3 ++ test/functional/xlsx_files/format24.xlsx | Bin 0 -> 7391 bytes 4 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 test/functional/src/test_format24.c create mode 100644 test/functional/xlsx_files/format24.xlsx diff --git a/src/styles.c b/src/styles.c index d2cb71e5..5aadfbdf 100644 --- a/src/styles.c +++ b/src/styles.c @@ -1045,13 +1045,16 @@ _write_alignment(lxw_styles *self, lxw_format *format) LXW_INIT_ATTRIBUTES(); - /* Indent is only allowed for horizontal left, right and distributed. */ + /* Indent is only allowed for some alignment properties. */ /* If it is defined for any other alignment or no alignment has been */ /* set then default to left alignment. */ if (format->indent && format->text_h_align != LXW_ALIGN_LEFT && format->text_h_align != LXW_ALIGN_RIGHT - && format->text_h_align != LXW_ALIGN_DISTRIBUTED) { + && format->text_h_align != LXW_ALIGN_DISTRIBUTED + && format->text_v_align != LXW_ALIGN_VERTICAL_TOP + && format->text_v_align != LXW_ALIGN_VERTICAL_BOTTOM + && format->text_v_align != LXW_ALIGN_VERTICAL_DISTRIBUTED) { format->text_h_align = LXW_ALIGN_LEFT; } @@ -1110,9 +1113,6 @@ _write_alignment(lxw_styles *self, lxw_format *format) if (format->text_v_align == LXW_ALIGN_VERTICAL_DISTRIBUTED) LXW_PUSH_ATTRIBUTES_STR("vertical", "distributed"); - if (format->indent) - LXW_PUSH_ATTRIBUTES_INT("indent", format->indent); - /* Map rotation to Excel values. */ if (rotation) { if (rotation == 270) @@ -1123,6 +1123,9 @@ _write_alignment(lxw_styles *self, lxw_format *format) LXW_PUSH_ATTRIBUTES_INT("textRotation", rotation); } + if (format->indent) + LXW_PUSH_ATTRIBUTES_INT("indent", format->indent); + if (format->text_wrap) LXW_PUSH_ATTRIBUTES_STR("wrapText", "1"); diff --git a/test/functional/src/test_format24.c b/test/functional/src/test_format24.c new file mode 100644 index 00000000..10d6a0ee --- /dev/null +++ b/test/functional/src/test_format24.c @@ -0,0 +1,37 @@ +/***************************************************************************** + * Test cases for libxlsxwriter. + * + * Test to compare output against Excel files. + * + * Copyright 2014-2024, John McNamara, jmcnamara@cpan.org + * + */ + +#include "xlsxwriter.h" + +int main() { + + lxw_workbook *workbook = workbook_new("test_format24.xlsx"); + lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); + + lxw_format *format1 = workbook_add_format(workbook); + + /* + 'rotation': 270, + 'indent': 1, + 'align': "center", + 'valign': "top" + */ + + + format_set_rotation(format1, 270); + format_set_indent(format1, 1); + format_set_align(format1, LXW_ALIGN_CENTER); + format_set_align(format1, LXW_ALIGN_VERTICAL_TOP); + + worksheet_set_row(worksheet, 0, 75, NULL); + + worksheet_write_string(worksheet, 0, 0, "ABCD", format1); + + return workbook_close(workbook); +} diff --git a/test/functional/test_formatting.py b/test/functional/test_formatting.py index 4807f0b8..077a83f5 100644 --- a/test/functional/test_formatting.py +++ b/test/functional/test_formatting.py @@ -49,6 +49,9 @@ class TestCompareXLSXFiles(base_test_class.XLSXBaseTest): def test_format18(self): self.run_exe_test('test_format18') + def test_format24(self): + self.run_exe_test('test_format24') + def test_format50(self): self.run_exe_test('test_format50') diff --git a/test/functional/xlsx_files/format24.xlsx b/test/functional/xlsx_files/format24.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..2e3117b250e771bc7abfe1108f1a81ee777e6663 GIT binary patch literal 7391 zcmeHMg;!Kt-=3jEQc7XymXcONS~>+uWq<*c?hue}=}rkL1w>L1bO1?d7?2^Qn-Lfq z-qCyC8(hDC;Qj8NHD|9`=RChPd++C0&(Tyt#~=e>0dN2S00UsddpOYy2mr)k007qk zQ$QnG2YXkDz3bx#UXBnK6CO`HTl)M7Ap1)I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