From 25da629e34fca5473452cbf696db3feb7ab2538d Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 18 May 2017 15:03:20 +0000 Subject: [PATCH] fpspreadsheet: Allow writing duplicate filler palette entries like in the built-in Excel colors git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5867 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../fpspreadsheet/source/common/xlsbiff5.pas | 9 ++++++- .../fpspreadsheet/source/common/xlsbiff8.pas | 25 ++++++++++++------- .../fpspreadsheet/source/common/xlscommon.pas | 6 +++-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/components/fpspreadsheet/source/common/xlsbiff5.pas b/components/fpspreadsheet/source/common/xlsbiff5.pas index 3a71a6bea..6ed1a580e 100644 --- a/components/fpspreadsheet/source/common/xlsbiff5.pas +++ b/components/fpspreadsheet/source/common/xlsbiff5.pas @@ -1230,6 +1230,11 @@ begin SetLength(sheetPos, 0); end; +{@@ ---------------------------------------------------------------------------- + Populates the palette of the writer with the colors used by the workbook. + BIFF8 begins with the 8 default colors which are duplicated. Then the user + colors follow up to a max of total 64 entries. +-------------------------------------------------------------------------------} procedure TsSpreadBIFF5Writer.PopulatePalette(AWorkbook: TsWorkbook); var i: Integer; @@ -1240,7 +1245,9 @@ begin // Fill up Excel colors of the standard palette to avoid empty color // place holders in Excel's colordialog. for i := 16 to High(PALETTE_BIFF5) do - FPalette.AddUniqueColor(PALETTE_BIFF5[i]); + FPalette.AddColor(PALETTE_BIFF5[i]); + // The BIFF5 palette contains duplicate colors -> don't use AddUniqueColor +// FPalette.AddUniqueColor(PALETTE_BIFF5[i]); end; {@@ ---------------------------------------------------------------------------- diff --git a/components/fpspreadsheet/source/common/xlsbiff8.pas b/components/fpspreadsheet/source/common/xlsbiff8.pas index d5aee35f3..ba60c1fa4 100644 --- a/components/fpspreadsheet/source/common/xlsbiff8.pas +++ b/components/fpspreadsheet/source/common/xlsbiff8.pas @@ -211,14 +211,14 @@ var $FF00FF, // $06: magenta $00FFFF, // $07: cyan - $000000, // $08: EGA black 1 - $FFFFFF, // $09: EGA white 2 - $FF0000, // $0A: EGA red 3 - $00FF00, // $0B: EGA green 4 - $0000FF, // $0C: EGA blue 5 - $FFFF00, // $0D: EGA yellow 6 - $FF00FF, // $0E: EGA magenta 7 pink - $00FFFF, // $0F: EGA cyan 8 turqoise + $000000, // $08: EGA black 1 + $FFFFFF, // $09: EGA white 2 + $FF0000, // $0A: EGA red 3 + $00FF00, // $0B: EGA green 4 + $0000FF, // $0C: EGA blue 5 + $FFFF00, // $0D: EGA yellow 6 + $FF00FF, // $0E: EGA magenta 7 pink + $00FFFF, // $0F: EGA cyan 8 turqoise $800000, // $10=16: EGA dark red 9 $008000, // $11=17: EGA dark green 10 @@ -2226,6 +2226,11 @@ begin SetLength(sheetPos, 0); end; +{@@ ---------------------------------------------------------------------------- + Populates the palette of the writer with the colors used by the workbook. + BIFF8 begins with the 8 default colors which are duplicated. Then the user + colors follow up to a max of total 64 entries. +-------------------------------------------------------------------------------} procedure TsSpreadBIFF8Writer.PopulatePalette(AWorkbook: TsWorkbook); var i: Integer; @@ -2236,7 +2241,9 @@ begin // Fill up Excel colors of the standard palette to avoid empty color // place holders in Excel's colordialog. for i := 16 to High(PALETTE_BIFF8) do - FPalette.AddUniqueColor(PALETTE_BIFF8[i]); + FPalette.AddColor(PALETTE_BIFF8[i]); + // The BIFF8 palette contains duplicate colors -> don't use AddUniqueColor +// FPalette.AddUniqueColor(PALETTE_BIFF8[i]); end; {@@ ---------------------------------------------------------------------------- diff --git a/components/fpspreadsheet/source/common/xlscommon.pas b/components/fpspreadsheet/source/common/xlscommon.pas index 3860d7464..d372ab33b 100644 --- a/components/fpspreadsheet/source/common/xlscommon.pas +++ b/components/fpspreadsheet/source/common/xlscommon.pas @@ -3853,11 +3853,13 @@ end; {@@ ---------------------------------------------------------------------------- Writes the PALETTE record for the color palette. - Valid for BIFF3-BIFF8. BIFF2 has no palette in the file. + Valid for BIFF3-BIFF8. BIFF2 has no palette in the file, i.e. WritePalette is + not called. -------------------------------------------------------------------------------} procedure TsSpreadBIFFWriter.WritePalette(AStream: TStream); const NUM_COLORS = 56; + MAX_PALETTE = NUM_COLORS + 8 - 1; var i, n: Integer; rgb: TsColor; @@ -3872,7 +3874,7 @@ begin n := FPalette.Count; { Skip the first 8 entries - they are hard-coded into Excel } - for i := 8 to 8 + NUM_COLORS - 1 do + for i := 8 to MAX_PALETTE do begin rgb := Math.IfThen(i < n, FPalette[i], $FFFFFF); AStream.WriteDWord(DWordToLE(rgb))