From 4839c2006bfa01e55e447e474234501a7e2496a2 Mon Sep 17 00:00:00 2001 From: nyanmisaka Date: Sat, 26 Dec 2020 01:24:25 +0800 Subject: [PATCH] fix boxes in library name backdrop for CJK character --- Jellyfin.Drawing.Skia/StripCollageBuilder.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Jellyfin.Drawing.Skia/StripCollageBuilder.cs b/Jellyfin.Drawing.Skia/StripCollageBuilder.cs index 0e94f87f6a..e9f9aad57d 100644 --- a/Jellyfin.Drawing.Skia/StripCollageBuilder.cs +++ b/Jellyfin.Drawing.Skia/StripCollageBuilder.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Text.RegularExpressions; using SkiaSharp; namespace Jellyfin.Drawing.Skia @@ -118,6 +119,16 @@ namespace Jellyfin.Drawing.Skia }; canvas.DrawRect(0, 0, width, height, paintColor); + var typeFace = SKTypeface.FromFamilyName("sans-serif", SKFontStyleWeight.Bold, SKFontStyleWidth.Normal, SKFontStyleSlant.Upright); + + // use the system fallback to find a typeface for the given CJK character + var nonCjkPattern = @"[^\p{IsCJKUnifiedIdeographs}\p{IsCJKUnifiedIdeographsExtensionA}\p{IsKatakana}\p{IsHiragana}\p{IsHangulSyllables}\p{IsHangulJamo}]"; + var filteredName = Regex.Replace(libraryName ?? string.Empty, nonCjkPattern, string.Empty); + if (!string.IsNullOrEmpty(filteredName)) + { + typeFace = SKFontManager.Default.MatchCharacter(null, SKFontStyleWeight.Bold, SKFontStyleWidth.Normal, SKFontStyleSlant.Upright, null, filteredName[0]); + } + // draw library name var textPaint = new SKPaint { @@ -125,7 +136,7 @@ namespace Jellyfin.Drawing.Skia Style = SKPaintStyle.Fill, TextSize = 112, TextAlign = SKTextAlign.Center, - Typeface = SKTypeface.FromFamilyName("sans-serif", SKFontStyleWeight.Bold, SKFontStyleWidth.Normal, SKFontStyleSlant.Upright), + Typeface = typeFace, IsAntialias = true };