-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Improve FontCollection customization #19756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Improve FontCollection customization #19756
Conversation
You can test this PR using the following package version. |
Introduce CustomFontCollection
85b525f
to
c06c943
Compare
…bald/Avalonia into feature/publicFontCollectionHelper
You can test this PR using the following package version. |
API diff between 12.0.999-cibuild0059262-alpha and 12.0.999Avalonia.Base (net6.0, net8.0, netstandard2.0) namespace Avalonia.Media
{
public sealed class Typeface
{
+ public Avalonia.Media.Typeface Normalize(out string normalizedFamilyName);
}
}
namespace Avalonia.Media.Fonts
{
public class EmbeddedFontCollection : Avalonia.Media.Fonts.FontCollectionBase
{
- public override System.Collections.Generic.IEnumerator<Avalonia.Media.FontFamily> GetEnumerator();
- public bool TryGetFamilyTypefaces(string familyName, out System.Collections.Generic.IReadOnlyList<Avalonia.Media.Typeface?>? familyTypefaces);
- public override bool TryGetGlyphTypeface(string familyName, Avalonia.Media.FontStyle style, Avalonia.Media.FontWeight weight, Avalonia.Media.FontStretch stretch, out Avalonia.Media.IGlyphTypeface? glyphTypeface);
- public override int Count { get; }
- public override Avalonia.Media.FontFamily this[int index] {
- get { }
- }
}
public abstract class FontCollectionBase : Avalonia.Media.Fonts.IFontCollection
{
+ public virtual System.Collections.Generic.IEnumerator<Avalonia.Media.FontFamily> GetEnumerator();
- public abstract System.Collections.Generic.IEnumerator<Avalonia.Media.FontFamily> GetEnumerator();
- public abstract void Initialize(Avalonia.Platform.IFontManagerImpl fontManager);
+ public virtual void Initialize(Avalonia.Platform.IFontManagerImpl fontManagerImpl);
- public abstract bool TryGetGlyphTypeface(string familyName, Avalonia.Media.FontStyle style, Avalonia.Media.FontWeight weight, Avalonia.Media.FontStretch stretch, out Avalonia.Media.IGlyphTypeface? glyphTypeface);
+ public virtual bool TryGetGlyphTypeface(string familyName, Avalonia.Media.FontStyle style, Avalonia.Media.FontWeight weight, Avalonia.Media.FontStretch stretch, out Avalonia.Media.IGlyphTypeface? glyphTypeface);
- public abstract int Count { get; }
+ public virtual int Count { get; }
- public abstract Avalonia.Media.FontFamily this[int index] { get; }
+ public virtual Avalonia.Media.FontFamily this[int index] {
+ get { }
+ }
+ protected void AddFontFamily(Avalonia.Media.FontFamily fontFamily);
+ public bool TryAddFontSource(System.Uri source);
+ public bool TryAddGlyphTypeface(Avalonia.Media.IGlyphTypeface glyphTypeface);
+ public bool TryAddGlyphTypeface(System.IO.Stream stream);
+ protected bool TryAddGlyphTypeface(string familyName, Avalonia.Media.Fonts.FontCollectionKey key, Avalonia.Media.IGlyphTypeface? glyphTypeface);
+ public virtual bool TryGetFamilyTypefaces(string familyName, out System.Collections.Generic.IReadOnlyList<Avalonia.Media.Typeface?>? familyTypefaces);
+ protected bool TryGetGlyphTypeface(string familyName, Avalonia.Media.Fonts.FontCollectionKey key, out Avalonia.Media.IGlyphTypeface? glyphTypeface);
+ protected bool? TryGetNearestMatch(System.Collections.Generic.IDictionary<Avalonia.Media.Fonts.FontCollectionKey, Avalonia.Media.IGlyphTypeface> glyphTypefaces, Avalonia.Media.Fonts.FontCollectionKey? key, out Avalonia.Media.IGlyphTypeface? glyphTypeface);
+ public bool TryGetNearestMatch(string familyName, Avalonia.Media.FontStyle style, Avalonia.Media.FontWeight weight, Avalonia.Media.FontStretch stretch, out Avalonia.Media.IGlyphTypeface? glyphTypeface);
+ protected Avalonia.Platform.IFontManagerImpl FontManagerImpl { get; }
}
public static class FontFamilyLoader
{
+ public static bool IsFontFile(string filePath);
}
} |
It might also be useful to add whole font collection into another |
A copy can be done via:
But we can also introduce some API to make this easier |
I was thinking of |
You can test this PR using the following package version. |
…tCollectionHelper # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
You can test this PR using the following package version. |
Introduce TryAddFontSource
…bald/Avalonia into feature/publicFontCollectionHelper
You can test this PR using the following package version. |
You can test this PR using the following package version. |
…bald/Avalonia into feature/publicFontCollectionHelper
…bald/Avalonia into feature/publicFontCollectionHelper
You can test this PR using the following package version. |
What does the pull request do?
What is the current behavior?
Example for TryAddFontSource
How was the solution implemented (if it's not obvious)?
Sorted Insertion of Font Families
FontFamily
inAddGlyphTypeface
, we now use aBinarySearch
to determine the correct insertion index for faster lookup in the future._fontFamilies
list remains sorted by name (case-insensitive).Efficient Prefix Search in
TryGetGlyphTypeface
Checklist
Breaking changes
Obsoletions / Deprecations
Fixed issues