Repository: qax-os/excelize

Issue:
Not able to specify font family on the title of a chart
### Description

When I specify the font family for the title on a chart then I am getting a nil pointer exception:

...
Title:     []excelize.RichTextRun{{Text: "Test", Font: &excelize.Font{Size: 11, Family: "Aptos"}}},
...

For me it looks like the problem is here:

```
diff --git a/drawing.go b/drawing.go
index 7241dac..8c336f2 100644
--- a/drawing.go
+++ b/drawing.go
@@ -1198,6 +1198,9 @@ func drawChartFont(fnt *Font, r *aRPr) {
                r.SolidFill.SrgbClr = &attrValString{Val: stringPtr(strings.ReplaceAll(strings.ToUpper(fnt.Color), "#", ""))}
        }
        if fnt.Family != "" {
+               if r.Latin == nil {
+                       r.Latin = &xlsxCTTextFont{}
+               }
                r.Latin.Typeface = fnt.Family
        }
        if fnt.Size > 0 {
```

### Steps to reproduce the issue

Add Family parameter to title of a chart

### Describe the results you received

Getting a nil pointer exception

### Describe the results you expected

No exceptions

### Go version

1.24

### Excelize version or commit ID

2.9.0

### Environment

```shell
Linux
```

### Validations

- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [x] The provided reproduction is a minimal reproducible example of the bug.

Discussion:
@xuri: Thanks for your issue. This issue has been fixed, please upgrade to the master branch code by `go get -u github.com/xuri/excelize/v2@master`, and this patch will be released in the next version.

Solution patch:
diff --git a/drawing.go b/drawing.go
index 7241dac..8c336f2 100644
--- a/drawing.go
+++ b/drawing.go
@@ -1198,6 +1198,9 @@ func drawChartFont(fnt *Font, r *aRPr) {
 		r.SolidFill.SrgbClr = &attrValString{Val: stringPtr(strings.ReplaceAll(strings.ToUpper(fnt.Color), "#", ""))}
 	}
 	if fnt.Family != "" {
+		if r.Latin == nil {
+			r.Latin = &xlsxCTTextFont{}
+		}
 		r.Latin.Typeface = fnt.Family
 	}
 	if fnt.Size > 0 {



Test patch:
diff --git a/chart_test.go b/chart_test.go
index 1527bc7..42e2a65 100644
--- a/chart_test.go
+++ b/chart_test.go
@@ -219,7 +219,7 @@ func TestAddChart(t *testing.T) {
 		sheetName, cell string
 		opts            *Chart
 	}{
-		{sheetName: "Sheet1", cell: "P1", opts: &Chart{Type: Col, Series: series, Format: format, Legend: ChartLegend{Position: "none", ShowLegendKey: true}, Title: []RichTextRun{{Text: "2D Column Chart"}}, PlotArea: plotArea, Border: ChartLine{Type: ChartLineNone}, ShowBlanksAs: "zero", XAxis: ChartAxis{Font: Font{Bold: true, Italic: true, Underline: "dbl", Family: "Times New Roman", Size: 15, Strike: true, Color: "000000"}, Title: []RichTextRun{{Text: "Primary Horizontal Axis Title"}}}, YAxis: ChartAxis{Font: Font{Bold: false, Italic: false, Underline: "sng", Color: "777777"}, Title: []RichTextRun{{Text: "Primary Vertical Axis Title", Font: &Font{Color: "777777", Bold: true, Italic: true, Size: 12}}}}}},
+		{sheetName: "Sheet1", cell: "P1", opts: &Chart{Type: Col, Series: series, Format: format, Legend: ChartLegend{Position: "none", ShowLegendKey: true}, Title: []RichTextRun{{Text: "2D Column Chart", Font: &Font{Size: 11, Family: "Calibri"}}}, PlotArea: plotArea, Border: ChartLine{Type: ChartLineNone}, ShowBlanksAs: "zero", XAxis: ChartAxis{Font: Font{Bold: true, Italic: true, Underline: "dbl", Family: "Times New Roman", Size: 15, Strike: true, Color: "000000"}, Title: []RichTextRun{{Text: "Primary Horizontal Axis Title"}}}, YAxis: ChartAxis{Font: Font{Bold: false, Italic: false, Underline: "sng", Color: "777777"}, Title: []RichTextRun{{Text: "Primary Vertical Axis Title", Font: &Font{Color: "777777", Bold: true, Italic: true, Size: 12}}}}}},
 		{sheetName: "Sheet1", cell: "X1", opts: &Chart{Type: ColStacked, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "2D Stacked Column Chart"}}, PlotArea: plotArea, Fill: Fill{Type: "pattern", Pattern: 1}, Border: ChartLine{Type: ChartLineAutomatic}, ShowBlanksAs: "zero", GapWidth: uintPtr(10), Overlap: intPtr(100)}},
 		{sheetName: "Sheet1", cell: "P16", opts: &Chart{Type: ColPercentStacked, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "100% Stacked Column Chart"}}, PlotArea: plotArea, Fill: Fill{Type: "pattern", Color: []string{"EEEEEE"}, Pattern: 1}, Border: ChartLine{Type: ChartLineSolid, Width: 2}, ShowBlanksAs: "zero", XAxis: ChartAxis{Alignment: Alignment{Vertical: "wordArtVertRtl", TextRotation: 0}}}},
 		{sheetName: "Sheet1", cell: "X16", opts: &Chart{Type: Col3DClustered, Series: series, Format: format, Legend: ChartLegend{Position: "bottom", ShowLegendKey: false}, Title: []RichTextRun{{Text: "3D Clustered Column Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}},