Plotly.NET
Plotly.NET copied to clipboard
load a custom font from file (ttf, woff, ...others)
Description
Currently only installed fonts are available for styling charts, it would be very helpful to load custom fonts from its source such as TTF, WOFF fonts (other formats are also welcome).
Repro steps
I created a c# project using dotnet8, plptly.net 4.2, Plotly.NET.ImageExport 5.0.1, this is the code for a basic chart:
` // Creating a bar trace Plotly.NET.Trace barTrace = new Plotly.NET.Trace("bar");
barTrace.SetValue("name", "cantidad n");
barTrace.SetValue("x", xValues);
barTrace.SetValue("y", yValues);
// Creating a layout
LinearAxis xAxis = new LinearAxis();
xAxis.SetValue("title", "xAxis");
xAxis.SetValue("zerolinecolor", "#ffff");
xAxis.SetValue("gridcolor", "#ffff");
xAxis.SetValue("showline", true);
xAxis.SetValue("zerolinewidth", 2);
LinearAxis yAxis = new LinearAxis();
yAxis.SetValue("title", "yAxis");
yAxis.SetValue("zerolinecolor", "#ffff");
yAxis.SetValue("gridcolor", "#ffff");
yAxis.SetValue("showline", true);
yAxis.SetValue("zerolinewidth", 2);
Layout layout = new Layout();
layout.SetValue("xaxis", xAxis);
layout.SetValue("yaxis", yAxis);
layout.SetValue("title", "A Figure Specified by DynamicObj");
layout.SetValue("paper_bgcolor", "#00000000");
layout.SetValue("plot_bgcolor", "#00000000");
//layout.SetValue("font", Font.init(Family:FontFamily.NewCustom("Poppins")));
//layout.SetValue("font", Font.init(Family:FontFamily.NewCustom("DejaVu Serif")));
layout.SetValue("showlegend", true);
Config config = new Config();
config.SetValue("plot_bgcolor", "#00000000");
GenericChart
.ofTraceObject(true, barTrace)
.WithLayout(layout)
.WithConfig(config)
.ToSVGString()
`
*. in a windows environment there is no trouble to get the chart with its labels
*. In a linux environment there are no labels, instead empty squares
Expected behavior
It would be very useful to load an arbitrary font from its source file, similar to a Font-face setting in a web page.
for instance: layout.SetValue("font", Font.init(Family:FontFamily.NewCustom("DejaVu Serif", "font_file_path")))
Related information
- Operating system: Windows 11, Debian Linux 12
- Branch
- .NET Runtime 8 LTS
- Performance information, links to performance testing scripts