-
-
Notifications
You must be signed in to change notification settings - Fork 72
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 #438 from SixLabors/js/fix-line-break
Rewrite Line Breaker.
- Loading branch information
Showing
70 changed files
with
1,508 additions
and
336 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
Large diffs are not rendered by default.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
tests/Images/ReferenceOutput/CountLinesWrappingLength_100-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
tests/Images/ReferenceOutput/CountLinesWrappingLength_200-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
tests/Images/ReferenceOutput/CountLinesWrappingLength_25-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
tests/Images/ReferenceOutput/CountLinesWrappingLength_50-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...dBreakMatchesMDN_238-_layoutMode_HorizontalBottomTop-wordBreaking_BreakAll_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...BreakMatchesMDN_238-_layoutMode_HorizontalBottomTop-wordBreaking_BreakWord_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...rdBreakMatchesMDN_238-_layoutMode_HorizontalBottomTop-wordBreaking_KeepAll_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...dBreakMatchesMDN_238-_layoutMode_HorizontalBottomTop-wordBreaking_Standard_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...dBreakMatchesMDN_238-_layoutMode_HorizontalTopBottom-wordBreaking_BreakAll_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...BreakMatchesMDN_238-_layoutMode_HorizontalTopBottom-wordBreaking_BreakWord_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...rdBreakMatchesMDN_238-_layoutMode_HorizontalTopBottom-wordBreaking_KeepAll_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...dBreakMatchesMDN_238-_layoutMode_HorizontalTopBottom-wordBreaking_Standard_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ureTextWordBreak_500-_layoutMode_HorizontalBottomTop-wordBreaking_BreakAll_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...reTextWordBreak_500-_layoutMode_HorizontalBottomTop-wordBreaking_BreakWord_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...sureTextWordBreak_500-_layoutMode_HorizontalBottomTop-wordBreaking_KeepAll_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ureTextWordBreak_500-_layoutMode_HorizontalBottomTop-wordBreaking_Standard_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ureTextWordBreak_500-_layoutMode_HorizontalTopBottom-wordBreaking_BreakAll_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...reTextWordBreak_500-_layoutMode_HorizontalTopBottom-wordBreaking_BreakWord_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...sureTextWordBreak_500-_layoutMode_HorizontalTopBottom-wordBreaking_KeepAll_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ureTextWordBreak_500-_layoutMode_HorizontalTopBottom-wordBreaking_Standard_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...put/MeasureTextWordWrappingHorizontalBottomTop_350-_height_10-width_87.125_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...MeasureTextWordWrappingHorizontalBottomTop_350-_height_11.438-width_279.13_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...MeasureTextWordWrappingHorizontalBottomTop_350-_height_62.625-width_318.86_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...put/MeasureTextWordWrappingHorizontalTopBottom_350-_height_10-width_87.125_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...MeasureTextWordWrappingHorizontalTopBottom_350-_height_11.438-width_279.13_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...MeasureTextWordWrappingHorizontalTopBottom_350-_height_62.625-width_318.86_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...utput/MeasureTextWordWrappingVerticalLeftRight_350-_height_171.25-width_10_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...t/MeasureTextWordWrappingVerticalLeftRight_350-_height_267.25-width_23.875_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
.../MeasureTextWordWrappingVerticalLeftRight_350-_height_318.563-width_62.813_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...ureTextWordWrappingVerticalMixedLeftRight_350-_height_279.125-width_11.438_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...ureTextWordWrappingVerticalMixedLeftRight_350-_height_318.563-width_62.813_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
.../MeasureTextWordWrappingVerticalMixedLeftRight_350-_height_87.125-width_10_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...utput/MeasureTextWordWrappingVerticalRightLeft_350-_height_171.25-width_10_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...t/MeasureTextWordWrappingVerticalRightLeft_350-_height_267.25-width_23.875_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
.../MeasureTextWordWrappingVerticalRightLeft_350-_height_318.563-width_62.813_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
tests/Images/ReferenceOutput/ShouldInsertExtraLineBreaksA_400-4.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
tests/Images/ReferenceOutput/ShouldInsertExtraLineBreaksB_400-4.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
tests/Images/ReferenceOutput/ShouldMatchBrowserBreak__WrappingLength_372_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
.../Images/ReferenceOutput/ShouldNotInsertExtraLineBreaks__WrappingLength_400_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...ter_Horizontal_400-_direction_LeftToRight-TextJustification_InterCharacter_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...ter_Horizontal_400-_direction_RightToLeft-TextJustification_InterCharacter_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...acter_Vertical_400-_direction_LeftToRight-TextJustification_InterCharacter_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...acter_Vertical_400-_direction_RightToLeft-TextJustification_InterCharacter_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...nterWord_Horizontal_400-_direction_LeftToRight-TextJustification_InterWord_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...nterWord_Horizontal_400-_direction_RightToLeft-TextJustification_InterWord_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
..._InterWord_Vertical_400-_direction_LeftToRight-TextJustification_InterWord_.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
..._InterWord_Vertical_400-_direction_RightToLeft-TextJustification_InterWord_.png
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
tests/SixLabors.Fonts.Tests/ImageComparison/ExactImageComparer.cs
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,58 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
using SixLabors.ImageSharp; | ||
using SixLabors.ImageSharp.Memory; | ||
using SixLabors.ImageSharp.PixelFormats; | ||
|
||
namespace SixLabors.Fonts.Tests.ImageComparison; | ||
|
||
public class ExactImageComparer : ImageComparer | ||
{ | ||
public static ExactImageComparer Instance { get; } = new ExactImageComparer(); | ||
|
||
public override ImageSimilarityReport<TPixelA, TPixelB> CompareImagesOrFrames<TPixelA, TPixelB>( | ||
int index, | ||
ImageFrame<TPixelA> expected, | ||
ImageFrame<TPixelB> actual) | ||
{ | ||
if (expected.Size != actual.Size) | ||
{ | ||
throw new InvalidOperationException("Calling ImageComparer is invalid when dimensions mismatch!"); | ||
} | ||
|
||
int width = actual.Width; | ||
|
||
// TODO: Comparing through Rgba64 may not be robust enough because of the existence of super high precision pixel types. | ||
Rgba64[] aBuffer = new Rgba64[width]; | ||
Rgba64[] bBuffer = new Rgba64[width]; | ||
|
||
List<PixelDifference> differences = new(); | ||
Configuration configuration = expected.Configuration; | ||
Buffer2D<TPixelA> expectedBuffer = expected.PixelBuffer; | ||
Buffer2D<TPixelB> actualBuffer = actual.PixelBuffer; | ||
|
||
for (int y = 0; y < actual.Height; y++) | ||
{ | ||
Span<TPixelA> aSpan = expectedBuffer.DangerousGetRowSpan(y); | ||
Span<TPixelB> bSpan = actualBuffer.DangerousGetRowSpan(y); | ||
|
||
PixelOperations<TPixelA>.Instance.ToRgba64(configuration, aSpan, aBuffer); | ||
PixelOperations<TPixelB>.Instance.ToRgba64(configuration, bSpan, bBuffer); | ||
|
||
for (int x = 0; x < width; x++) | ||
{ | ||
Rgba64 aPixel = aBuffer[x]; | ||
Rgba64 bPixel = bBuffer[x]; | ||
|
||
if (aPixel != bPixel) | ||
{ | ||
PixelDifference diff = new(new Point(x, y), aPixel, bPixel); | ||
differences.Add(diff); | ||
} | ||
} | ||
} | ||
|
||
return new ImageSimilarityReport<TPixelA, TPixelB>(index, expected, actual, differences); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...xLabors.Fonts.Tests/ImageComparison/Exceptions/ImageDifferenceIsOverThresholdException.cs
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,63 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
using System.Globalization; | ||
using System.Text; | ||
|
||
namespace SixLabors.Fonts.Tests.ImageComparison; | ||
|
||
public class ImageDifferenceIsOverThresholdException : ImagesSimilarityException | ||
{ | ||
public ImageSimilarityReport[] Reports { get; } | ||
|
||
public ImageDifferenceIsOverThresholdException(params ImageSimilarityReport[] reports) | ||
: base("Image difference is over threshold!" + FormatReports(reports)) | ||
=> this.Reports = reports.ToArray(); | ||
|
||
private static string FormatReports(IEnumerable<ImageSimilarityReport> reports) | ||
{ | ||
StringBuilder sb = new(); | ||
|
||
sb.Append(Environment.NewLine); | ||
sb.AppendFormat(CultureInfo.InvariantCulture, "Test Environment OS : {0}", GetEnvironmentName()); | ||
sb.Append(Environment.NewLine); | ||
|
||
sb.AppendFormat(CultureInfo.InvariantCulture, "Test Environment is CI : {0}", TestEnvironment.RunsOnCI); | ||
sb.Append(Environment.NewLine); | ||
|
||
sb.AppendFormat(CultureInfo.InvariantCulture, "Test Environment OS Architecture : {0}", TestEnvironment.OSArchitecture); | ||
sb.Append(Environment.NewLine); | ||
|
||
sb.AppendFormat(CultureInfo.InvariantCulture, "Test Environment Process Architecture : {0}", TestEnvironment.ProcessArchitecture); | ||
sb.Append(Environment.NewLine); | ||
|
||
foreach (ImageSimilarityReport r in reports) | ||
{ | ||
sb.AppendFormat(CultureInfo.InvariantCulture, "Report ImageFrame {0}: ", r.Index) | ||
.Append(r) | ||
.Append(Environment.NewLine); | ||
} | ||
|
||
return sb.ToString(); | ||
} | ||
|
||
private static string GetEnvironmentName() | ||
{ | ||
if (TestEnvironment.IsMacOS) | ||
{ | ||
return "MacOS"; | ||
} | ||
|
||
if (TestEnvironment.IsLinux) | ||
{ | ||
return "Linux"; | ||
} | ||
|
||
if (TestEnvironment.IsWindows) | ||
{ | ||
return "Windows"; | ||
} | ||
|
||
return "Unknown"; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/SixLabors.Fonts.Tests/ImageComparison/Exceptions/ImageDimensionsMismatchException.cs
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,20 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
using SixLabors.ImageSharp; | ||
|
||
namespace SixLabors.Fonts.Tests.ImageComparison; | ||
|
||
public class ImageDimensionsMismatchException : ImagesSimilarityException | ||
{ | ||
public ImageDimensionsMismatchException(Size expectedSize, Size actualSize) | ||
: base($"The image dimensions {actualSize} do not match the expected {expectedSize}!") | ||
{ | ||
this.ExpectedSize = expectedSize; | ||
this.ActualSize = actualSize; | ||
} | ||
|
||
public Size ExpectedSize { get; } | ||
|
||
public Size ActualSize { get; } | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/SixLabors.Fonts.Tests/ImageComparison/Exceptions/ImagesSimilarityException.cs
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,14 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
namespace SixLabors.Fonts.Tests.ImageComparison; | ||
|
||
using System; | ||
|
||
public class ImagesSimilarityException : Exception | ||
{ | ||
public ImagesSimilarityException(string message) | ||
: base(message) | ||
{ | ||
} | ||
} |
Oops, something went wrong.