From 289d74c7bb84288dd81c5c1b504035fd33385f9b Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sat, 3 Feb 2024 10:17:21 +0000 Subject: [PATCH] fpspreadsheet: Fix xlsx chart reader sometimes ignoring colors. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9203 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/other/chart/write_demos.lpg | 5 + .../source/common/xlsxooxmlchart.pas | 99 ++++++++++--------- 2 files changed, 57 insertions(+), 47 deletions(-) diff --git a/components/fpspreadsheet/examples/other/chart/write_demos.lpg b/components/fpspreadsheet/examples/other/chart/write_demos.lpg index 742022d7d..1c328c638 100644 --- a/components/fpspreadsheet/examples/other/chart/write_demos.lpg +++ b/components/fpspreadsheet/examples/other/chart/write_demos.lpg @@ -2,6 +2,11 @@ + + + + + diff --git a/components/fpspreadsheet/source/common/xlsxooxmlchart.pas b/components/fpspreadsheet/source/common/xlsxooxmlchart.pas index b6e4f3793..e897e81a3 100644 --- a/components/fpspreadsheet/source/common/xlsxooxmlchart.pas +++ b/components/fpspreadsheet/source/common/xlsxooxmlchart.pas @@ -211,7 +211,7 @@ function HTMLColorStr(AValue: TsColor): string; var rgb: TRGBA absolute AValue; begin - Result := Lowercase(Format('%.2x%.2x%.2x', [rgb.r, rgb.g, rgb.b])); + Result := Format('%.2x%.2x%.2x', [rgb.r, rgb.g, rgb.b]); end; @@ -587,62 +587,63 @@ var n: Integer; child: TDOMNode; begin - if ANode = nil then - exit; - - nodeName := ANode.NodeName; - case nodeName of - 'a:schemeClr': - begin - s := GetAttrValue(ANode, 'val'); - if (s <> '') then + while Assigned(ANode) do + begin + nodeName := ANode.NodeName; + case nodeName of + 'a:schemeClr': begin - idx := FColors.IndexOf(ColorAlias(s)); - if idx > -1 then + s := GetAttrValue(ANode, 'val'); + if (s <> '') then begin - AColor := FColors.Data[idx]; - child := ANode.FirstChild; - while Assigned(child) do + idx := FColors.IndexOf(ColorAlias(s)); + if idx > -1 then begin - nodeName := child.NodeName; - s := GetAttrValue(child, 'val'); - case nodeName of - 'a:tint': - if TryStrToInt(s, n) then - AColor := TintedColor(AColor, n/FACTOR_MULTIPLIER); - 'a:lumMod': // luminance modulated - if TryStrToInt(s, n) then - AColor := LumModColor(AColor, n/FACTOR_MULTIPLIER); - 'a:lumOff': - if TryStrToInt(s, n) then - AColor := LumOffsetColor(AColor, n/FACTOR_MULTIPLIER); - 'a:alpha': - if TryStrToInt(s, n) then - Alpha := n / 100000; + AColor := FColors.Data[idx]; + child := ANode.FirstChild; + while Assigned(child) do + begin + nodeName := child.NodeName; + s := GetAttrValue(child, 'val'); + case nodeName of + 'a:tint': + if TryStrToInt(s, n) then + AColor := TintedColor(AColor, n/FACTOR_MULTIPLIER); + 'a:lumMod': // luminance modulated + if TryStrToInt(s, n) then + AColor := LumModColor(AColor, n/FACTOR_MULTIPLIER); + 'a:lumOff': + if TryStrToInt(s, n) then + AColor := LumOffsetColor(AColor, n/FACTOR_MULTIPLIER); + 'a:alpha': + if TryStrToInt(s, n) then + Alpha := n / 100000; + end; + child := child.NextSibling; end; - child := child.NextSibling; end; end; end; - end; - 'a:srgbClr': - begin - s := GetAttrValue(ANode, 'val'); - if s <> '' then - AColor := HTMLColorStrToColor(s); - child := ANode.FirstChild; - while Assigned(child) do + 'a:srgbClr': begin - nodeName := child.NodeName; - s := GetAttrValue(child, 'val'); - case nodeName of - 'a:alpha': - if TryStrToInt(s, n) then - Alpha := n / FACTOR_MULTIPLIER; + s := GetAttrValue(ANode, 'val'); + if s <> '' then + AColor := HTMLColorStrToColor(s); + child := ANode.FirstChild; + while Assigned(child) do + begin + nodeName := child.NodeName; + s := GetAttrValue(child, 'val'); + case nodeName of + 'a:alpha': + if TryStrToInt(s, n) then + Alpha := n / FACTOR_MULTIPLIER; + end; + child := child.NextSibling; end; - child := child.NextSibling; end; - end; + end; + ANode := ANode.NextSibling; end; end; @@ -3235,12 +3236,16 @@ begin Result := Format( indent + '<%0:s sz="%d" spc="-1" %s%s%s%s>' + LE + + indent + ' ' + LE + + indent + ' ' + LE + + indent + ' ' + LE + indent + ' ' + LE + indent + '', [ ANodeName, round(AFont.Size * 100), bold, italic, strike, underline, + HTMLColorStr(AFont.Color), fontName ] );