Skip to content

Commit

Permalink
upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
hellzerg committed Aug 19, 2023
1 parent 2e48f90 commit 2e89125
Show file tree
Hide file tree
Showing 10 changed files with 931 additions and 630 deletions.
16 changes: 16 additions & 0 deletions Optimizer/FontHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ internal static void ChangeGlobalFont(string fontName)
}
}

internal static string GetCurrentGlobalFont()
{
try
{
using (RegistryKey fontSubstitutesKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes", false))
{
return fontSubstitutesKey.GetValue("Segoe UI", string.Empty) as string;
}
}
catch (Exception ex)
{
ErrorLogger.LogError("FontHelper.GetCurrentGlobalFont", ex.Message, ex.StackTrace);
return string.Empty;
}
}

internal static void RestoreDefaultGlobalFont()
{
try
Expand Down
2 changes: 1 addition & 1 deletion Optimizer/Forms/FirstRunForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

379 changes: 293 additions & 86 deletions Optimizer/Forms/MainForm.Designer.cs

Large diffs are not rendered by default.

58 changes: 56 additions & 2 deletions Optimizer/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public sealed partial class MainForm : Form
bool _skipSystemRestore = false;

string[] _currentDNS;
string[] _availableFonts;

ColorOverrider _colorOverrider;

Expand Down Expand Up @@ -950,6 +951,7 @@ public MainForm(SplashForm _splashForm, bool disableIndicium = false, bool disab
LoadReadyMenusState();
GetDesktopItems();
GetCustomCommands();
LoadAvailableFonts();
}
else
{
Expand Down Expand Up @@ -1061,6 +1063,16 @@ public MainForm(SplashForm _splashForm, bool disableIndicium = false, bool disab
EnableToggleEvents();
}

private void LoadAvailableFonts()
{
listFonts.Items.Clear();
_availableFonts = FontHelper.GetAvailableFonts().ToArray();
listFonts.Items.AddRange(_availableFonts);
string currentFont = FontHelper.GetCurrentGlobalFont();
lblCurrentFont.Text = !string.IsNullOrEmpty(currentFont) ? currentFont : "-";
lblFontsNumber.Text = _availableFonts.Length.ToString();
}

private void FixFormSize()
{
int desiredWidth = (tabCollection.ItemSize.Width * tabCollection.TabPages.Count) + (Program.DPI_PREFERENCE / 3);
Expand Down Expand Up @@ -4346,7 +4358,7 @@ private void boxLang_SelectedIndexChanged(object sender, EventArgs e)
}
else if (boxLang.Text == Constants.TAIWANESE)
{
picFlag.Image = Properties.Resources.taiwan;
picFlag.Image = Properties.Resources.china;
Options.CurrentOptions.LanguageCode = LanguageCode.TW;
}
else if (boxLang.Text == Constants.KOREAN)
Expand Down Expand Up @@ -4405,6 +4417,7 @@ private void boxLang_SelectedIndexChanged(object sender, EventArgs e)
Translate();

FixFormSize();
btnUpdate.Focus();
}

private void cleanDriveB_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -4793,5 +4806,46 @@ private void linkLabel6_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
{
Process.Start(_featureRequestLink);
}

private void btnRefreshFonts_Click(object sender, EventArgs e)
{
LoadAvailableFonts();
}

private void btnRestoreFont_Click(object sender, EventArgs e)
{
if (MessageBox.Show(_uwpRestoreMessage, "Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
FontHelper.RestoreDefaultGlobalFont();
ShowRestartNeeded();
}
}

private void btnSetGlobalFont_Click(object sender, EventArgs e)
{
if (listFonts.SelectedIndex < 0)
{
return;
}
if (MessageBox.Show(_uwpRestoreMessage, "Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
string fontName = listFonts.SelectedItem.ToString();
FontHelper.ChangeGlobalFont(fontName);
ShowRestartNeeded();
}
}

private void txtSearchFonts_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtSearchFonts.Text))
{
listFonts.Items.Clear();
listFonts.Items.AddRange(_availableFonts.Where(x => x.ToLowerInvariant().Contains(txtSearchFonts.Text.ToLowerInvariant().Trim())).ToArray());
}
else
{
LoadAvailableFonts();
}
}
}
}
}
Loading

0 comments on commit 2e89125

Please sign in to comment.