diff --git a/components/fpspreadsheet/source/common/fpschart.pas b/components/fpspreadsheet/source/common/fpschart.pas index 4684b1593..e4ccd6f1c 100644 --- a/components/fpspreadsheet/source/common/fpschart.pas +++ b/components/fpspreadsheet/source/common/fpschart.pas @@ -3008,6 +3008,8 @@ constructor TsChart.Create; begin inherited Create(nil); + CreateRawFillPatterns; + FLineStyles := TsChartLineStyleList.Create; clsFineDot := FLineStyles.Add('fine-dot', 100, 1, 0, 0, 100, false); clsDot := FLineStyles.Add('dot', 500, 1, 0, 0, 500, true); @@ -3101,6 +3103,9 @@ begin FFillPatterns.Free; FGradients.Free; FLineStyles.Free; + + DestroyRawFillPatterns; + inherited; end; diff --git a/components/fpspreadsheet/source/common/fpsopendocumentchart.pas b/components/fpspreadsheet/source/common/fpsopendocumentchart.pas index cc61de459..08830449c 100644 --- a/components/fpspreadsheet/source/common/fpsopendocumentchart.pas +++ b/components/fpspreadsheet/source/common/fpsopendocumentchart.pas @@ -2160,11 +2160,11 @@ begin else hatchAngle := 0; - fillPatternIdx := workbook.RawFillPatterns.FindLinePatternIndex(hatchDist, hatchAngle, 0.1, patternMultiplier); + fillPatternIdx := GetRawFillPatternIndex(hatchDist, hatchAngle, 0.1, patternMultiplier); if fillPatternIdx = -1 then begin - fillPatternName := Format('LinePattern%d', [workbook.RawFillPatterns.Count]); - fillPatternIdx := workbook.RawFillPatterns.AddLineFillPattern(fillPatternName, hatchDist, hatchAngle, 0.1, patternMultiplier); + fillPatternName := Format('LinePattern%d', [GetRawFillPatternCount]); + fillPatternIdx := RegisterRawFillPattern(fillPatternName, hatchDist, hatchAngle, 0.1, patternMultiplier); end; AChart.FillPatterns.AddPattern(styleName, fillPatternIdx, hatchColor); //, bgColor); // wp: bgColor ???? end; @@ -2649,7 +2649,7 @@ begin if (AFill.Pattern < 0) or (AChart.FillPatterns.Count = 0) then exit; coloredFillPattern := AChart.FillPatterns[AFill.Pattern]; - rawFillPattern := workbook.RawFillPatterns[coloredFillPattern.Index]; + rawFillPattern := GetRawFillPattern(coloredFillPattern.Index); if Assigned(rawFillPattern.LinePattern) then begin if (AFill.Color.Transparency > 0) then @@ -3768,7 +3768,7 @@ begin for i := 0 to AChart.FillPatterns.Count-1 do begin coloredFillPattern := AChart.FillPatterns[i]; - rawFillPattern := wBook.RawFillPatterns[coloredFillPattern.Index]; + rawFillPattern := GetRawFillPattern(coloredFillPattern.Index); if Assigned(rawFillPattern.LinePattern) then begin style := Format(indent + diff --git a/components/fpspreadsheet/source/common/fpspatterns.pas b/components/fpspreadsheet/source/common/fpspatterns.pas index 57b858dfd..211d2e03d 100644 --- a/components/fpspreadsheet/source/common/fpspatterns.pas +++ b/components/fpspreadsheet/source/common/fpspatterns.pas @@ -129,6 +129,15 @@ type property Items[AIndex: Integer]: TsRawFillPattern read GetItem write SetItem; default; end; +procedure CreateRawFillPatterns; +procedure DestroyRawFillPatterns; + +function GetRawFillPattern(APatternIndex: Integer): TsRawFillPattern; +function GetRawFillPatternCount: Integer; +function GetRawFillPatternIndex(ALineDistance, ALineAngle, ALineWidth: Single; AMultiplier: TsLineFillPatternMultiplier): Integer; + +function RegisterRawFillPattern(AName: String; ALineDistance, ALineAngle, ALineWidth: Single; + AMultiplier: TsLineFillPatternMultiplier): Integer; implementation @@ -632,5 +641,71 @@ begin TsRawFillPattern(inherited Items[AIndex]).CopyFrom(AValue); end; +{ ------------------------------------------------------------------------------ + global procedures +-------------------------------------------------------------------------------} +var + RawFillPatterns: TsRawFillPatternList = nil; + RawFillPatterns_ReferenceCounter: Integer = 0; + +procedure CreateRawFillPatterns; +begin + if RawFillPatterns_ReferenceCounter = 0 then + begin + RawFillPatterns := TsRawFillPatternList.Create; + RawFillPatterns.AddBuiltinPatterns; + end; + inc(RawFillPatterns_ReferenceCounter); +end; + +procedure DestroyRawFillPatterns; +begin + dec(RawFillPatterns_ReferenceCounter); + if RawFillPatterns_ReferenceCounter <= 0 then + begin + FreeAndNil(RawfillPatterns); + RawFillPatterns_ReferenceCounter := 0; + end; +end; + +function GetRawFillPattern(APatternIndex: Integer): TsRawFillPattern; +begin + if Assigned(RawFillPatterns) then + Result := RawFillPatterns.Items[APatternIndex] + else + Result := nil; +end; + +{ Finds the index of the line fill pattern having the specified parameters. + Returns -1 if not found. } +function GetRawFillPatternIndex(ALineDistance, ALineAngle, ALineWidth: Single; + AMultiplier: TsLineFillPatternMultiplier): Integer; +begin + if Assigned(RawFillPatterns) then + Result := RawFillPatterns.FindLinePatternIndex(ALineDistance, ALineAngle, ALineWidth, AMultiplier) + else + Result := -1; +end; + +function GetRawFillPatternCount: Integer; +begin + if Assigned(RawFillPatterns) then + Result := RawFillPatterns.Count + else + Result := 0; +end; + +function RegisterRawFillPattern(AName: String; ALineDistance, ALineAngle, ALineWidth: Single; + AMultiplier: TsLineFillPatternMultiplier): Integer; +begin + if Assigned(RawFillPatterns) then + Result := RawFillPatterns.AddLineFillPattern(AName, ALineDistance, ALineAngle, ALineWidth, AMultiplier) + else + Result := -1; +end; + +finalization + FreeAndNil(RawFillPatterns); + end. diff --git a/components/fpspreadsheet/source/common/fpspreadsheet.pas b/components/fpspreadsheet/source/common/fpspreadsheet.pas index 55487c7aa..1ee3d7001 100644 --- a/components/fpspreadsheet/source/common/fpspreadsheet.pas +++ b/components/fpspreadsheet/source/common/fpspreadsheet.pas @@ -822,7 +822,6 @@ type {$ifdef FPS_CHARTS} protected FCharts: TsChartList; - FRawFillPatternList: TsRawFillPatternList; {$endif} public @@ -982,11 +981,6 @@ type {@@ Workbook metadata} property MetaData: TsMetaData read FMetaData write FMetaData; - {$ifdef FPS_CHARTS} - {@@ Raw fill patterns for charts } - property RawFillPatterns: TsRawFillPatternList read FRawFillPatternList; - {$endif} - {@@ This event fires whenever a new worksheet is added } property OnAddWorksheet: TsWorksheetEvent read FOnAddWorksheet write FOnAddWorksheet; {@@ This event fires whenever a worksheet is changed } @@ -6652,8 +6646,6 @@ begin FEmbeddedObjList := TFPList.Create; {$ifdef FPS_CHARTS} - FRawFillPatternList := TsRawFillPatternList.Create; - FRawFillPatternList.AddBuiltinPatterns; FCharts := TsChartList.Create; {$endif} @@ -6694,7 +6686,6 @@ begin FEmbeddedObjList.Free; {$ifdef FPS_CHARTS} FCharts.Free; - FRawFillPatternList.Free; {$endif} inherited Destroy; diff --git a/components/fpspreadsheet/source/common/xlsxooxmlchart.pas b/components/fpspreadsheet/source/common/xlsxooxmlchart.pas index 47ad2b437..d063ff89c 100644 --- a/components/fpspreadsheet/source/common/xlsxooxmlchart.pas +++ b/components/fpspreadsheet/source/common/xlsxooxmlchart.pas @@ -3669,7 +3669,7 @@ begin if (AFill.Pattern < 0) or (AChart.FillPatterns.Count = 0) then exit; coloredPattern := AChart.FillPatterns[AFill.Pattern]; - rawPattern := workbook.RawFillPatterns[coloredPattern.Index]; + rawPattern := GetRawFillPattern(coloredPattern.Index); // hatch := AChart.Hatches[AFill.Hatch]; presetIdx := -1; for i := 0 to High(OOXML_PATTERN_NAMES) do