{"id":18246605,"url":"https://github.com/datvm/blazor.localfontaccess","last_synced_at":"2025-10-28T00:47:16.980Z","repository":{"id":65211976,"uuid":"587419265","full_name":"datvm/Blazor.LocalFontAccess","owner":"datvm","description":"Local Font Access API interop for Blazor.","archived":false,"fork":false,"pushed_at":"2023-01-25T17:42:39.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-28T00:47:16.273Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/datvm.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.MD","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-10T17:55:12.000Z","updated_at":"2023-01-10T18:43:08.000Z","dependencies_parsed_at":"2023-02-14T10:00:58.447Z","dependency_job_id":null,"html_url":"https://github.com/datvm/Blazor.LocalFontAccess","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/datvm/Blazor.LocalFontAccess","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FBlazor.LocalFontAccess","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FBlazor.LocalFontAccess/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FBlazor.LocalFontAccess/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FBlazor.LocalFontAccess/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datvm","download_url":"https://codeload.github.com/datvm/Blazor.LocalFontAccess/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FBlazor.LocalFontAccess/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281366880,"owners_count":26488696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-27T02:00:05.855Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T09:26:57.053Z","updated_at":"2025-10-28T00:47:16.956Z","avatar_url":"https://github.com/datvm.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"This library add interop support for [Local Font Access API](https://developer.mozilla.org/en-US/docs/Web/API/Local_Font_Access_API) in Blazor WebAssembly.\n\n# Demo \u0026 Documentation\n\nSee [Demo project](./Blazor.LocalFont.DemoWebAssembly/).\n\nThe library is fully XML documented. All the methods and properties names follow the original [Javascript API](https://developer.mozilla.org/en-US/docs/Web/API/Local_Font_Access_API).\n\n# Installation \u0026 Setup\n\n## Nuget Package\n\nInstall this library through [Blazor.LocalFont](https://www.nuget.org/packages/Blazor.LocalFont):\n\n```ps\ndotnet add package Blazor.LocalFont\n```\n\nThe project requires .NET 7.0 or later.\n\n## Setup Dependency Injection\n\nCall `AddLocalFont` method to register `ILocalFontService` into your DI container.\n\n```cs\nbuilder.Services\n    .AddLocalFont();\n```\n\nFrom your pages or services, you can inject an instance of `ILocalFontService` to use the library.\n\n```cs\n@inject ILocalFontService LFonts;\n```\n\n# Usage\n\n## `Task\u003cbool\u003e IsSupportedAsync()`\n\nCheck if the browser supports the Local Font Access API.\n\n```cs\nif (await LFonts.IsSupportedAsync()) \n{\n    // It is supported\n}\n```\n\n## `Task\u003cFontPermission\u003e GetPermissionAsync()`\n\nGet the current permission status for `local-fonts` permission. See [Javascript Permissions API](https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API).\n\n```cs\nvar permission = await LFonts.GetPermissionAsync();\n// permission is one of the following values: \"granted\", \"denied\", \"prompt\"\n```\n\nIf the permission is `prompt`, you can request the permission with one of the query methods.\n\n## `QueryLocalFontsAsync` and `QueryLocalFontsRefAsync`\n\nYou can request a list of local fonts with these methods:\n\n```cs\n    Task\u003cIEnumerable\u003cFontData\u003e\u003e QueryLocalFontsAsync();\n    Task\u003cIEnumerable\u003cFontData\u003e\u003e QueryLocalFontsAsync(IEnumerable\u003cstring\u003e? postscriptNames);\n    Task\u003cIEnumerable\u003cFontData\u003e\u003e QueryLocalFontsAsync(QueryLocalFontsOptions? options);\n    Task\u003cIFontDataRefCollection\u003e QueryLocalFontsRefAsync();\n    Task\u003cIFontDataRefCollection\u003e QueryLocalFontsRefAsync(IEnumerable\u003cstring\u003e? postscriptNames);\n    Task\u003cIFontDataRefCollection\u003e QueryLocalFontsRefAsync(QueryLocalFontsOptions? options);\n```\n\n`postscriptNames` is a list of PostScript names of the fonts you want to query. If you don't specify any, all the fonts will be returned.\n\nThe difference between `QueryLocalFontsAsync` and `QueryLocalFontsRefAsync` is that one returns the serialized information only (and no further operation is possible), while the other returns a reference to the font data that can be used to load the font data. See [Font Data JS Reference types below](#ifontdatarefcollection-and-ifontdataref) for more information.\n\n**Example**\n\n```cs\n// Get the font from backend C#\nvar fonts = await LFonts.QueryLocalFontsAsync();\nfirstFont = fonts.First();\n```\n\n```html\n\u003c!-- Use it in HTML --\u003e\n\u003cspan style=\"font-family: @(firstFont.Family);\"\u003e\n    The quick brown fox jumps over the lazy dog\n\u003c/span\u003e\n```\n\n## `IFontDataRefCollection` and `IFontDataRef`\n\nIf you use `QueryLocalFontsRefAsync` method, you will receive an instance of `IFontDataRefCollection` instead of `FontData`.\n\n- `IFontDataRefCollection`: A reference to a Javascript Array of FontData for further operation.\n\n    - `Task\u003clong\u003e GetLengthAsync()`: Get the total number of items (length) in this array.\n\n    - `Task\u003cIFontDataRef\u003e GetItemAsync(long index)`: Get a single FontData reference at the specified index.\n\n- `IFontDataRef`: A reference to a Javascript `FontData` for further operation.\n\n    - `Task\u003cFontData\u003e GetFontDataAsync()`: Get the information of this `FontData`.\n\n    - `Task\u003cStream\u003e GetFontFileAsync(long maxAllowedSize = DefaultMaxAllowedSize)`: Get the raw binary data of this font. The default max size is 10MB, you will receive an error if a font is larger than this size.\n\n**Example**\n\nThis example request a list of fonts and then load its binary data to determine the font type according to [the example from MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/queryLocalFonts#accessing_low-level_data).\n\n\n```cs\n// Get font list\nfontRefs = await LFonts.QueryLocalFontsRefAsync();\nfontRefsLen = await fontRefs.GetLengthAsync();\n\n// Read data from the first font\nvar font = await fontRefs.GetItemAsync(0);\nvar data = await font.GetFontDataAsync();\n\nusing var stream = await font.GetFontFileAsync();\nvar buffer = new byte[4];\nvar count = await stream.ReadAsync(buffer, 0, 4);\n\nif (count != 4)\n{\n    currFontType = \"Unknown\";\n}\nelse\n{\n    var sfntVersion = System.Text.Encoding.UTF8.GetString(buffer);\n    switch (sfntVersion)\n    {\n        case \"\\x00\\x01\\x00\\x00\":\n        case \"true\":\n        case \"typ1\":\n            currFontType = \"truetype\";\n            break;\n        case \"OTTO\":\n            currFontType = \"cff\";\n            break;\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatvm%2Fblazor.localfontaccess","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatvm%2Fblazor.localfontaccess","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatvm%2Fblazor.localfontaccess/lists"}