Browse Source

Nullability for text related types

pull/7203/head
Benedikt Stebner 5 years ago
committed by Steven Kirk
parent
commit
42f552d803
  1. 4
      src/Avalonia.Visuals/ApiCompatBaseline.txt
  2. 2
      src/Avalonia.Visuals/Media/FontFallback.cs
  3. 8
      src/Avalonia.Visuals/Media/FontManager.cs
  4. 4
      src/Avalonia.Visuals/Media/FontManagerOptions.cs
  5. 2
      src/Avalonia.Visuals/Media/Fonts/FontFamilyLoader.cs
  6. 18
      src/Avalonia.Visuals/Media/GlyphRun.cs
  7. 4
      src/Avalonia.Visuals/Media/GlyphTypeface.cs
  8. 12
      src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs
  9. 12
      src/Avalonia.Visuals/Media/TextFormatting/TextLineImpl.cs
  10. 2
      src/Avalonia.Visuals/Media/Typeface.cs
  11. 2
      src/Avalonia.Visuals/Media/UnicodeRange.cs

4
src/Avalonia.Visuals/ApiCompatBaseline.txt

@ -5,6 +5,8 @@ InterfacesShouldHaveSameMembers : Interface member 'public System.Threading.Task
MembersMustExist : Member 'public System.Threading.Tasks.Task Avalonia.Animation.IPageTransition.Start(Avalonia.Visual, Avalonia.Visual, System.Boolean)' does not exist in the implementation but it does exist in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.Threading.Tasks.Task Avalonia.Animation.IPageTransition.Start(Avalonia.Visual, Avalonia.Visual, System.Boolean, System.Threading.CancellationToken)' is present in the implementation but not in the contract.
MembersMustExist : Member 'public System.Threading.Tasks.Task Avalonia.Animation.PageSlide.Start(Avalonia.Visual, Avalonia.Visual, System.Boolean)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public void Avalonia.Media.GlyphRun..ctor()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public void Avalonia.Media.GlyphRun.GlyphTypeface.set(Avalonia.Media.GlyphTypeface)' does not exist in the implementation but it does exist in the contract.
TypeCannotChangeClassification : Type 'Avalonia.Media.Immutable.ImmutableSolidColorBrush' is a 'class' in the implementation but is a 'struct' in the contract.
MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.DrawableTextRun.Draw(Avalonia.Media.DrawingContext)' does not exist in the implementation but it does exist in the contract.
CannotAddAbstractMembers : Member 'public void Avalonia.Media.TextFormatting.DrawableTextRun.Draw(Avalonia.Media.DrawingContext, Avalonia.Point)' is abstract in the implementation but is missing in the contract.
@ -77,4 +79,4 @@ InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IWr
InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IWriteableBitmapImpl Avalonia.Platform.IPlatformRenderInterface.LoadWriteableBitmap(System.String)' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IWriteableBitmapImpl Avalonia.Platform.IPlatformRenderInterface.LoadWriteableBitmapToHeight(System.IO.Stream, System.Int32, Avalonia.Visuals.Media.Imaging.BitmapInterpolationMode)' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IWriteableBitmapImpl Avalonia.Platform.IPlatformRenderInterface.LoadWriteableBitmapToWidth(System.IO.Stream, System.Int32, Avalonia.Visuals.Media.Imaging.BitmapInterpolationMode)' is present in the implementation but not in the contract.
Total Issues: 78
Total Issues: 79

2
src/Avalonia.Visuals/Media/FontFallback.cs

@ -8,7 +8,7 @@
/// <summary>
/// Get or set the fallback <see cref="FontFamily"/>
/// </summary>
public FontFamily FontFamily { get; set; }
public FontFamily FontFamily { get; set; } = FontFamily.Default;
/// <summary>
/// Get or set the <see cref="UnicodeRange"/> that is covered by the fallback.

8
src/Avalonia.Visuals/Media/FontManager.cs

@ -16,7 +16,7 @@ namespace Avalonia.Media
private readonly ConcurrentDictionary<Typeface, GlyphTypeface> _glyphTypefaceCache =
new ConcurrentDictionary<Typeface, GlyphTypeface>();
private readonly FontFamily _defaultFontFamily;
private readonly IReadOnlyList<FontFallback> _fontFallbacks;
private readonly IReadOnlyList<FontFallback>? _fontFallbacks;
public FontManager(IFontManagerImpl platformImpl)
{
@ -87,7 +87,7 @@ namespace Avalonia.Media
/// <returns>
/// The <see cref="GlyphTypeface"/>.
/// </returns>
public GlyphTypeface? GetOrAddGlyphTypeface(Typeface typeface)
public GlyphTypeface GetOrAddGlyphTypeface(Typeface typeface)
{
while (true)
{
@ -105,7 +105,7 @@ namespace Avalonia.Media
if (typeface.FontFamily == _defaultFontFamily)
{
return null;
throw new InvalidOperationException($"Could not create glyph typeface for: {typeface.FontFamily.Name}.");
}
typeface = new Typeface(_defaultFontFamily, typeface.Style, typeface.Weight);
@ -126,7 +126,7 @@ namespace Avalonia.Media
/// </returns>
public bool TryMatchCharacter(int codepoint, FontStyle fontStyle,
FontWeight fontWeight,
FontFamily fontFamily, CultureInfo culture, out Typeface typeface)
FontFamily? fontFamily, CultureInfo? culture, out Typeface typeface)
{
if(_fontFallbacks != null)
{

4
src/Avalonia.Visuals/Media/FontManagerOptions.cs

@ -4,8 +4,8 @@ namespace Avalonia.Media
{
public class FontManagerOptions
{
public string DefaultFamilyName { get; set; }
public string? DefaultFamilyName { get; set; }
public IReadOnlyList<FontFallback> FontFallbacks { get; set; }
public IReadOnlyList<FontFallback>? FontFallbacks { get; set; }
}
}

2
src/Avalonia.Visuals/Media/Fonts/FontFamilyLoader.cs

@ -89,7 +89,7 @@ namespace Avalonia.Media.Fonts
{
fileExtension = "." + fontFamilyKey.Source.AbsolutePath.Split('.').LastOrDefault();
var fileName = fontFamilyKey.Source.LocalPath.Replace(fileExtension, string.Empty).Split('.').LastOrDefault();
var fileName = fontFamilyKey.Source.LocalPath.Replace(fileExtension, string.Empty).Split('.').Last();
location = new Uri(fontFamilyKey.Source.AbsoluteUri.Replace("." + fileName + fileExtension, string.Empty), UriKind.RelativeOrAbsolute);

18
src/Avalonia.Visuals/Media/GlyphRun.cs

@ -27,14 +27,6 @@ namespace Avalonia.Media
private ReadOnlySlice<ushort> _glyphClusters;
private ReadOnlySlice<char> _characters;
/// <summary>
/// Initializes a new instance of the <see cref="GlyphRun"/> class.
/// </summary>
public GlyphRun()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="GlyphRun"/> class by specifying properties of the class.
/// </summary>
@ -56,7 +48,7 @@ namespace Avalonia.Media
ReadOnlySlice<ushort> glyphClusters = default,
int biDiLevel = 0)
{
GlyphTypeface = glyphTypeface;
_glyphTypeface = glyphTypeface;
FontRenderingEmSize = fontRenderingEmSize;
@ -74,13 +66,9 @@ namespace Avalonia.Media
}
/// <summary>
/// Gets or sets the <see cref="Media.GlyphTypeface"/> for the <see cref="GlyphRun"/>.
/// Gets the <see cref="Media.GlyphTypeface"/> for the <see cref="GlyphRun"/>.
/// </summary>
public GlyphTypeface GlyphTypeface
{
get => _glyphTypeface;
set => Set(ref _glyphTypeface, value);
}
public GlyphTypeface GlyphTypeface => _glyphTypeface;
/// <summary>
/// Gets or sets the em size used for rendering the <see cref="GlyphRun"/>.

4
src/Avalonia.Visuals/Media/GlyphTypeface.cs

@ -8,8 +8,8 @@ namespace Avalonia.Media
public const int InvisibleGlyph = 3;
public GlyphTypeface(Typeface typeface)
: this(FontManager.Current?.PlatformImpl.CreateGlyphTypeface(typeface))
{
: this(FontManager.Current.PlatformImpl.CreateGlyphTypeface(typeface))
{
}
public GlyphTypeface(IGlyphTypefaceImpl platformImpl)

12
src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs

@ -277,7 +277,7 @@ namespace Avalonia.Media.TextFormatting
var textRuns = new List<ShapedTextCharacters>();
if (previousLineBreak != null)
if (previousLineBreak?.RemainingCharacters != null)
{
for (var index = 0; index < previousLineBreak.RemainingCharacters.Count; index++)
{
@ -317,7 +317,7 @@ namespace Avalonia.Media.TextFormatting
while (textRunEnumerator.MoveNext())
{
var textRun = textRunEnumerator.Current;
var textRun = textRunEnumerator.Current!;
switch (textRun)
{
@ -398,7 +398,7 @@ namespace Avalonia.Media.TextFormatting
/// <param name="currentLineBreak">The current line break if the line was explicitly broken.</param>
/// <returns>The wrapped text line.</returns>
private static TextLine PerformTextWrapping(List<ShapedTextCharacters> textRuns, TextRange textRange,
double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak currentLineBreak)
double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak? currentLineBreak)
{
var availableWidth = paragraphWidth;
var currentWidth = 0.0;
@ -517,7 +517,7 @@ namespace Avalonia.Media.TextFormatting
var lineBreak = remainingCharacters?.Count > 0 ? new TextLineBreak(remainingCharacters) : null;
if (lineBreak is null && currentLineBreak.TextEndOfLine != null)
if (lineBreak is null && currentLineBreak?.TextEndOfLine != null)
{
lineBreak = new TextLineBreak(currentLineBreak.TextEndOfLine);
}
@ -586,11 +586,11 @@ namespace Avalonia.Media.TextFormatting
{
_textSource = textSource;
_pos = firstTextSourceIndex;
Current = null!;
Current = null;
}
// ReSharper disable once MemberHidesStaticFromOuterClass
public TextRun Current { get; private set; }
public TextRun? Current { get; private set; }
public bool MoveNext()
{

12
src/Avalonia.Visuals/Media/TextFormatting/TextLineImpl.cs

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Avalonia.Media.TextFormatting.Unicode;
using Avalonia.Platform;
using Avalonia.Utilities;
@ -479,12 +480,13 @@ namespace Avalonia.Media.TextFormatting
/// </returns>
internal static ShapedTextCharacters CreateShapedSymbol(TextRun textRun)
{
var formatterImpl = AvaloniaLocator.Current.GetService<ITextShaperImpl>();
var properties = textRun.Properties;
var glyphRun = formatterImpl.ShapeText(textRun.Text, textRun.Properties.Typeface, textRun.Properties.FontRenderingEmSize,
textRun.Properties.CultureInfo);
_ = properties ?? throw new InvalidOperationException($"{nameof(TextRun.Properties)} should not be null.");
return new ShapedTextCharacters(glyphRun, textRun.Properties);
var glyphRun = TextShaper.Current.ShapeText(textRun.Text, properties.Typeface, properties.FontRenderingEmSize, properties.CultureInfo);
return new ShapedTextCharacters(glyphRun, properties);
}
}
}

2
src/Avalonia.Visuals/Media/Typeface.cs

@ -66,7 +66,7 @@ namespace Avalonia.Media
/// <value>
/// The glyph typeface.
/// </value>
public GlyphTypeface? GlyphTypeface => FontManager.Current.GetOrAddGlyphTypeface(this);
public GlyphTypeface GlyphTypeface => FontManager.Current.GetOrAddGlyphTypeface(this);
public static bool operator !=(Typeface a, Typeface b)
{

2
src/Avalonia.Visuals/Media/UnicodeRange.cs

@ -37,7 +37,7 @@ namespace Avalonia.Media
internal UnicodeRangeSegment Single => _single;
internal IReadOnlyList<UnicodeRangeSegment> Segments => _segments;
internal IReadOnlyList<UnicodeRangeSegment>? Segments => _segments;
/// <summary>
/// Determines if given value is inside the range.

Loading…
Cancel
Save