Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow users changing font stretch #933

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal void HookExternalEvents()
AppSettingsService.OnFontSizeChanged += EditorSettingsService_OnFontSizeChanged;
AppSettingsService.OnFontStyleChanged += EditorSettingsService_OnFontStyleChanged;
AppSettingsService.OnFontWeightChanged += EditorSettingsService_OnFontWeightChanged;
AppSettingsService.OnFontStretchChanged += EditorSettingsService_OnFontStretchChanged;
AppSettingsService.OnDefaultTextWrappingChanged += EditorSettingsService_OnDefaultTextWrappingChanged;
AppSettingsService.OnHighlightMisspelledWordsChanged += EditorSettingsService_OnHighlightMisspelledWordsChanged;
AppSettingsService.OnDefaultDisplayLineNumbersViewStateChanged += EditorSettingsService_OnDefaultDisplayLineNumbersViewStateChanged;
Expand All @@ -29,6 +30,7 @@ internal void UnhookExternalEvents()
AppSettingsService.OnFontSizeChanged -= EditorSettingsService_OnFontSizeChanged;
AppSettingsService.OnFontStyleChanged -= EditorSettingsService_OnFontStyleChanged;
AppSettingsService.OnFontWeightChanged -= EditorSettingsService_OnFontWeightChanged;
AppSettingsService.OnFontStretchChanged -= EditorSettingsService_OnFontStretchChanged;
AppSettingsService.OnDefaultTextWrappingChanged -= EditorSettingsService_OnDefaultTextWrappingChanged;
AppSettingsService.OnHighlightMisspelledWordsChanged -= EditorSettingsService_OnHighlightMisspelledWordsChanged;
AppSettingsService.OnDefaultDisplayLineNumbersViewStateChanged -= EditorSettingsService_OnDefaultDisplayLineNumbersViewStateChanged;
Expand Down Expand Up @@ -70,6 +72,17 @@ private async void EditorSettingsService_OnFontWeightChanged(object sender, Font
});
}

private async void EditorSettingsService_OnFontStretchChanged(object sender, FontStretch fontStretch)
{
await Dispatcher.CallOnUIThreadAsync(() =>
{
//FontStretch = fontStretch;
var format = Document.GetDefaultCharacterFormat();
format.FontStretch = fontStretch;
Document.SetDefaultCharacterFormat(format);
});
}

private async void EditorSettingsService_OnDefaultTextWrappingChanged(object sender, TextWrapping textWrapping)
{
await Dispatcher.CallOnUIThreadAsync(() =>
Expand Down
5 changes: 5 additions & 0 deletions src/Notepads/Controls/TextEditor/TextEditorCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public TextEditorCore()
FontSize = AppSettingsService.EditorFontSize;
FontStyle = AppSettingsService.EditorFontStyle;
FontWeight = AppSettingsService.EditorFontWeight;
//FontStretch = AppSettingsService.EditorFontStretch;
var format = Document.GetDefaultCharacterFormat();
format.FontStretch = AppSettingsService.EditorFontStretch;
Document.SetDefaultCharacterFormat(format);

SelectionHighlightColor = new SolidColorBrush(ThemeSettingsService.AppAccentColor);
SelectionHighlightColorWhenNotFocused = new SolidColorBrush(ThemeSettingsService.AppAccentColor);
SelectionFlyout = null;
Expand Down
24 changes: 24 additions & 0 deletions src/Notepads/Services/AppSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static class AppSettingsService
public static event EventHandler<string> OnFontFamilyChanged;
public static event EventHandler<FontStyle> OnFontStyleChanged;
public static event EventHandler<FontWeight> OnFontWeightChanged;
public static event EventHandler<FontStretch> OnFontStretchChanged;
public static event EventHandler<int> OnFontSizeChanged;
public static event EventHandler<TextWrapping> OnDefaultTextWrappingChanged;
public static event EventHandler<bool> OnDefaultLineHighlighterViewStateChanged;
Expand Down Expand Up @@ -75,6 +76,19 @@ public static FontWeight EditorFontWeight
}
}

private static FontStretch _editorFontStretch;

public static FontStretch EditorFontStretch
{
get => _editorFontStretch;
set
{
_editorFontStretch = value;
OnFontStretchChanged?.Invoke(null, value);
ApplicationSettingsStore.Write(SettingsKey.EditorFontStretchStr, value.ToString());
}
}

private static TextWrapping _editorDefaultTextWrapping;

public static TextWrapping EditorDefaultTextWrapping
Expand Down Expand Up @@ -555,6 +569,16 @@ private static void InitializeFontSettings()
{
_editorFontWeight = FontWeights.Normal;
}

if (ApplicationSettingsStore.Read(SettingsKey.EditorFontStretchStr) is string fontStretchStr &&
Enum.TryParse(typeof(FontStretch), fontStretchStr, out var fontStretch))
{
_editorFontStretch = (FontStretch)fontStretch;
}
else
{
_editorFontStretch = FontStretch.Normal;
}
}

private static void InitializeAppOpeningPreferencesSettings()
Expand Down
1 change: 1 addition & 0 deletions src/Notepads/Settings/SettingsKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal static class SettingsKey
internal static string EditorFontSizeInt = "EditorFontSizeInt";
internal static string EditorFontStyleStr = "EditorFontStyleStr";
internal static string EditorFontWeightUshort = "EditorFontWeightUshort";
internal static string EditorFontStretchStr = "EditorFontStretchStr";
internal static string EditorDefaultTextWrappingStr = "EditorDefaultTextWrappingStr";
internal static string EditorDefaultLineHighlighterViewStateBool = "EditorDefaultLineHighlighterViewStateBool";
internal static string EditorDefaultLineEndingStr = "EditorDefaultLineEndingStr";
Expand Down
36 changes: 36 additions & 0 deletions src/Notepads/Strings/ar-YE/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -693,4 +693,40 @@
<value>صيغة الملف "{0}" غير مدعومة في الوقت الحاضر.</value>
<comment>FileRenameError: Extension is not currently supported. {0} stands for the file extension string.</comment>
</data>
<data name="FontStretch_Condensed" xml:space="preserve">
<value>Condensed</value>
<comment>FontStretch: "Condensed"</comment>
</data>
<data name="FontStretch_Expanded" xml:space="preserve">
<value>Expanded</value>
<comment>FontStretch: "Expanded"</comment>
</data>
<data name="FontStretch_ExtraCondensed" xml:space="preserve">
<value>ExtraCondensed</value>
<comment>FontStretch: "ExtraCondensed"</comment>
</data>
<data name="FontStretch_ExtraExpanded" xml:space="preserve">
<value>ExtraExpanded</value>
<comment>FontStretch: "ExtraExpanded"</comment>
</data>
<data name="FontStretch_Normal" xml:space="preserve">
<value>Normal</value>
<comment>FontStretch: "Normal"</comment>
</data>
<data name="FontStretch_SemiCondensed" xml:space="preserve">
<value>SemiCondensed</value>
<comment>FontStretch: "SemiCondensed"</comment>
</data>
<data name="FontStretch_SemiExpanded" xml:space="preserve">
<value>SemiExpanded</value>
<comment>FontStretch: "SemiExpanded"</comment>
</data>
<data name="FontStretch_UltraCondensed" xml:space="preserve">
<value>UltraCondensed</value>
<comment>FontStretch: "UltraCondensed"</comment>
</data>
<data name="FontStretch_UltraExpanded" xml:space="preserve">
<value>UltraExpanded</value>
<comment>FontStretch: "UltraExpanded"</comment>
</data>
</root>
4 changes: 4 additions & 0 deletions src/Notepads/Strings/ar-YE/Settings.resw
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,8 @@
<value>الإفتراضي في النظام</value>
<comment>AdvancedPage LanguagePreferenceSettings System Default option text.</comment>
</data>
<data name="TextAndEditorPage_FontStretchSettings_Title.Text" xml:space="preserve">
<value>Default Font Stretch</value>
<comment>TextAndEditorPage FontStretchSettings Title display text.</comment>
</data>
</root>
36 changes: 36 additions & 0 deletions src/Notepads/Strings/bg-BG/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -693,4 +693,40 @@
<value>File extension "{0}" is not supported at this moment</value>
<comment>FileRenameError: Extension is not currently supported. {0} stands for the file extension string.</comment>
</data>
<data name="FontStretch_Condensed" xml:space="preserve">
<value>Condensed</value>
<comment>FontStretch: "Condensed"</comment>
</data>
<data name="FontStretch_Expanded" xml:space="preserve">
<value>Expanded</value>
<comment>FontStretch: "Expanded"</comment>
</data>
<data name="FontStretch_ExtraCondensed" xml:space="preserve">
<value>ExtraCondensed</value>
<comment>FontStretch: "ExtraCondensed"</comment>
</data>
<data name="FontStretch_ExtraExpanded" xml:space="preserve">
<value>ExtraExpanded</value>
<comment>FontStretch: "ExtraExpanded"</comment>
</data>
<data name="FontStretch_Normal" xml:space="preserve">
<value>Normal</value>
<comment>FontStretch: "Normal"</comment>
</data>
<data name="FontStretch_SemiCondensed" xml:space="preserve">
<value>SemiCondensed</value>
<comment>FontStretch: "SemiCondensed"</comment>
</data>
<data name="FontStretch_SemiExpanded" xml:space="preserve">
<value>SemiExpanded</value>
<comment>FontStretch: "SemiExpanded"</comment>
</data>
<data name="FontStretch_UltraCondensed" xml:space="preserve">
<value>UltraCondensed</value>
<comment>FontStretch: "UltraCondensed"</comment>
</data>
<data name="FontStretch_UltraExpanded" xml:space="preserve">
<value>UltraExpanded</value>
<comment>FontStretch: "UltraExpanded"</comment>
</data>
</root>
4 changes: 4 additions & 0 deletions src/Notepads/Strings/bg-BG/Settings.resw
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,8 @@
<value>System Default</value>
<comment>AdvancedPage LanguagePreferenceSettings System Default option text.</comment>
</data>
<data name="TextAndEditorPage_FontStretchSettings_Title.Text" xml:space="preserve">
<value>Default Font Stretch</value>
<comment>TextAndEditorPage FontStretchSettings Title display text.</comment>
</data>
</root>
36 changes: 36 additions & 0 deletions src/Notepads/Strings/cs-CZ/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -693,4 +693,40 @@
<value>Souborová přípona "{0}" není v tento moment podporována</value>
<comment>FileRenameError: Extension is not currently supported. {0} stands for the file extension string.</comment>
</data>
<data name="FontStretch_Condensed" xml:space="preserve">
<value>Condensed</value>
<comment>FontStretch: "Condensed"</comment>
</data>
<data name="FontStretch_Expanded" xml:space="preserve">
<value>Expanded</value>
<comment>FontStretch: "Expanded"</comment>
</data>
<data name="FontStretch_ExtraCondensed" xml:space="preserve">
<value>ExtraCondensed</value>
<comment>FontStretch: "ExtraCondensed"</comment>
</data>
<data name="FontStretch_ExtraExpanded" xml:space="preserve">
<value>ExtraExpanded</value>
<comment>FontStretch: "ExtraExpanded"</comment>
</data>
<data name="FontStretch_Normal" xml:space="preserve">
<value>Normal</value>
<comment>FontStretch: "Normal"</comment>
</data>
<data name="FontStretch_SemiCondensed" xml:space="preserve">
<value>SemiCondensed</value>
<comment>FontStretch: "SemiCondensed"</comment>
</data>
<data name="FontStretch_SemiExpanded" xml:space="preserve">
<value>SemiExpanded</value>
<comment>FontStretch: "SemiExpanded"</comment>
</data>
<data name="FontStretch_UltraCondensed" xml:space="preserve">
<value>UltraCondensed</value>
<comment>FontStretch: "UltraCondensed"</comment>
</data>
<data name="FontStretch_UltraExpanded" xml:space="preserve">
<value>UltraExpanded</value>
<comment>FontStretch: "UltraExpanded"</comment>
</data>
</root>
4 changes: 4 additions & 0 deletions src/Notepads/Strings/cs-CZ/Settings.resw
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,8 @@
<value>Výchozí systémový</value>
<comment>AdvancedPage LanguagePreferenceSettings System Default option text.</comment>
</data>
<data name="TextAndEditorPage_FontStretchSettings_Title.Text" xml:space="preserve">
<value>Default Font Stretch</value>
<comment>TextAndEditorPage FontStretchSettings Title display text.</comment>
</data>
</root>
36 changes: 36 additions & 0 deletions src/Notepads/Strings/de-CH/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -693,4 +693,40 @@
<value>File extension "{0}" is not supported at this moment</value>
<comment>FileRenameError: Extension is not currently supported. {0} stands for the file extension string.</comment>
</data>
<data name="FontStretch_Condensed" xml:space="preserve">
<value>Condensed</value>
<comment>FontStretch: "Condensed"</comment>
</data>
<data name="FontStretch_Expanded" xml:space="preserve">
<value>Expanded</value>
<comment>FontStretch: "Expanded"</comment>
</data>
<data name="FontStretch_ExtraCondensed" xml:space="preserve">
<value>ExtraCondensed</value>
<comment>FontStretch: "ExtraCondensed"</comment>
</data>
<data name="FontStretch_ExtraExpanded" xml:space="preserve">
<value>ExtraExpanded</value>
<comment>FontStretch: "ExtraExpanded"</comment>
</data>
<data name="FontStretch_Normal" xml:space="preserve">
<value>Normal</value>
<comment>FontStretch: "Normal"</comment>
</data>
<data name="FontStretch_SemiCondensed" xml:space="preserve">
<value>SemiCondensed</value>
<comment>FontStretch: "SemiCondensed"</comment>
</data>
<data name="FontStretch_SemiExpanded" xml:space="preserve">
<value>SemiExpanded</value>
<comment>FontStretch: "SemiExpanded"</comment>
</data>
<data name="FontStretch_UltraCondensed" xml:space="preserve">
<value>UltraCondensed</value>
<comment>FontStretch: "UltraCondensed"</comment>
</data>
<data name="FontStretch_UltraExpanded" xml:space="preserve">
<value>UltraExpanded</value>
<comment>FontStretch: "UltraExpanded"</comment>
</data>
</root>
4 changes: 4 additions & 0 deletions src/Notepads/Strings/de-CH/Settings.resw
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,8 @@
<value>System Default</value>
<comment>AdvancedPage LanguagePreferenceSettings System Default option text.</comment>
</data>
<data name="TextAndEditorPage_FontStretchSettings_Title.Text" xml:space="preserve">
<value>Default Font Stretch</value>
<comment>TextAndEditorPage FontStretchSettings Title display text.</comment>
</data>
</root>
36 changes: 36 additions & 0 deletions src/Notepads/Strings/de-DE/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -693,4 +693,40 @@
<value>File extension "{0}" is not supported at this moment</value>
<comment>FileRenameError: Extension is not currently supported. {0} stands for the file extension string.</comment>
</data>
<data name="FontStretch_Condensed" xml:space="preserve">
<value>Condensed</value>
<comment>FontStretch: "Condensed"</comment>
</data>
<data name="FontStretch_Expanded" xml:space="preserve">
<value>Expanded</value>
<comment>FontStretch: "Expanded"</comment>
</data>
<data name="FontStretch_ExtraCondensed" xml:space="preserve">
<value>ExtraCondensed</value>
<comment>FontStretch: "ExtraCondensed"</comment>
</data>
<data name="FontStretch_ExtraExpanded" xml:space="preserve">
<value>ExtraExpanded</value>
<comment>FontStretch: "ExtraExpanded"</comment>
</data>
<data name="FontStretch_Normal" xml:space="preserve">
<value>Normal</value>
<comment>FontStretch: "Normal"</comment>
</data>
<data name="FontStretch_SemiCondensed" xml:space="preserve">
<value>SemiCondensed</value>
<comment>FontStretch: "SemiCondensed"</comment>
</data>
<data name="FontStretch_SemiExpanded" xml:space="preserve">
<value>SemiExpanded</value>
<comment>FontStretch: "SemiExpanded"</comment>
</data>
<data name="FontStretch_UltraCondensed" xml:space="preserve">
<value>UltraCondensed</value>
<comment>FontStretch: "UltraCondensed"</comment>
</data>
<data name="FontStretch_UltraExpanded" xml:space="preserve">
<value>UltraExpanded</value>
<comment>FontStretch: "UltraExpanded"</comment>
</data>
</root>
4 changes: 4 additions & 0 deletions src/Notepads/Strings/de-DE/Settings.resw
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,8 @@
<value>System Default</value>
<comment>AdvancedPage LanguagePreferenceSettings System Default option text.</comment>
</data>
<data name="TextAndEditorPage_FontStretchSettings_Title.Text" xml:space="preserve">
<value>Default Font Stretch</value>
<comment>TextAndEditorPage FontStretchSettings Title display text.</comment>
</data>
</root>