From b5c56326686500a6d0d71508abdeb62eb7628502 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 22 Mar 2022 10:11:23 +0000 Subject: [PATCH] fpspreadsheet: Fix incorrect row height when row switches from hidden to visible (https://forum.lazarus.freepascal.org/index.php?topic=58792.msg438138#msg438138). git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8218 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../source/visual/fpspreadsheetgrid.pas | 40 ++++++++++--------- .../source/visual/fpsvisualutils.pas | 8 +++- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas index 6224a044f..f3455bd85 100644 --- a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas @@ -5967,26 +5967,30 @@ begin if h = 0 then h := DefaultRowHeight; // Zoom factor is applied by getter function end; - end else + end; + // No row record so far. - if Worksheet.GetCellCountInRow(sr) > 0 then + if lRow = nil then begin - // Case 1: This row does contain cells - lRow := Worksheet.AddRow(sr); - if AEnforceCalcRowHeight then - h := CalcAutoRowHeight(ARow) - else - h := DefaultRowHeight; - lRow^.Height := CalcRowHeightToSheet(round(h / ZoomFactor)); - if h <> DefaultRowHeight then - lRow^.RowHeightType := rhtAuto - else - lRow^.RowHeightType := rhtDefault; - if h = 0 then - h := DefaultRowHeight; // Zoom factor is applied by getter function - end else - // Case 2: No cells in row - h := DefaultRowHeight; // Zoom factor is applied by getter function + if Worksheet.GetCellCountInRow(sr) > 0 then + begin + // Case 1: This row does contain cells + lRow := Worksheet.AddRow(sr); + if AEnforceCalcRowHeight then + h := CalcAutoRowHeight(ARow) + else + h := DefaultRowHeight; + lRow^.Height := CalcRowHeightToSheet(round(h / ZoomFactor)); + if h <> DefaultRowHeight then + lRow^.RowHeightType := rhtAuto + else + lRow^.RowHeightType := rhtDefault; + if h = 0 then + h := DefaultRowHeight; // Zoom factor is applied by getter function + end else + // Case 2: No cells in row + h := DefaultRowHeight; // Zoom factor is applied by getter function + end; end; inc(FZoomLock); // We don't want to modify the sheet row heights here. diff --git a/components/fpspreadsheet/source/visual/fpsvisualutils.pas b/components/fpspreadsheet/source/visual/fpsvisualutils.pas index 84b919c10..a105a520f 100644 --- a/components/fpspreadsheet/source/visual/fpsvisualutils.pas +++ b/components/fpspreadsheet/source/visual/fpsvisualutils.pas @@ -326,9 +326,10 @@ function RichTextWidth(ACanvas: TCanvas; AWorkbook: TsWorkbook; ARect: TRect; var painter: TsTextPainter; begin + // In contrast to RichTextHeight, the next two lines have no effect on col + // width when a column switches from hidden to visible. if (ARect.Left = ARect.Right) or (ARect.Top = ARect.Bottom) then exit(0); - painter := TsTextPainter.Create(ACanvas, AWorkbook, ARect, AText, ARichTextParams, AFontIndex, ATextRotation, haLeft, vaTop, AWordWrap, ARightToLeft, AZoomFactor); try @@ -345,9 +346,12 @@ function RichTextHeight(ACanvas: TCanvas; AWorkbook: TsWorkbook; ARect: TRect; var painter: TsTextPainter; begin + { -- causes incorrect row height, when row switches from hidden to visible. + // see: https://forum.lazarus.freepascal.org/index.php/topic,58792.msg438090.html#msg438090 + if (ARect.Left = ARect.Right) or (ARect.Top = ARect.Bottom) then exit(0); - + } painter := TsTextPainter.Create(ACanvas, AWorkbook, ARect, AText, ARichTextParams, AFontIndex, ATextRotation, haLeft, vaTop, AWordWrap, ARightToLeft, AZoomFactor); try