Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
Crop dial: long one-word ratio names fit a seventh slice again
cre8ive-marketing53f27602cb24
diff --git a/src/Filee.App/Controls/AspectDial.cs b/src/Filee.App/Controls/AspectDial.csindex b7a17970..da5c0558 100644--- a/src/Filee.App/Controls/AspectDial.cs+++ b/src/Filee.App/Controls/AspectDial.cs@@ -220,8 +220,7 @@ public sealed class RingSegment : Button, ICustomHitTestDrawShape(context, ink, new Point(labelCenter.X, labelCenter.Y - 9));var typeface = new Typeface(GetValue(TextElement.FontFamilyProperty), FontStyle.Normal, FontWeight.SemiBold);- // As wide as the slice is a little outside its middle; a long word gets a smaller size before it would break.- var width = 2 * ((_inner + _outer) / 2 + 6) * Math.Sin(Math.Min(Math.PI / 2, DonutGeometry.Span(_count) / 2)) - 12;+ var width = LabelWidth(_inner, _outer, _count);var direction = CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;FormattedText Text(double size) => new(Label, CultureInfo.CurrentUICulture, direction, typeface, size, ink){@@ -233,10 +232,17 @@ public sealed class RingSegment : Button, ICustomHitTestvar text = Text(12);var longest = Label.Split(' ').Max(word => new FormattedText(word, CultureInfo.CurrentUICulture, direction, typeface, 12, ink).Width);if (longest > width)- text = Text(Math.Max(9.5, 12 * width / longest));+ text = Text(Math.Max(MinLabelSize, 12 * width / longest));context.DrawText(text, new Point(labelCenter.X - width / 2, labelCenter.Y + 2));}+ /// <summary>The smallest size a long one-word label shrinks to before it breaks: ru's "Произвольные" needs 9.4 with seven slices.</summary>+ internal const double MinLabelSize = 9;++ /// <summary>As wide as the slice is a little outside its middle; a long word gets a smaller size before it would break.</summary>+ internal static double LabelWidth(double inner, double outer, int count) =>+ 2 * ((inner + outer) / 2 + 6) * Math.Sin(Math.Min(Math.PI / 2, DonutGeometry.Span(count) / 2)) - 12;+/// <summary>A small outline of the ratio over its name; free is a dashed square.</summary>private void DrawShape(DrawingContext context, IBrush? ink, Point center){@@ -258,7 +264,7 @@ public sealed class RingSegment : Button, ICustomHitTest}}-/// <summary>The dial in miniature (the toolbar button): six slices, the one in use lit.</summary>+/// <summary>The dial in miniature (the toolbar button): a slice per ratio, the one in use lit.</summary>public sealed class AspectGlyph : Control{public static readonly StyledProperty<int> SelectedIndexProperty =diff --git a/tests/Filee.App.Tests/CropOverlayTests.cs b/tests/Filee.App.Tests/CropOverlayTests.csindex 31208d7f..834e61d6 100644--- a/tests/Filee.App.Tests/CropOverlayTests.cs+++ b/tests/Filee.App.Tests/CropOverlayTests.cs@@ -288,6 +288,27 @@ public class CropOverlayTests});}+ [AvaloniaFact]+ public void Every_language_fits_its_longest_one_word_ratio_name_on_a_slice_without_breaking_it()+ {+ var dial = new AspectDial();+ var width = RingSegment.LabelWidth(dial.InnerRadius, dial.OuterRadius, CropMath.AspectModes.Count);+ var i18n = Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "..", "..", "src", "Filee.App", "Assets", "i18n");+ foreach (var language in LocalizationService.Languages.Select(l => l.Code))+ {+ var strings = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, string>>(File.ReadAllText(Path.Combine(i18n, language + ".json")))!;+ var typeface = new Avalonia.Media.Typeface(SoftPalette.FontFamilyFor(language), Avalonia.Media.FontStyle.Normal, Avalonia.Media.FontWeight.SemiBold);+ foreach (var key in new[] { "crop.aspect_free", "crop.aspect_original" })+ {+ if (!strings.TryGetValue(key, out var label))+ continue;+ var longest = label.Split(' ').Max(word => new Avalonia.Media.FormattedText(word, System.Globalization.CultureInfo.InvariantCulture,+ Avalonia.Media.FlowDirection.LeftToRight, typeface, 12, Avalonia.Media.Brushes.Black).Width);+ Assert.True(12 * width / longest >= RingSegment.MinLabelSize, $"{language} {key} \"{label}\" needs {12 * width / longest:F2}");+ }+ }+ }+[AvaloniaFact]public void An_upright_picture_crops_at_instagrams_4_to_5_from_the_5_to_4_slice(){