diff --git a/samples/AvalonDraw/MainWindow.axaml.cs b/samples/AvalonDraw/MainWindow.axaml.cs index 591d8dbbb7..dfd8a4baba 100644 --- a/samples/AvalonDraw/MainWindow.axaml.cs +++ b/samples/AvalonDraw/MainWindow.axaml.cs @@ -2166,12 +2166,13 @@ private async void EditTextMenuItem_Click(object? sender, RoutedEventArgs e) { if (_document is null) return; - var win = new TextEditorWindow(_document.GetXML()); - var result = await win.ShowDialog(this); - if (!string.IsNullOrEmpty(result)) + var win = new TextEditorWindow(_document.GetXML(), _toolService.CurrentFontFamily, + _toolService.CurrentFontWeight, _toolService.CurrentLetterSpacing, _toolService.CurrentWordSpacing); + var ok = await win.ShowDialog(this); + if (ok) { SaveUndoState(); - _document = SvgService.FromSvg(result); + _document = SvgService.FromSvg(win.TextResult); SvgView.SkSvg!.FromSvgDocument(_document); BuildTree(); } @@ -2181,12 +2182,21 @@ private async void EditContentMenuItem_Click(object? sender, RoutedEventArgs e) { if (_selectedSvgElement is SvgTextBase txt && _document is { }) { - var win = new TextEditorWindow(txt.Text); - var result = await win.ShowDialog(this); - if (result is not null) + var win = new TextEditorWindow( + txt.Text, + txt.FontFamily, + txt.FontWeight, + txt.LetterSpacing.Value, + txt.WordSpacing.Value); + var ok2 = await win.ShowDialog(this); + if (ok2) { SaveUndoState(); - txt.Text = result; + txt.Text = win.TextResult; + txt.FontFamily = win.FontFamilyResult; + txt.FontWeight = win.FontWeightResult; + txt.LetterSpacing = new SvgUnit(SvgUnitType.User, win.LetterSpacingResult); + txt.WordSpacing = new SvgUnit(SvgUnitType.User, win.WordSpacingResult); SvgView.SkSvg!.FromSvgDocument(_document); UpdateSelectedDrawable(); LoadProperties(txt); diff --git a/samples/AvalonDraw/Services/ToolService.cs b/samples/AvalonDraw/Services/ToolService.cs index d5438bd869..314aa262ff 100644 --- a/samples/AvalonDraw/Services/ToolService.cs +++ b/samples/AvalonDraw/Services/ToolService.cs @@ -37,6 +37,11 @@ public enum Tool public float CurrentStrokeWidth { get; set; } = 1f; + public string CurrentFontFamily { get; set; } = "Arial"; + public SvgFontWeight CurrentFontWeight { get; set; } = SvgFontWeight.Normal; + public float CurrentLetterSpacing { get; set; } = 0f; + public float CurrentWordSpacing { get; set; } = 0f; + public event Action? ToolChanged; public void SetTool(Tool tool) @@ -109,20 +114,32 @@ public void SetTool(Tool tool) { X = new SvgUnitCollection { new SvgUnit(SvgUnitType.User, start.X) }, Y = new SvgUnitCollection { new SvgUnit(SvgUnitType.User, start.Y) }, - Text = "Text" + Text = "Text", + FontFamily = CurrentFontFamily, + FontWeight = CurrentFontWeight, + LetterSpacing = new SvgUnit(SvgUnitType.User, CurrentLetterSpacing), + WordSpacing = new SvgUnit(SvgUnitType.User, CurrentWordSpacing) }, Tool.TextPath when !string.IsNullOrEmpty(ReferenceId) => new SvgTextPath { ReferencedPath = new Uri($"#{ReferenceId}", UriKind.Relative), StartOffset = new SvgUnit(SvgUnitType.User, 0), - Text = "Text" + Text = "Text", + FontFamily = CurrentFontFamily, + FontWeight = CurrentFontWeight, + LetterSpacing = new SvgUnit(SvgUnitType.User, CurrentLetterSpacing), + WordSpacing = new SvgUnit(SvgUnitType.User, CurrentWordSpacing) }, Tool.TextArea when !string.IsNullOrEmpty(ReferenceId) => new SvgText { X = new SvgUnitCollection { new SvgUnit(SvgUnitType.User, start.X) }, Y = new SvgUnitCollection { new SvgUnit(SvgUnitType.User, start.Y) }, ClipPath = new Uri($"#{ReferenceId}", UriKind.Relative), - Text = "Text" + Text = "Text", + FontFamily = CurrentFontFamily, + FontWeight = CurrentFontWeight, + LetterSpacing = new SvgUnit(SvgUnitType.User, CurrentLetterSpacing), + WordSpacing = new SvgUnit(SvgUnitType.User, CurrentWordSpacing) }, Tool.PathLine => CreatePath(start, Tool.PathLine), Tool.PathCubic => CreatePath(start, Tool.PathCubic), diff --git a/samples/AvalonDraw/TextEditorWindow.axaml b/samples/AvalonDraw/TextEditorWindow.axaml index 2480bfce6c..02e20af58a 100644 --- a/samples/AvalonDraw/TextEditorWindow.axaml +++ b/samples/AvalonDraw/TextEditorWindow.axaml @@ -5,6 +5,14 @@ Title="Edit SVG Text"> + + + + + + + +