Skip to content

Demo: show how to use a custom font #3722

@kebox7

Description

@kebox7

How can I use my own fonts in ScottPlot, which are located in application resources? For example, there is the PDFsharp library. It has a font substitution mechanism that allows you to get a font in any available way. It looks something like this (very simplified):

using Avalonia.Platform;
using PdfSharp.Fonts;

namespace TestApp.Main;

internal sealed partial class PdfDocument {
    private sealed class CustomFontResolver : IFontResolver {
        public byte[]? GetFont(string faceName) {
            using (var memory = new MemoryStream()) {
                using (var asset = AssetLoader.Open(new Uri(faceName))) {
                    asset.CopyTo(memory);
                    memory.Position = 0;
                    return memory.ToArray();
                }
            }
        }

        public FontResolverInfo? ResolveTypeface(string familyName, bool isBold, bool isItalic) =>
            new($"avares://TestApp.Fonts/Assets/NotoSans-{(isBold ? "Bold" : "Regular")}.ttf");
    }
}

Is there something similar for ScottPlot?

ScottPlot Version: 5.0.25

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions