|
|
@ -16,7 +16,6 @@ namespace Avalonia.Skia |
|
|
internal class GlyphTypefaceImpl : IGlyphTypeface2 |
|
|
internal class GlyphTypefaceImpl : IGlyphTypeface2 |
|
|
{ |
|
|
{ |
|
|
private bool _isDisposed; |
|
|
private bool _isDisposed; |
|
|
private readonly SKTypeface _typeface; |
|
|
|
|
|
private readonly NameTable? _nameTable; |
|
|
private readonly NameTable? _nameTable; |
|
|
private readonly OS2Table? _os2Table; |
|
|
private readonly OS2Table? _os2Table; |
|
|
private readonly HorizontalHeadTable? _hhTable; |
|
|
private readonly HorizontalHeadTable? _hhTable; |
|
|
@ -24,7 +23,7 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
|
public GlyphTypefaceImpl(SKTypeface typeface, FontSimulations fontSimulations) |
|
|
public GlyphTypefaceImpl(SKTypeface typeface, FontSimulations fontSimulations) |
|
|
{ |
|
|
{ |
|
|
_typeface = typeface ?? throw new ArgumentNullException(nameof(typeface)); |
|
|
SKTypeface = typeface ?? throw new ArgumentNullException(nameof(typeface)); |
|
|
|
|
|
|
|
|
Face = new Face(GetTable) { UnitsPerEm = typeface.UnitsPerEm }; |
|
|
Face = new Face(GetTable) { UnitsPerEm = typeface.UnitsPerEm }; |
|
|
|
|
|
|
|
|
@ -96,6 +95,11 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
|
var style = _os2Table != null ? GetFontStyle(_os2Table.FontStyle) : FontStyle.Normal; |
|
|
var style = _os2Table != null ? GetFontStyle(_os2Table.FontStyle) : FontStyle.Normal; |
|
|
|
|
|
|
|
|
|
|
|
if (typeface.FontStyle.Slant == SKFontStyleSlant.Oblique) |
|
|
|
|
|
{ |
|
|
|
|
|
style = FontStyle.Oblique; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Style = (fontSimulations & FontSimulations.Oblique) != 0 ? FontStyle.Italic : style; |
|
|
Style = (fontSimulations & FontSimulations.Oblique) != 0 ? FontStyle.Italic : style; |
|
|
|
|
|
|
|
|
var stretch = _os2Table != null ? (FontStretch)_os2Table.WidthClass : FontStretch.Normal; |
|
|
var stretch = _os2Table != null ? (FontStretch)_os2Table.WidthClass : FontStretch.Normal; |
|
|
@ -205,6 +209,8 @@ namespace Avalonia.Skia |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public SKTypeface SKTypeface { get; } |
|
|
|
|
|
|
|
|
public Face Face { get; } |
|
|
public Face Face { get; } |
|
|
|
|
|
|
|
|
public Font Font { get; } |
|
|
public Font Font { get; } |
|
|
@ -300,12 +306,12 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
|
private static FontStyle GetFontStyle(OS2Table.FontStyleSelection styleSelection) |
|
|
private static FontStyle GetFontStyle(OS2Table.FontStyleSelection styleSelection) |
|
|
{ |
|
|
{ |
|
|
if((styleSelection & OS2Table.FontStyleSelection.ITALIC) != 0) |
|
|
if ((styleSelection & OS2Table.FontStyleSelection.ITALIC) != 0) |
|
|
{ |
|
|
{ |
|
|
return FontStyle.Italic; |
|
|
return FontStyle.Italic; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if((styleSelection & OS2Table.FontStyleSelection.OBLIQUE) != 0) |
|
|
if ((styleSelection & OS2Table.FontStyleSelection.OBLIQUE) != 0) |
|
|
{ |
|
|
{ |
|
|
return FontStyle.Oblique; |
|
|
return FontStyle.Oblique; |
|
|
} |
|
|
} |
|
|
@ -315,18 +321,18 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
|
private Blob? GetTable(Face face, Tag tag) |
|
|
private Blob? GetTable(Face face, Tag tag) |
|
|
{ |
|
|
{ |
|
|
var size = _typeface.GetTableSize(tag); |
|
|
var size = SKTypeface.GetTableSize(tag); |
|
|
|
|
|
|
|
|
var data = Marshal.AllocCoTaskMem(size); |
|
|
var data = Marshal.AllocCoTaskMem(size); |
|
|
|
|
|
|
|
|
var releaseDelegate = new ReleaseDelegate(() => Marshal.FreeCoTaskMem(data)); |
|
|
var releaseDelegate = new ReleaseDelegate(() => Marshal.FreeCoTaskMem(data)); |
|
|
|
|
|
|
|
|
return _typeface.TryGetTableData(tag, 0, size, data) ? |
|
|
return SKTypeface.TryGetTableData(tag, 0, size, data) ? |
|
|
new Blob(data, size, MemoryMode.ReadOnly, releaseDelegate) : null; |
|
|
new Blob(data, size, MemoryMode.ReadOnly, releaseDelegate) : null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public SKFont CreateSKFont(float size) |
|
|
public SKFont CreateSKFont(float size) |
|
|
=> new(_typeface, size, skewX: (FontSimulations & FontSimulations.Oblique) != 0 ? -0.3f : 0.0f) |
|
|
=> new(SKTypeface, size, skewX: (FontSimulations & FontSimulations.Oblique) != 0 ? -0.3f : 0.0f) |
|
|
{ |
|
|
{ |
|
|
LinearMetrics = true, |
|
|
LinearMetrics = true, |
|
|
Embolden = (FontSimulations & FontSimulations.Bold) != 0 |
|
|
Embolden = (FontSimulations & FontSimulations.Bold) != 0 |
|
|
@ -348,7 +354,7 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
|
Font.Dispose(); |
|
|
Font.Dispose(); |
|
|
Face.Dispose(); |
|
|
Face.Dispose(); |
|
|
_typeface.Dispose(); |
|
|
SKTypeface.Dispose(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
public void Dispose() |
|
|
@ -359,14 +365,14 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
|
public bool TryGetTable(uint tag, out byte[] table) |
|
|
public bool TryGetTable(uint tag, out byte[] table) |
|
|
{ |
|
|
{ |
|
|
return _typeface.TryGetTableData(tag, out table); |
|
|
return SKTypeface.TryGetTableData(tag, out table); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public bool TryGetStream([NotNullWhen(true)] out Stream? stream) |
|
|
public bool TryGetStream([NotNullWhen(true)] out Stream? stream) |
|
|
{ |
|
|
{ |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
var asset = _typeface.OpenStream(); |
|
|
var asset = SKTypeface.OpenStream(); |
|
|
var size = asset.Length; |
|
|
var size = asset.Length; |
|
|
var buffer = new byte[size]; |
|
|
var buffer = new byte[size]; |
|
|
|
|
|
|
|
|
|