-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFontConfig.xaml.cs
191 lines (177 loc) · 7.92 KB
/
FontConfig.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace SkinText {
public partial class FontConfig : Window {
public FontConfig() {
InitializeComponent();
}
public void UpdateStrikethrough() {
if (textrun.TextDecorations != null) {
textrun.TextDecorations.Clear();
}
else {
textrun.TextDecorations = new TextDecorationCollection();
}
if (OverLine.IsChecked.Value) {
textrun.TextDecorations.Add(TextDecorations.OverLine);
}
if (Strikethrough.IsChecked.Value) {
textrun.TextDecorations.Add(TextDecorations.Strikethrough);
}
if (Baseline.IsChecked.Value) {
textrun.TextDecorations.Add(TextDecorations.Baseline);
}
if (Underline.IsChecked.Value) {
textrun.TextDecorations.Add(TextDecorations.Underline);
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
private void Align_Checked(object sender, RoutedEventArgs e) {
try {
System.Windows.Controls.RadioButton btn = (System.Windows.Controls.RadioButton)sender;
if (btn != null && btn.IsChecked.Value && txtSampleText != null) {
switch (btn.Name) {
case nameof(leftAlign): {
txtSampleText.Selection.Start.Paragraph.TextAlignment = TextAlignment.Left;
break;
}
case nameof(centerAlign): {
txtSampleText.Selection.Start.Paragraph.TextAlignment = TextAlignment.Center;
break;
}
case nameof(rightAlign): {
txtSampleText.Selection.Start.Paragraph.TextAlignment = TextAlignment.Right;
break;
}
case nameof(justifyAlign): {
txtSampleText.Selection.Start.Paragraph.TextAlignment = TextAlignment.Justify;
break;
}
}
}
}
catch (Exception ex) {
#if DEBUG
MessageBox.Show("DEBUG: "+ex.ToString());
//throw;
#endif
}
}
private void Apply_Click(object sender, RoutedEventArgs e) {
if (textrun.TextDecorations == null) {
textrun.TextDecorations = new TextDecorationCollection();
}
CustomMethods.TextFormat(textrun.Foreground, textrun.Background, textrun.FontFamily, textrun.FontSize, textrun.TextDecorations, textrun.FontStyle, textrun.FontWeight, txtSampleText.Selection.Start.Paragraph.TextAlignment, txtSampleText.FlowDirection, textrun.BaselineAlignment, textpar.LineHeight);
}
private void CloseButt_Click(object sender, RoutedEventArgs e) {
this.Hide();
CustomMethods.SaveConfig();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
private void ClrPcker_Bg_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs<Color?> e) {
try {
if (textrun != null) {
SolidColorBrush brush = new SolidColorBrush(ClrPcker_Bg.SelectedColor.Value);
/*if (brush.Color.A < 255) {
brush = Brushes.Transparent;
}*/
textrun.Background = brush;
//ClrPcker_Bg.SelectedColor = brush.Color;
}
}
catch (Exception ex) {
#if DEBUG
MessageBox.Show("DEBUG: "+ex.ToString());
//throw;
#endif
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
private void ClrPcker_Font_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs<Color?> e) {
try {
if (textrun != null) {
textrun.Foreground = new SolidColorBrush(ClrPcker_Font.SelectedColor.Value);
}
}
catch (Exception ex) {
#if DEBUG
MessageBox.Show("DEBUG: "+ex.ToString());
//throw;
#endif
}
}
private void FontSzLineSz_Click(object sender, RoutedEventArgs e) {
lineHeightSlider.Value = fontSizeSlider.Value;
}
private void Strikethrough_Checked(object sender, RoutedEventArgs e) {
UpdateStrikethrough();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
private void Superscript_Checked(object sender, RoutedEventArgs e) {
try {
if (textrun != null) {
System.Windows.Controls.RadioButton btn = (System.Windows.Controls.RadioButton)sender;
if (btn != null && btn.IsChecked.Value) {
switch (btn.Name) {
case nameof(topScript): {
textrun.BaselineAlignment = BaselineAlignment.Top;
break;
}
case nameof(superscript): {
textrun.BaselineAlignment = BaselineAlignment.Superscript;
break;
}
case nameof(texttopScript): {
textrun.BaselineAlignment = BaselineAlignment.TextTop;
break;
}
case nameof(centerScript): {
textrun.BaselineAlignment = BaselineAlignment.Center;
break;
}
case nameof(subscript): {
textrun.BaselineAlignment = BaselineAlignment.Subscript;
break;
}
case nameof(textbottomScript): {
textrun.BaselineAlignment = BaselineAlignment.TextBottom;
break;
}
case nameof(bottomScript): {
textrun.BaselineAlignment = BaselineAlignment.Bottom;
break;
}
case nameof(baseScript): {
textrun.BaselineAlignment = BaselineAlignment.Baseline;
break;
}
}
}
}
}
catch (Exception ex) {
#if DEBUG
MessageBox.Show("DEBUG: "+ex.ToString());
//throw;
#endif
}
}
private void Window_MouseDown(object sender, MouseButtonEventArgs e) {
if (e.ChangedButton == MouseButton.Left) {
this.DragMove();
}
}
private void FlowDirLTR_Checked(object sender, RoutedEventArgs e) {
if (txtSampleText != null) {
if (FlowDirLTR.IsChecked.Value) {
txtSampleText.FlowDirection = FlowDirection.LeftToRight;
}
else {
txtSampleText.FlowDirection = FlowDirection.RightToLeft;
}
}
}
}
}