Skip to content

Label.Typeface#4043

Merged
swharden merged 4 commits intomainfrom
3830
Jul 5, 2024
Merged

Label.Typeface#4043
swharden merged 4 commits intomainfrom
3830

Conversation

@swharden
Copy link
Member

@swharden swharden commented Jul 5, 2024

Adds SKTypeface? Typeface property to Label, LabelStyle, and Legend allowing objects with text to be supplied a custom typeface. This strategy works for automatically generated and manually added legend items too.

SKTypeface customTypeface = SKTypeface.FromFile(ttfFilePath);

plot.Legend.ManualItems.Add(new LegendItem()
{
    LabelText = "Manual Item",
    LabelFontColor = Colors.Blue,
    LabelFontSize = 26,
    LabelTypeface = customTypeface,
});

image

@swharden swharden enabled auto-merge (squash) July 5, 2024 20:31
@swharden swharden merged commit 3ec6481 into main Jul 5, 2024
@swharden swharden deleted the 3830 branch July 5, 2024 20:34
@kebox7
Copy link
Contributor

kebox7 commented Jul 8, 2024

Hi @swharden! I'm sorry, but a similar result can be achieved using existing functionality, in particular using FileFontResolver. It seems to me that adding the Typeface property is redundant, it is an explicit regression.

[Test]
public void Test_CustomTypeface_InLegend()
{
    string ttfFilePath = Paths.GetTtfFilePaths().First();
    Fonts.AddFontFile("Font Name", ttfFilePath, bold: false, italic: false);

    // create a plot with data
    Plot plot = new();
    var sig = plot.Add.Signal(Generate.Sin());
    sig.LegendText = "Sine Wave";

    // axis label custom typeface
    plot.XLabel("Horizontal Axis Label");
    plot.Axes.Bottom.Label.ForeColor = Colors.Red;
    plot.Axes.Bottom.Label.FontSize = 26;
    plot.Axes.Bottom.Label.FontName = "Font Name";

    // manual legend items custom typeface
    plot.Legend.ManualItems.Add(new LegendItem()
    {
        LabelText = "Manual Item",
        LabelFontColor = Colors.Blue,
        LabelFontSize = 26,
        LabelFontName = "Font Name"
    });

    plot.SaveTestImage();
}

@swharden
Copy link
Member Author

swharden commented Jul 8, 2024

It seems to me that adding the Typeface property is redundant, it is an explicit regression.

Hi @kebox7, thanks for pointing this out! I'll create a new issue to see about rolling back this change and creating a test or cookbook recipe that demonstrates how to achieve this functionality with the original feature set #4057

kebox7 added a commit to kebox7/ScottPlot that referenced this pull request Jul 9, 2024
swharden added a commit that referenced this pull request Jul 21, 2024
#4060)

* rollback #4043

* Tests

* Cookbook recipe

* Artifacts in Cookbook

* Fixed an issue with incorrect font file paths in Cookbook

* Normalize line breaks

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Scott W Harden <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Legend: rendering text labels resets custom typefaces

2 participants