KernSmith.Fonts.Web 0.25.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package KernSmith.Fonts.Web --version 0.25.0
                    
NuGet\Install-Package KernSmith.Fonts.Web -Version 0.25.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KernSmith.Fonts.Web" Version="0.25.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KernSmith.Fonts.Web" Version="0.25.0" />
                    
Directory.Packages.props
<PackageReference Include="KernSmith.Fonts.Web" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KernSmith.Fonts.Web --version 0.25.0
                    
#r "nuget: KernSmith.Fonts.Web, 0.25.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package KernSmith.Fonts.Web@0.25.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KernSmith.Fonts.Web&version=0.25.0
                    
Install as a Cake Addin
#tool nuget:?package=KernSmith.Fonts.Web&version=0.25.0
                    
Install as a Cake Tool

KernSmith.Fonts.Web

A web font source for KernSmith. Fetches WOFF2 (or WOFF) fonts from CSS-based font CDNs by parsing @font-face responses.

Overview

WebFontSource implements the core KernSmith.Font.IFontSource abstraction. It fetches a stylesheet from a font CDN (Bunny Fonts, Google Fonts, or any compatible custom endpoint), parses the @font-face rules, and downloads the font file for the requested Unicode subset: the .woff2 when offered (smaller), otherwise the .woff. KernSmith core decodes both, WOFF2 with its own managed Brotli decoder, so it works in the browser.

This is primarily useful in browser/WASM scenarios (e.g. running KernSmith in Blazor WebAssembly) where there is no filesystem and fonts must be obtained over the network.

Platform: Cross-platform (net8.0, net10.0). Uses HttpClient from the BCL.

Usage

dotnet add package KernSmith.Fonts.Web
using KernSmith;
using KernSmith.Font;
using KernSmith.Fonts.Web;

var source = new WebFontSource(WebFontProvider.BunnyFonts);
byte[] bytes = await source.GetFontAsync("Roboto", weight: 400);

BmFont.RegisterFont("Roboto", bytes);
var result = BmFont.GenerateFromSystem("Roboto", size: 32);

Providers

new WebFontSource(WebFontProvider.BunnyFonts);                 // privacy-friendly default
new WebFontSource(WebFontProvider.GoogleFonts);                // fonts.googleapis.com
new WebFontSource(WebFontProvider.Custom("https://my.cdn/css")); // any compatible endpoint

Subsets and styles

await source.GetFontAsync("Roboto", weight: 700, style: FontStyle.Italic, subset: "latin");
await source.GetFontAsync("Roboto", subset: "cyrillic");

Caching

Fetched fonts are cached in memory (keyed by family + weight + style + subset). Pass a diskCachePath to also persist across runs (leave it null on WASM):

new WebFontSource(WebFontProvider.BunnyFonts, diskCachePath: "cache/fonts");

Limitations

  • WOFF2 or WOFF only — a source is picked by its format() hint, else its file extension; TTF/OTF/EOT/SVG sources are ignored, so a subset offering neither WOFF2 nor WOFF throws InvalidOperationException.
  • User-Agent — outside a browser the source sends a modern Chrome User-Agent (unless your HttpClient already has one), because Google Fonts serves TTF to unknown agents. In the browser it sends none and the browser's own UA is used: a custom User-Agent is not CORS-safelisted, and the CDNs reject the preflight it causes in Firefox.
  • No family listing — CSS CDNs do not expose a discovery endpoint, so ListFamiliesAsync returns an empty list.

Build

dotnet build src/KernSmith.Fonts.Web/KernSmith.Fonts.Web.csproj

See the KernSmith repository for full project documentation.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.28.0 93 11/15/2026
0.27.0 114 11/6/2026
0.26.0 95 11/2/2026
0.25.0 109 11/1/2026
0.24.0 101 10/18/2026
0.23.1 105 10/17/2026
0.23.0 100 10/14/2026
0.22.1 96 10/13/2026
0.22.0 125 9/10/2026
0.21.0 123 8/28/2026
0.20.0 131 8/5/2026
0.19.0 137 7/31/2026
0.18.2 120 7/28/2026
0.18.1 130 7/28/2026
0.18.0 126 7/27/2026
0.17.0 131 7/19/2026