diff --git a/FModel/Creator/Bases/BaseItemAccess.cs b/FModel/Creator/Bases/BaseItemAccess.cs index e25cc25e..b742ced3 100644 --- a/FModel/Creator/Bases/BaseItemAccess.cs +++ b/FModel/Creator/Bases/BaseItemAccess.cs @@ -4,6 +4,7 @@ using PakReader.Pak; using PakReader.Parsers.Class; using PakReader.Parsers.PropertyTagData; using SkiaSharp; +using SkiaSharp.HarfBuzz; namespace FModel.Creator.Bases { @@ -77,11 +78,36 @@ namespace FModel.Creator.Bases Color = SKColors.White, TextAlign = SKTextAlign.Center, }; - while (namePaint.MeasureText(DisplayName) > (Size - (Item.Margin * 2))) + if ((ELanguage)Properties.Settings.Default.AssetsLanguage == ELanguage.Arabic) { - namePaint.TextSize = size -= 2; + SKShaper shaper = new SKShaper(namePaint.Typeface); + float shapedTextWidth; + + while (true) + { + SKShaper.Result shapedText = shaper.Shape(DisplayName, namePaint); + shapedTextWidth = shapedText.Points[^1].X + namePaint.TextSize / 2f; + + if (shapedTextWidth > (Size - (Item.Margin * 2))) + { + namePaint.TextSize -= 2; + } + else + { + break; + } + } + + c.DrawShapedText(shaper, DisplayName, (Size - shapedTextWidth) / 2f, Item.Margin * 8 + size, namePaint); + } + else + { + while (namePaint.MeasureText(DisplayName) > (Size - (Item.Margin * 2))) + { + namePaint.TextSize = size -= 2; + } + c.DrawText(DisplayName, left, Item.Margin * 8 + size, namePaint); } - c.DrawText(DisplayName, left, Item.Margin * 8 + size, namePaint); int topBase = Item.Margin + size * 2; c.DrawBitmap(Lock, new SKRect(50, topBase, 50 + Lock.Width, topBase + Lock.Height), @@ -102,7 +128,7 @@ namespace FModel.Creator.Bases { IsAntialias = true, FilterQuality = SKFilterQuality.High, - Typeface = Text.TypeFaces.DefaultTypeface, + Typeface = Text.TypeFaces.BottomDefaultTypeface ?? Text.TypeFaces.DefaultTypeface, TextSize = 15, Color = SKColors.White, TextAlign = SKTextAlign.Right, diff --git a/FModel/Creator/Bases/BaseSeason.cs b/FModel/Creator/Bases/BaseSeason.cs index 17870087..3c5b558b 100644 --- a/FModel/Creator/Bases/BaseSeason.cs +++ b/FModel/Creator/Bases/BaseSeason.cs @@ -3,6 +3,7 @@ using FModel.Creator.Texts; using PakReader.Parsers.Class; using PakReader.Parsers.PropertyTagData; using SkiaSharp; +using SkiaSharp.HarfBuzz; using System; using System.Collections.Generic; @@ -62,7 +63,7 @@ namespace FModel.Creator.Bases { if (reward.Value is UObject o && o.GetExport("ItemDefinition") is SoftObjectProperty itemDefinition && - //!itemDefinition.Value.AssetPathName.String.StartsWith("/Game/Athena/Items/ChallengeBundleSchedules/") && + !itemDefinition.Value.AssetPathName.String.StartsWith("/Game/Items/Tokens/") && o.GetExport("Quantity") is IntProperty quantity) { BookXpSchedule[i].Add(new Reward(quantity, itemDefinition.Value)); @@ -84,7 +85,7 @@ namespace FModel.Creator.Bases { if (reward.Value is UObject o && o.GetExport("ItemDefinition") is SoftObjectProperty itemDefinition && - //!itemDefinition.Value.AssetPathName.String.StartsWith("/Game/Athena/Items/ChallengeBundleSchedules/") && + //!itemDefinition.Value.AssetPathName.String.StartsWith("/Game/Items/Tokens/") && o.GetExport("Quantity") is IntProperty quantity) { BookXpSchedule[i].Add(new Reward(quantity, itemDefinition.Value)); @@ -177,15 +178,41 @@ namespace FModel.Creator.Bases string text = DisplayName.ToUpper(); int x = 300; - while (paint.MeasureText(text) > (Width - x)) + if ((ELanguage)Properties.Settings.Default.AssetsLanguage == ELanguage.Arabic) { - paint.TextSize -= 2; + SKShaper shaper = new SKShaper(paint.Typeface); + float shapedTextWidth; + + while (true) + { + SKShaper.Result shapedText = shaper.Shape(text, paint); + shapedTextWidth = shapedText.Points[^1].X + paint.TextSize / 2f; + + if (shapedTextWidth > Width) + { + paint.TextSize -= 2; + } + else + { + break; + } + } + + c.DrawShapedText(shaper, text, x, 155, paint); + } + else + { + while (paint.MeasureText(text) > (Width - x)) + { + paint.TextSize -= 2; + } + c.DrawText(text, x, 155, paint); } - c.DrawText(text, x, 155, paint); paint.Color = SKColors.White.WithAlpha(150); paint.TextAlign = SKTextAlign.Right; paint.TextSize = 23; + paint.Typeface = Text.TypeFaces.DefaultTypeface; c.DrawText(Watermark .Replace("{BundleName}", text) .Replace("{Date}", DateTime.Now.ToString("dd/MM/yyyy")), diff --git a/FModel/Creator/Bases/BaseUserOption.cs b/FModel/Creator/Bases/BaseUserOption.cs index 977f6851..16470651 100644 --- a/FModel/Creator/Bases/BaseUserOption.cs +++ b/FModel/Creator/Bases/BaseUserOption.cs @@ -3,6 +3,7 @@ using PakReader.Parsers.Class; using PakReader.Parsers.Objects; using PakReader.Parsers.PropertyTagData; using SkiaSharp; +using SkiaSharp.HarfBuzz; using System.Collections.Generic; namespace FModel.Creator.Bases @@ -124,17 +125,48 @@ namespace FModel.Creator.Bases Color = SKColors.White, TextAlign = SKTextAlign.Left }; - - // resize if too long - while (namePaint.MeasureText(OptionDisplayName) > (Width - (Margin * 2))) + SKPaint optionPaint = new SKPaint { - namePaint.TextSize = textSize -= 2; - } - int y = Margin + textSize; - c.DrawText(OptionDisplayName, Margin, y, namePaint); - y += (int)descriptionPaint.TextSize + (Margin / 2); + IsAntialias = true, + FilterQuality = SKFilterQuality.High, + Typeface = Text.TypeFaces.DisplayNameTypeface, + TextSize = 20, + Color = SKColor.Parse("EEFFFF"), + TextAlign = SKTextAlign.Left + }; - // wrap if too long + if ((ELanguage)Properties.Settings.Default.AssetsLanguage == ELanguage.Arabic) + { + SKShaper shaper = new SKShaper(namePaint.Typeface); + float shapedTextWidth; + + while (true) + { + SKShaper.Result shapedText = shaper.Shape(OptionDisplayName, namePaint); + shapedTextWidth = shapedText.Points[^1].X + namePaint.TextSize / 2f; + + if (shapedTextWidth > (Width - (Margin * 2))) + { + namePaint.TextSize -= 2; + } + else + { + break; + } + } + + c.DrawShapedText(shaper, OptionDisplayName, Margin, Margin + textSize, namePaint); + } + else + { + while (namePaint.MeasureText(OptionDisplayName) > (Width - (Margin * 2))) + { + namePaint.TextSize = textSize -= 2; + } + c.DrawText(OptionDisplayName, Margin, Margin + textSize, namePaint); + } + + int y = (Margin + textSize) + ((int)descriptionPaint.TextSize + (Margin / 2)); Helper.DrawMultilineText(c, OptionDescription, Width, Margin, ETextSide.Left, new SKRect(Margin, y, Width - Margin, 256), descriptionPaint, out int top); @@ -150,17 +182,17 @@ namespace FModel.Creator.Bases Color = option.Color }); - int ts = 20; - c.DrawText(option.Option, Margin + (space * 2), top + (ts * 1.1f), - new SKPaint - { - IsAntialias = true, - FilterQuality = SKFilterQuality.High, - Typeface = Text.TypeFaces.DisplayNameTypeface, - TextSize = ts, - Color = SKColor.Parse("EEFFFF"), - TextAlign = SKTextAlign.Left - }); + if ((ELanguage)Properties.Settings.Default.AssetsLanguage == ELanguage.Arabic) + { + SKShaper shaper = new SKShaper(optionPaint.Typeface); + SKShaper.Result shapedText = shaper.Shape(option.Option, optionPaint); + float shapedTextWidth = shapedText.Points[^1].X + optionPaint.TextSize / 2f; + c.DrawShapedText(shaper, option.Option, Margin + (space * 2), top + (20 * 1.1f), optionPaint); + } + else + { + c.DrawText(option.Option, Margin + (space * 2), top + (20 * 1.1f), optionPaint); + } top += height + space; } diff --git a/FModel/Creator/Bundles/HeaderStyle.cs b/FModel/Creator/Bundles/HeaderStyle.cs index d12ab7f9..271b727d 100644 --- a/FModel/Creator/Bundles/HeaderStyle.cs +++ b/FModel/Creator/Bundles/HeaderStyle.cs @@ -1,6 +1,7 @@ using FModel.Creator.Bases; using FModel.Creator.Texts; using SkiaSharp; +using SkiaSharp.HarfBuzz; using System; namespace FModel.Creator.Bundles @@ -75,15 +76,41 @@ namespace FModel.Creator.Bundles string text = icon.DisplayName.ToUpper(); int x = icon.IsDisplayNameShifted ? 300 : 50; - while (paint.MeasureText(text) > (icon.Width - x)) + if ((ELanguage)Properties.Settings.Default.AssetsLanguage == ELanguage.Arabic) { - paint.TextSize -= 2; + SKShaper shaper = new SKShaper(paint.Typeface); + float shapedTextWidth; + + while (true) + { + SKShaper.Result shapedText = shaper.Shape(text, paint); + shapedTextWidth = shapedText.Points[^1].X + paint.TextSize / 2f; + + if (shapedTextWidth > (icon.Width - x)) + { + paint.TextSize -= 1; + } + else + { + break; + } + } + + c.DrawShapedText(shaper, text, x, 155, paint); + } + else + { + while (paint.MeasureText(text) > (icon.Width - x)) + { + paint.TextSize -= 2; + } + c.DrawText(text, x, 155, paint); } - c.DrawText(text, x, 155, paint); paint.Color = SKColors.White.WithAlpha(150); paint.TextAlign = SKTextAlign.Right; paint.TextSize = 23; + paint.Typeface = Text.TypeFaces.DefaultTypeface; c.DrawText(icon.Watermark .Replace("{BundleName}", text) .Replace("{Date}", DateTime.Now.ToString("dd/MM/yyyy")), diff --git a/FModel/Creator/Bundles/QuestStyle.cs b/FModel/Creator/Bundles/QuestStyle.cs index 58243005..9578014a 100644 --- a/FModel/Creator/Bundles/QuestStyle.cs +++ b/FModel/Creator/Bundles/QuestStyle.cs @@ -1,6 +1,7 @@ using FModel.Creator.Bases; using FModel.Creator.Texts; using SkiaSharp; +using SkiaSharp.HarfBuzz; namespace FModel.Creator.Bundles { @@ -28,11 +29,39 @@ namespace FModel.Creator.Bundles paint.Color = SKColors.White; paint.TextAlign = SKTextAlign.Left; paint.Typeface = Text.TypeFaces.BundleDisplayNameTypeface; - while (paint.MeasureText(q.Description) > icon.Width - 65 - 165) + if (!string.IsNullOrEmpty(q.Description)) { - paint.TextSize -= 1; + if ((ELanguage)Properties.Settings.Default.AssetsLanguage == ELanguage.Arabic) + { + SKShaper shaper = new SKShaper(paint.Typeface); + float shapedTextWidth; + + while (true) + { + SKShaper.Result shapedText = shaper.Shape(q.Description, paint); + shapedTextWidth = shapedText.Points[^1].X + paint.TextSize / 2f; + + if (shapedTextWidth > icon.Width - 65 - 165) + { + paint.TextSize -= 1; + } + else + { + break; + } + } + + c.DrawShapedText(shaper, q.Description, 65, y + paint.TextSize + 11, paint); + } + else + { + while (paint.MeasureText(q.Description) > icon.Width - 65 - 165) + { + paint.TextSize -= 1; + } + c.DrawText(q.Description, new SKPoint(65, y + paint.TextSize + 11), paint); + } } - c.DrawText(q.Description, new SKPoint(65, y + paint.TextSize + 11), paint); paint.TextSize = 16; paint.Color = SKColors.White.WithAlpha(200); @@ -83,11 +112,36 @@ namespace FModel.Creator.Bundles paint.Color = SKColors.White; paint.TextAlign = SKTextAlign.Left; paint.Typeface = Text.TypeFaces.BundleDisplayNameTypeface; - while (paint.MeasureText(r.CompletionText) > icon.Width - 65 - 165) + if ((ELanguage)Properties.Settings.Default.AssetsLanguage == ELanguage.Arabic) { - paint.TextSize -= 1; + SKShaper shaper = new SKShaper(paint.Typeface); + float shapedTextWidth; + + while (true) + { + SKShaper.Result shapedText = shaper.Shape(r.CompletionText, paint); + shapedTextWidth = shapedText.Points[^1].X + paint.TextSize / 2f; + + if (shapedTextWidth > icon.Width - 65 - 165) + { + paint.TextSize -= 1; + } + else + { + break; + } + } + + c.DrawShapedText(shaper, r.CompletionText, 65, y + paint.TextSize + 15, paint); + } + else + { + while (paint.MeasureText(r.CompletionText) > icon.Width - 65 - 165) + { + paint.TextSize -= 1; + } + c.DrawText(r.CompletionText, new SKPoint(65, y + paint.TextSize + 15), paint); } - c.DrawText(r.CompletionText, new SKPoint(65, y + paint.TextSize + 15), paint); if (r.Reward?.RewardIcon != null) { diff --git a/FModel/Creator/Stats/Statistics.cs b/FModel/Creator/Stats/Statistics.cs index e1041ff9..ca62bdf0 100644 --- a/FModel/Creator/Stats/Statistics.cs +++ b/FModel/Creator/Stats/Statistics.cs @@ -5,6 +5,7 @@ using PakReader.Pak; using PakReader.Parsers.Class; using PakReader.Parsers.PropertyTagData; using SkiaSharp; +using SkiaSharp.HarfBuzz; using System; using System.Windows; @@ -192,13 +193,36 @@ namespace FModel.Creator.Stats TextAlign = SKTextAlign.Center, }; - // resize if too long - while (statPaint.MeasureText(stat.Description) > (icon.Size - (icon.Margin * 2) - iconSize)) + if ((ELanguage)Properties.Settings.Default.AssetsLanguage == ELanguage.Arabic) { - statPaint.TextSize = textSize -= 2; - } + SKShaper shaper = new SKShaper(statPaint.Typeface); + float shapedTextWidth; - c.DrawText(stat.Description, icon.Size / 2, y + 32, statPaint); + while (true) + { + SKShaper.Result shapedText = shaper.Shape(stat.Description, statPaint); + shapedTextWidth = shapedText.Points[^1].X + statPaint.TextSize / 2f; + + if (shapedTextWidth > (icon.Size - (icon.Margin * 2) - iconSize)) + { + statPaint.TextSize -= 2; + } + else + { + break; + } + } + + c.DrawShapedText(shaper, stat.Description, (icon.Size - shapedTextWidth) / 2f, y + 32, statPaint); + } + else + { + while (statPaint.MeasureText(stat.Description) > (icon.Size - (icon.Margin * 2) - iconSize)) + { + statPaint.TextSize = textSize -= 2; + } + c.DrawText(stat.Description, icon.Size / 2, y + 32, statPaint); + } y += size; } diff --git a/FModel/Creator/Texts/Text.cs b/FModel/Creator/Texts/Text.cs index ee565909..32003a9a 100644 --- a/FModel/Creator/Texts/Text.cs +++ b/FModel/Creator/Texts/Text.cs @@ -1,14 +1,9 @@ -using System; -using System.Collections.Generic; - +using System.Collections.Generic; using FModel.Creator.Bases; -using FModel.Properties; - using PakReader.Pak; using PakReader.Parsers.Class; using PakReader.Parsers.Objects; using PakReader.Parsers.PropertyTagData; - using SkiaSharp; using SkiaSharp.HarfBuzz; @@ -125,7 +120,7 @@ namespace FModel.Creator.Texts public static void DrawBackground(SKCanvas c, IBase icon) { - switch ((EIconDesign)Settings.Default.AssetsIconDesign) + switch ((EIconDesign)Properties.Settings.Default.AssetsIconDesign) { case EIconDesign.Flat: { @@ -162,67 +157,70 @@ namespace FModel.Creator.Texts { _NAME_TEXT_SIZE = 45; string text = icon.DisplayName; - SKTextAlign side = SKTextAlign.Center; - int x = icon.Width / 2; - int y = _STARTER_TEXT_POSITION + _NAME_TEXT_SIZE; - switch ((EIconDesign)Settings.Default.AssetsIconDesign) + if (!string.IsNullOrEmpty(text)) { - case EIconDesign.Mini: - { - _NAME_TEXT_SIZE = 47; - text = text.ToUpperInvariant(); - break; - } - case EIconDesign.Flat: - { - _NAME_TEXT_SIZE = 47; - side = SKTextAlign.Right; - x = icon.Width - icon.Margin * 2; - break; - } - } - - SKPaint namePaint = new SKPaint - { - IsAntialias = true, - FilterQuality = SKFilterQuality.High, - Typeface = TypeFaces.DisplayNameTypeface, - TextSize = _NAME_TEXT_SIZE, - Color = SKColors.White, - TextAlign = side - }; - - if ((ELanguage)Settings.Default.AssetsLanguage == ELanguage.Arabic) - { - SKShaper shaper = new SKShaper(namePaint.Typeface); - float shapedTextWidth; - - while (true) + SKTextAlign side = SKTextAlign.Center; + int x = icon.Width / 2; + int y = _STARTER_TEXT_POSITION + _NAME_TEXT_SIZE; + switch ((EIconDesign)Properties.Settings.Default.AssetsIconDesign) { - SKShaper.Result shapedText = shaper.Shape(text, namePaint); - shapedTextWidth = shapedText.Points[^1].X + namePaint.TextSize / 2f; + case EIconDesign.Mini: + { + _NAME_TEXT_SIZE = 47; + text = text.ToUpperInvariant(); + break; + } + case EIconDesign.Flat: + { + _NAME_TEXT_SIZE = 47; + side = SKTextAlign.Right; + x = icon.Width - icon.Margin * 2; + break; + } + } - if (shapedTextWidth > icon.Width - icon.Margin * 2) + SKPaint namePaint = new SKPaint + { + IsAntialias = true, + FilterQuality = SKFilterQuality.High, + Typeface = TypeFaces.DisplayNameTypeface, + TextSize = _NAME_TEXT_SIZE, + Color = SKColors.White, + TextAlign = side + }; + + if ((ELanguage)Properties.Settings.Default.AssetsLanguage == ELanguage.Arabic) + { + SKShaper shaper = new SKShaper(namePaint.Typeface); + float shapedTextWidth; + + while (true) + { + SKShaper.Result shapedText = shaper.Shape(text, namePaint); + shapedTextWidth = shapedText.Points[^1].X + namePaint.TextSize / 2f; + + if (shapedTextWidth > icon.Width - icon.Margin * 2) + { + namePaint.TextSize = _NAME_TEXT_SIZE -= 1; + } + else + { + break; + } + } + + c.DrawShapedText(shaper, text, (icon.Width - shapedTextWidth) / 2f, y, namePaint); + } + else + { + // resize if too long + while (namePaint.MeasureText(text) > icon.Width - icon.Margin * 2) { namePaint.TextSize = _NAME_TEXT_SIZE -= 1; } - else - { - break; - } - } - c.DrawShapedText(shaper, text, (icon.Width - shapedTextWidth) / 2f, y, namePaint); - } - else - { - // resize if too long - while (namePaint.MeasureText(text) > icon.Width - icon.Margin * 2) - { - namePaint.TextSize = _NAME_TEXT_SIZE -= 1; + c.DrawText(text, x, y, namePaint); } - - c.DrawText(text, x, y, namePaint); } } @@ -232,7 +230,7 @@ namespace FModel.Creator.Texts _BOTTOM_TEXT_SIZE = 15; string text = icon.Description; ETextSide side = ETextSide.Center; - switch ((EIconDesign)Settings.Default.AssetsIconDesign) + switch ((EIconDesign)Properties.Settings.Default.AssetsIconDesign) { case EIconDesign.Mini: { @@ -277,7 +275,7 @@ namespace FModel.Creator.Texts if (side == ETextSide.Left) { - if ((ELanguage)Settings.Default.AssetsLanguage == ELanguage.Arabic) + if ((ELanguage)Properties.Settings.Default.AssetsLanguage == ELanguage.Arabic) { shortDescriptionPaint.TextSize -= 4f; SKShaper shaper = new SKShaper(shortDescriptionPaint.Typeface);