-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #295 from SixLabors/js/font-hinting
Fix Font Hinting
- Loading branch information
Showing
27 changed files
with
1,741 additions
and
973 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
using System; | ||
using System.Buffers; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace SixLabors.Fonts | ||
{ | ||
/// <summary> | ||
/// A custom <see cref="MemoryManager{T}"/> that can wrap <see cref="Memory{T}"/> of <see cref="byte"/> instances | ||
/// and cast them to be <see cref="Memory{T}"/> for any arbitrary unmanaged <typeparamref name="T"/> value type. | ||
/// </summary> | ||
/// <typeparam name="T">The value type to use when casting the wrapped <see cref="Memory{T}"/> instance.</typeparam> | ||
internal sealed class ByteMemoryManager<T> : MemoryManager<T> | ||
where T : unmanaged | ||
{ | ||
/// <summary> | ||
/// The wrapped <see cref="Memory{T}"/> of <see cref="byte"/> instance. | ||
/// </summary> | ||
private readonly Memory<byte> memory; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ByteMemoryManager{T}"/> class. | ||
/// </summary> | ||
/// <param name="memory">The <see cref="Memory{T}"/> of <see cref="byte"/> instance to wrap.</param> | ||
public ByteMemoryManager(Memory<byte> memory) => this.memory = memory; | ||
|
||
/// <inheritdoc/> | ||
protected override void Dispose(bool disposing) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override Span<T> GetSpan() => MemoryMarshal.Cast<byte, T>(this.memory.Span); | ||
|
||
/// <inheritdoc/> | ||
public override MemoryHandle Pin(int elementIndex = 0) | ||
|
||
// We need to adjust the offset into the wrapped byte segment, | ||
// as the input index refers to the target-cast memory of T. | ||
// We just have to shift this index by the byte size of T. | ||
=> this.memory.Slice(elementIndex * Unsafe.SizeOf<T>()).Pin(); | ||
|
||
/// <inheritdoc/> | ||
public override void Unpin() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace SixLabors.Fonts | ||
{ | ||
/// <summary> | ||
/// Provides a readonly mapped view of an underlying slice, selecting arbitrary indices | ||
/// from the source array. | ||
/// </summary> | ||
/// <typeparam name="T">The type of item contained in the underlying array.</typeparam> | ||
internal readonly struct ReadonlyMappedArraySlice<T> | ||
where T : struct | ||
{ | ||
private readonly ReadOnlyArraySlice<T> data; | ||
private readonly ReadOnlyArraySlice<int> map; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ReadonlyMappedArraySlice{T}"/> struct. | ||
/// </summary> | ||
/// <param name="data">The data slice.</param> | ||
/// <param name="map">The map slice.</param> | ||
public ReadonlyMappedArraySlice(in ReadOnlyArraySlice<T> data, in ReadOnlyArraySlice<int> map) | ||
{ | ||
Guard.MustBeGreaterThanOrEqualTo(data.Length, map.Length, nameof(map)); | ||
|
||
this.data = data; | ||
this.map = map; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the number of items in the map. | ||
/// </summary> | ||
public int Length => this.map.Length; | ||
|
||
/// <summary> | ||
/// Returns a reference to specified element of the slice. | ||
/// </summary> | ||
/// <param name="index">The index of the element to return.</param> | ||
/// <returns>The <typeparamref name="T"/>.</returns> | ||
/// <exception cref="IndexOutOfRangeException"> | ||
/// Thrown when index less than 0 or index greater than or equal to <see cref="Length"/>. | ||
/// </exception> | ||
public readonly T this[int index] | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get => this.data[this.map[index]]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.