Skip to content

Fonts: Extend styling options (weight, slant, density, etc.)#5013

Merged
swharden merged 14 commits intoScottPlot:mainfrom
aespitia:feature/aespitia/font-selection-updates
Aug 7, 2025
Merged

Fonts: Extend styling options (weight, slant, density, etc.)#5013
swharden merged 14 commits intoScottPlot:mainfrom
aespitia:feature/aespitia/font-selection-updates

Conversation

@aespitia
Copy link
Contributor

@aespitia aespitia commented Jul 30, 2025

This is a branch from #4873, where @Christoph-Wagner added support for more specialized fonts. Historically, the font resolver would only default to "Normal" or "Regular" width fonts, and would not appropriately find Condensed and other font widths. This PR updates that PR with some notes/feedback from @swharden in order to make primitive types

Sample usage with a system installed font

ScottPlot.Plot myPlot = new();
myPlot.Font.SetExact("Arial Narrow", FontWeight.Normal, FontSlant.Upright, FontWidth.Condensed);
myPlot.SavePng("bug.png");

using Arial Narrow

image

@aespitia aespitia changed the title Feature/aespitia/font selection updates feat: font resolver updates Jul 30, 2025
@swharden swharden changed the title feat: font resolver updates Fonts: Extend styling options (weight, slant, density, etc.) Jul 30, 2025
@swharden
Copy link
Member

swharden commented Aug 7, 2025

FYI I'm updating the demos to use Calibri because Arial Narrow isn't working with bold and italic on my system. Weird!

@swharden
Copy link
Member

swharden commented Aug 7, 2025

I'm also thinking SKFontStyleWidth may not be supported... it's not doing anything on my system, and there's not much on google images demonstrating it

myPlot.Font.Set("Segoe UI", spacing: FontSpacing.Expanded); // apply to many existing plot labels
myPlot.Title("Hello, World");

FontSpacing[] spacings = [FontSpacing.ExtraCondensed, FontSpacing.Condensed,
    FontSpacing.Normal, FontSpacing.Expanded, FontSpacing.UltraExpanded];

for (int i = 0; i < spacings.Length; i++)
{
    FontSpacing spacing = spacings[i];
    myPlot.Font.Set("Segoe UI", spacing: spacing); // apply to new labels
    var text = myPlot.Add.Text($"FontSpacing.{spacing}", 0, i);
    text.LabelFontSize = 18;
}

myPlot.Axes.SetLimits(-1, 5, -1, spacings.Length);
myPlot.HideGrid();
image

@swharden
Copy link
Member

swharden commented Aug 7, 2025

Thanks @aespitia and @Christoph-Wagner! I'm merging this now.

I added a few cookbook recipes like this too:

image

@swharden swharden merged commit 3da4cc9 into ScottPlot:main Aug 7, 2025
3 checks passed
@aespitia aespitia deleted the feature/aespitia/font-selection-updates branch August 8, 2025 13:23
@swharden
Copy link
Member

Hey @aespitia, a quick comment about this solution... I don't think we should store much plot-specific state in the static Fonts class because processes with generate tons of plots (e.g., the cookbook) get broken when one plot changes the default options, then all the subsequent new plots have different styles.

I haven't figured it out exactly yet, but I'm going to try to move that default style state into the Plot... or add a ResetDefaults() and call it before every cookbook recipe. It's probably a niche case, but it would be nice to solve it elegantly.

I welcome any suggestions you may have about the best way to go about this! You don't need to come up with a PR - I'll make a quick fix so I can publish new packages tonight and we can refine this behavior if/as needed.

Thanks!
Scott

@swharden
Copy link
Member

Hey @aespitia, I implemented the Reset() approach in #5048 but now I see the same issue affects default Legend style 😅

I'll squeeze in a Reset() there too, then later we can figure out a way to tie these defaults to the Plot instead of at the static ScottPlot level 👍

@swharden
Copy link
Member

swharden commented Aug 17, 2025

Typical me, I commented before thorough investigation and got my assessment wrong. Sorry for the noise about legends! There is an issue (see MarkerLegend cookbook recipe below) but I don't think it's related to static storage of defaults

More info here: #5006 (comment)

@aespitia
Copy link
Contributor Author

Typical me, I commented before thorough investigation and got my assessment wrong. Sorry for the noise about legends! There is an issue (see MarkerLegend cookbook recipe below) but I don't think it's related to static storage of defaults

More info here: #5006 (comment)

I think this PR has some good updates, but not sure if it fixes whatever issue you saw?

#5031

Are you talking about the legend items changing from rectangles to circles? from looking at the code before, it looked like for that particular graph type, the default should have been circles originally, but were rendering as rectangles. I think i had looked at the implementation of that particular plot type, and it seemed like it was adding FilledCircle as the legend marker type. So, I do think there was a change, but I think the rectangle was bugged before if you're looking at before and after?

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.

3 participants