Skip to content

Commit

Permalink
Merge pull request #262 from SixLabors/js/hangul-shaper
Browse files Browse the repository at this point in the history
Implement Hangul Shaper
  • Loading branch information
JimBobSquarePants authored May 17, 2022
2 parents 2832534 + 6a0947e commit eb87428
Show file tree
Hide file tree
Showing 36 changed files with 1,313 additions and 248 deletions.
43 changes: 42 additions & 1 deletion src/SixLabors.Fonts/GlyphMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.Fonts.Tables.General;
using SixLabors.Fonts.Tables.General.Glyphs;
using SixLabors.Fonts.Unicode;
Expand Down Expand Up @@ -237,6 +238,12 @@ internal FontRectangle GetBoundingBox(Vector2 origin, float scaledPointSize)
/// <exception cref="NotSupportedException">Too many control points</exception>
internal void RenderTo(IGlyphRenderer surface, float pointSize, Vector2 location, TextOptions options)
{
// https://www.unicode.org/faq/unsup_char.html
if (ShouldSkipGlyphRendering(this.CodePoint))
{
return;
}

float dpi = options.Dpi;
location *= dpi;
float scaledPPEM = dpi * pointSize;
Expand All @@ -255,7 +262,7 @@ internal void RenderTo(IGlyphRenderer surface, float pointSize, Vector2 location

if (surface.BeginGlyph(box, parameters))
{
if (!CodePoint.IsWhiteSpace(this.CodePoint))
if (!ShouldRenderWhiteSpaceOnly(this.CodePoint))
{
if (this.GlyphColor.HasValue && surface is IColorGlyphRenderer colorSurface)
{
Expand Down Expand Up @@ -452,6 +459,40 @@ void SetDecoration(TextDecorations decorationType, float thickness, float positi
surface.EndGlyph();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool ShouldSkipGlyphRendering(CodePoint codePoint)
{
uint value = (uint)codePoint.Value;
return UnicodeUtility.IsDefaultIgnorableCodePoint(value) && !ShouldRenderWhiteSpaceOnly(codePoint);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool ShouldRenderWhiteSpaceOnly(CodePoint codePoint)
{
if (CodePoint.IsWhiteSpace(codePoint))
{
return true;
}

// Note: While U+115F, U+1160, U+3164 and U+FFA0 are Default_Ignorable,
// we do NOT want to hide them, as the way Uniscribe has implemented them
// is with regular spacing glyphs, and that's the way fonts are made to work.
// As such, we make exceptions for those four.
// Also ignoring U+1BCA0..1BCA3. https://github.com/harfbuzz/harfbuzz/issues/503
uint value = (uint)codePoint.Value;
if (value is 0x115F or 0x1160 or 0x3164 or 0xFFA0)
{
return true;
}

if (UnicodeUtility.IsInRangeInclusive(value, 0x1BCA0, 0x1BCA3))
{
return true;
}

return false;
}

private static void AlignToGrid(ref Vector2 point)
{
var floorPoint = new Vector2(MathF.Floor(point.X), MathF.Floor(point.Y));
Expand Down
Loading

0 comments on commit eb87428

Please sign in to comment.