[LyX/2.5.x] Fix cell background drawing for non-centered aligned cells
Juergen Spitzmueller
spitz at lyx.org
Thu May 7 15:12:58 UTC 2026
commit 041194f54df398f9b3fa12c5326e9da7c8ea94a5
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Thu May 7 13:05:11 2026 +0200
Fix cell background drawing for non-centered aligned cells
(cherry picked from commit d470d4224baed5ee84b24cbbef4e2fd2d7c4d7aa)
---
src/insets/InsetTabular.cpp | 27 +++++++++++++++++++++++++--
src/insets/InsetTabular.h | 4 ++++
status.25x | 2 ++
3 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index 0560a48815..033e5c6dca 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -1333,7 +1333,7 @@ int Tabular::cellWidth(idx_type cell) const
int w = 0;
col_type const span = columnSpan(cell);
col_type const col = cellColumn(cell);
- for(col_type c = col; c < col + span ; ++c)
+ for (col_type c = col; c < col + span ; ++c)
w += column_info[c].width;
return w;
}
@@ -4978,7 +4978,29 @@ void InsetTableCell::draw(PainterInfo & pi, int x, int y) const
int const w = width;
int const h = mr_rows * (tm.height() + 2 * topOffset(pi.base.bv) + bottomOffset(pi.base.bv) + Painter::thin_line);
int const yframe = y - mr_rows * (tm.ascent()) - mr_rows * (Painter::thin_line) - topOffset(pi.base.bv);
- int const xframe = (isVarwidth) ? x : x - (w - tm.width()) / 2 + leftOffset(pi.base.bv);
+ // xframe depends on alignment if not varwidth
+ int xframe = x;
+ switch (contentAlign) {
+ case LYX_ALIGN_CENTER:
+ xframe = (isVarwidth) ? x
+ : x - text_h_offset;
+ break;
+ case LYX_ALIGN_NONE:
+ case LYX_ALIGN_BLOCK:
+ case LYX_ALIGN_LEFT:
+ xframe = x - leftOffset(pi.base.bv);
+ break;
+ case LYX_ALIGN_RIGHT:
+ xframe = (isVarwidth) ? x + rightOffset(pi.base.bv) + Painter::thin_line
+ : x - text_h_offset;
+ break;
+ case LYX_ALIGN_DECIMAL:
+ xframe = x - text_h_offset;
+ break;
+ case LYX_ALIGN_LAYOUT:
+ case LYX_ALIGN_SPECIAL:
+ break;
+ }
if (pi.full_repaint)
pi.pain.fillRectangle(xframe, yframe, w, h,
@@ -5340,6 +5362,7 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const
drawCellLines(pi, nx, yy, r, idx);
nx += tabular.cellWidth(idx);
pi.selected = original_selection_state;
+ tabular.cell_info[r][c].inset->setTextHOffset(tabular.textHOffset(tabular.cellIndex(r, c)));
tabular.cell_info[r][c].inset->setWidth(tabular.cellWidth(tabular.cellIndex(r, c)));
}
diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h
index b385ba8346..ffb489c1f2 100644
--- a/src/insets/InsetTabular.h
+++ b/src/insets/InsetTabular.h
@@ -84,6 +84,8 @@ public:
///
void setWidth(int i) { width = i; }
///
+ void setTextHOffset(int i) { text_h_offset = i; }
+ ///
void setContentAlignment(LyXAlignment al) { contentAlign = al; }
///
void setBackgroundColor(std::string const & col) { background_color = col; }
@@ -151,6 +153,8 @@ private:
///
int width = 0;
///
+ int text_h_offset = 0;
+ ///
bool isCaptionRow = false;
///
LyXAlignment contentAlign = LYX_ALIGN_CENTER;
diff --git a/status.25x b/status.25x
index a5fb4c3716..884e4fef2c 100644
--- a/status.25x
+++ b/status.25x
@@ -76,6 +76,8 @@ What's new
- Fix casing of strings in English localization (bug 13304).
+- Fix background color drawing for non-center aligned tabular cells.
+
* INTERNALS
More information about the lyx-cvs
mailing list