Added a test for SKFontManager.MatchCharacter

This commit is contained in:
Matthew Leibowitz 2017-02-04 17:41:10 +04:00
Родитель ca4aa79555
Коммит 33883435bd
3 изменённых файлов: 27 добавлений и 4 удалений

Просмотреть файл

@ -92,6 +92,12 @@ namespace SkiaSharp
public SKTypeface MatchCharacter (string familyName, int weight, int width, SKFontStyleSlant slant, string[] bcp47, int character) public SKTypeface MatchCharacter (string familyName, int weight, int width, SKFontStyleSlant slant, string[] bcp47, int character)
{ {
// TODO: work around for https://bugs.chromium.org/p/skia/issues/detail?id=6196
if (familyName == null)
{
familyName = string.Empty;
}
return GetObject<SKTypeface> (SkiaApi.sk_fontmgr_match_family_style_character (Handle, familyName, weight, width, slant, bcp47, bcp47?.Length ?? 0, character)); return GetObject<SKTypeface> (SkiaApi.sk_fontmgr_match_family_style_character (Handle, familyName, weight, width, slant, bcp47, bcp47?.Length ?? 0, character));
} }
} }

Просмотреть файл

@ -27,7 +27,7 @@ namespace SkiaSharpSample.Samples
using (var courier = SKTypeface.FromFamilyName("Courier New")) using (var courier = SKTypeface.FromFamilyName("Courier New"))
{ {
paint.Typeface = courier; paint.Typeface = courier;
canvas.DrawText("'A' and 'ݐ' and '年'", 40, 100, paint); canvas.DrawText("'A', 'ݐ', '年'", 40, 100, paint);
} }
// the font manager finds fonts // the font manager finds fonts
@ -38,7 +38,7 @@ namespace SkiaSharpSample.Samples
using (var courier = fontManager.MatchCharacter("Courier New", 'ݐ')) using (var courier = fontManager.MatchCharacter("Courier New", 'ݐ'))
{ {
paint.Typeface = courier; paint.Typeface = courier;
canvas.DrawText("'A' and 'ݐ' and '年'", 40, 200, paint); canvas.DrawText("'A', 'ݐ', '年'", 40, 200, paint);
} }
// if we know the font doesn't have the character, or don't want to fall back // if we know the font doesn't have the character, or don't want to fall back
@ -46,7 +46,7 @@ namespace SkiaSharpSample.Samples
using (var courier = SKTypeface.FromFamilyName("Courier New")) using (var courier = SKTypeface.FromFamilyName("Courier New"))
using (var japanese = fontManager.MatchCharacter("Courier New", '年')) using (var japanese = fontManager.MatchCharacter("Courier New", '年'))
{ {
var first = "'A' and 'ݐ' and '"; var first = "'A', 'ݐ', '";
var mid = "年"; var mid = "年";
var last = "'"; var last = "'";
@ -73,7 +73,7 @@ namespace SkiaSharpSample.Samples
using (var emoji = fontManager.MatchCharacter(emojiChar)) using (var emoji = fontManager.MatchCharacter(emojiChar))
{ {
paint.Typeface = emoji; paint.Typeface = emoji;
canvas.DrawText("🌐 🍪 🍕 🚀", 40, 400, paint); canvas.DrawText("🌐 🍪 🍕 🚀", 40, 400, paint);
} }
} }
} }

Просмотреть файл

@ -97,6 +97,23 @@ namespace SkiaSharp.Tests
} }
} }
[Fact]
public void TestFontManagerMatchCharacter()
{
var fonts = SKFontManager.Default;
var emoji = "🚀";
var emojiChar = StringUtilities.GetUnicodeCharacterCode(emoji, SKTextEncoding.Utf32);
using (var typeface = fonts.MatchCharacter(emojiChar))
{
if (IsLinux)
Assert.Equal("", typeface.FamilyName); // see issue #225
else if (IsMac)
Assert.Equal("Apple Color Emoji", typeface.FamilyName);
else if (IsWindows)
Assert.Equal("Segoe UI Emoji", typeface.FamilyName);
}
}
[Fact] [Fact]
public void ExceptionInInvalidGetTableData() public void ExceptionInInvalidGetTableData()
{ {