-
-
Notifications
You must be signed in to change notification settings - Fork 72
Ensure glyphs are not overwritten by fallbacks. #471
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| using SixLabors.ImageSharp.Drawing; | ||
| using SixLabors.ImageSharp.Drawing.Processing; | ||
| using SixLabors.ImageSharp.Drawing.Processing.Processors.Text; | ||
| using SixLabors.ImageSharp.Drawing.Text; | ||
| using SixLabors.ImageSharp.PixelFormats; | ||
| using SixLabors.ImageSharp.Processing; | ||
| using IOPath = System.IO.Path; | ||
|
|
@@ -21,15 +22,15 @@ | |
| { | ||
| var fonts = new FontCollection(); | ||
| var woffFonts = new FontCollection(); | ||
| FontFamily font = fonts.Add(IOPath.Combine("Fonts", "SixLaborsSampleAB.ttf")); | ||
|
Check warning on line 25 in samples/DrawWithImageSharp/Program.cs
|
||
| FontFamily fontWoff = woffFonts.Add(IOPath.Combine("Fonts", "SixLaborsSampleAB.woff")); | ||
|
Check warning on line 26 in samples/DrawWithImageSharp/Program.cs
|
||
| FontFamily fontWoff2 = woffFonts.Add(IOPath.Combine("Fonts", "OpenSans-Regular.woff2")); | ||
|
Check warning on line 27 in samples/DrawWithImageSharp/Program.cs
|
||
| FontFamily carter = fonts.Add(IOPath.Combine("Fonts", "CarterOne.ttf")); | ||
|
Check warning on line 28 in samples/DrawWithImageSharp/Program.cs
|
||
| FontFamily wendyOne = fonts.Add(IOPath.Combine("Fonts", "WendyOne-Regular.ttf")); | ||
|
Check warning on line 29 in samples/DrawWithImageSharp/Program.cs
|
||
| FontFamily whitneyBook = fonts.Add(IOPath.Combine("Fonts", "whitney-book.ttf")); | ||
|
Check warning on line 30 in samples/DrawWithImageSharp/Program.cs
|
||
| FontFamily colorEmoji = fonts.Add(IOPath.Combine("Fonts", "Twemoji Mozilla.ttf")); | ||
|
Check warning on line 31 in samples/DrawWithImageSharp/Program.cs
|
||
| FontFamily openSans = fonts.Add(IOPath.Combine("Fonts", "OpenSans-Regular.ttf")); | ||
|
Check warning on line 32 in samples/DrawWithImageSharp/Program.cs
|
||
| FontFamily sunflower = fonts.Add(IOPath.Combine("Fonts", "Sunflower-Medium.ttf")); | ||
|
Check warning on line 33 in samples/DrawWithImageSharp/Program.cs
|
||
| FontFamily bugzilla = fonts.Add(IOPath.Combine("Fonts", "me_quran_volt_newmet.ttf")); | ||
|
|
||
| FontFamily notoKR = fonts.Add(IOPath.Combine("Fonts", "NotoSansKR-Regular.otf")); | ||
|
|
@@ -75,10 +76,10 @@ | |
| }); | ||
|
|
||
| return; | ||
| RenderText(arial, "abcdefghijklmnopqrstuvwxyz", pointSize: 30); | ||
|
Check warning on line 79 in samples/DrawWithImageSharp/Program.cs
|
||
| RenderText(arial, "abcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz", pointSize: 30); | ||
| RenderText(arial, "abcdef ghijk lmnopq rstuvwxyz", pointSize: 30); | ||
| // return; | ||
|
Check warning on line 82 in samples/DrawWithImageSharp/Program.cs
|
||
|
|
||
| var textRuns = new List<RichTextRun> | ||
| { | ||
|
|
@@ -218,7 +219,7 @@ | |
| using var img = new Image<Rgba32>(width, height); | ||
| img.Mutate(x => x.Fill(Color.White)); | ||
|
|
||
| IPathCollection shapes = TextBuilder.GenerateGlyphs(text, new RichTextOptions(font) { Origin = new Vector2(50f, 4f) }); | ||
| IPathCollection shapes = TextBuilder.GeneratePaths(text, new RichTextOptions(font) { Origin = new Vector2(50f, 4f) }); | ||
| img.Mutate(x => x.Fill(Color.Black, shapes)); | ||
|
|
||
| Directory.CreateDirectory(IOPath.GetDirectoryName(fullPath)); | ||
|
|
@@ -288,9 +289,9 @@ | |
| float pointSize = 12, | ||
| IEnumerable<FontFamily> fallbackFonts = null) | ||
| { | ||
| foreach (VerticalAlignment va in (VerticalAlignment[])Enum.GetValues(typeof(VerticalAlignment))) | ||
|
Check warning on line 292 in samples/DrawWithImageSharp/Program.cs
|
||
| { | ||
| foreach (HorizontalAlignment ha in (HorizontalAlignment[])Enum.GetValues(typeof(HorizontalAlignment))) | ||
|
Check warning on line 294 in samples/DrawWithImageSharp/Program.cs
|
||
| { | ||
| Font font = new(fontFamily, pointSize); | ||
| RichTextOptions textOptions = new(font) | ||
|
|
@@ -320,8 +321,8 @@ | |
|
|
||
| img[size.Width / 2, size.Height / 2] = Color.White.ToPixel<Rgba32>(); | ||
|
|
||
| string h = ha.ToString().Replace(nameof(HorizontalAlignment), string.Empty).ToLower(); | ||
|
Check warning on line 324 in samples/DrawWithImageSharp/Program.cs
|
||
| string v = va.ToString().Replace(nameof(VerticalAlignment), string.Empty).ToLower(); | ||
|
Check warning on line 325 in samples/DrawWithImageSharp/Program.cs
|
||
|
|
||
| string fullPath = CreatePath(font.Name, text + "-" + h + "-" + v + ".png"); | ||
| Directory.CreateDirectory(IOPath.GetDirectoryName(fullPath)); | ||
|
|
@@ -365,7 +366,7 @@ | |
|
|
||
| var sb = new StringBuilder(); | ||
| IEnumerable<ISimplePath> converted = shape.Flatten(); | ||
| converted.Aggregate(sb, (s, p) => | ||
|
Check warning on line 369 in samples/DrawWithImageSharp/Program.cs
|
||
| { | ||
| ReadOnlySpan<PointF> points = p.Points.Span; | ||
| for (int i = 0; i < points.Length; i++) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Copyright (c) Six Labors. | ||
| // Licensed under the Six Labors Split License. | ||
|
|
||
| using System.Text; | ||
|
|
||
| namespace SixLabors.Fonts.Tests.Issues; | ||
|
|
||
| public class Issues_469 | ||
| { | ||
| [Fact] | ||
| public void Test_Issue_469() | ||
| { | ||
| const string arialFontName = "Arial"; | ||
| const string inconsolataFontName = "Inconsolata"; | ||
| const string nanumGothicCodingFontName = "NanumGothicCoding"; | ||
| const string cousineFontName = "Cousine"; | ||
| const string notoSansScThinFontName = "Noto Sans SC Thin"; | ||
| const string notoSansJpThinFontName = "Noto Sans JP Thin"; | ||
| const string notoNaskhArabicFontName = "Noto Naskh Arabic"; | ||
| const string sarabunFontName = "Sarabun"; | ||
| const string hindFontName = "Hind"; | ||
|
|
||
| StringBuilder stringBuilder = new(); | ||
| stringBuilder.AppendLine("Latin: The quick brown fox jumps over the lazy dog.") | ||
| .AppendLine("Cyrillic: Съешь же ещё этих мягких французских булок.") | ||
| .AppendLine("Greek: Ζαφείρι δέξου πάγκαλο, βαθῶν ψυχῆς τὸ σῆμα.") | ||
| .AppendLine("Chinese: 敏捷的棕色狐狸跳过了懒狗") | ||
| .AppendLine("Japanese: いろはにほへと ちりぬるを") | ||
| .AppendLine("Korean: 다람쥐 헌 쳇바퀴에 타고파") | ||
| .AppendLine("Arabic (RTL & Shaping): نص حكيم له سر قاطع وذو شأن عظيم") | ||
| .AppendLine("Hebrew (RTL): דג סקרן שט בים מאוכזב ולפתע מצא חברה") | ||
| .AppendLine("Thai (Complex): เป็นมนุษย์สุดประเสริฐเลิศคุณค่า") | ||
| .AppendLine("Devanagari (Conjuncts): ऋषियों को सताने वाले राक्षसों का अंत हो गया"); | ||
|
|
||
| string text = stringBuilder.ToString(); | ||
| FontCollection fontCollection = new(); | ||
| fontCollection.Add(TestFonts.Arial); | ||
| fontCollection.Add(TestFonts.CousineRegular); | ||
| fontCollection.Add(TestFonts.HindRegular); | ||
| fontCollection.Add(TestFonts.NanumGothicCodingRegular); | ||
| fontCollection.Add(TestFonts.InconsolataRegular); | ||
| fontCollection.Add(TestFonts.NotoNaskhArabicRegular); | ||
| fontCollection.Add(TestFonts.NotoSansHKVariableFontWght); | ||
| fontCollection.Add(TestFonts.NotoSansJPRegular); | ||
| fontCollection.Add(TestFonts.NotoSansSCRegular); | ||
| fontCollection.Add(TestFonts.SarabunRegular); | ||
|
|
||
| FontFamily mainFontFamily = fontCollection.Get(arialFontName); | ||
| Font mainFont = mainFontFamily.CreateFont(30, FontStyle.Regular); | ||
|
|
||
| TextOptions options = new(mainFont) | ||
| { | ||
| FallbackFontFamilies = | ||
| [ | ||
| fontCollection.Get(inconsolataFontName), | ||
| fontCollection.Get(nanumGothicCodingFontName), | ||
| fontCollection.Get(cousineFontName), | ||
| fontCollection.Get(notoSansScThinFontName), | ||
| fontCollection.Get(notoSansJpThinFontName), | ||
| fontCollection.Get(notoNaskhArabicFontName), | ||
| fontCollection.Get(sarabunFontName), | ||
| fontCollection.Get(hindFontName), | ||
| ], | ||
| }; | ||
|
|
||
| // There are too many metrics to validate here so we just ensure no exceptions are thrown | ||
| // and the rendering looks correct by inspecting the snapshot. | ||
| TextLayoutTestUtilities.TestLayout( | ||
| text, | ||
| options, | ||
| includeGeometry: false); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.