Skip to content

Commit ee0492e

Browse files
authored
Merge pull request #8990 from Kuldeep-MS/feat/add-hyphen-ligature
Adding AppContext Switch for disabling special character ligatures
2 parents c30fa6e + 327ad72 commit ee0492e

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/CoreAppContextSwitches.cs

+15
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,21 @@ public static bool EnableHardwareAccelerationInRdp
395395

396396
#endregion
397397

398+
#region DisableSpecialCharacterLigature
399+
400+
internal const string DisableSpecialCharacterLigatureSwitchName = "Switch.System.Windows.DisableSpecialCharacterLigature";
401+
private static int _disableSpecialCharacterLigature;
402+
public static bool DisableSpecialCharacterLigature
403+
{
404+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
405+
get
406+
{
407+
return LocalAppContext.GetCachedSwitchValue(DisableSpecialCharacterLigatureSwitchName, ref _disableSpecialCharacterLigature);
408+
}
409+
}
410+
411+
#endregion
412+
398413
}
399414
#pragma warning restore 436
400415
}

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/AppContextDefaultValues.cs

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private static void InitializeNetFxSwitchDefaultsForNetCoreRuntime()
6161
LocalAppContext.DefineSwitchDefault(CoreAppContextSwitches.DoNotUsePresentationDpiCapabilityTier3OrGreaterSwitchName, false);
6262
LocalAppContext.DefineSwitchDefault(CoreAppContextSwitches.AllowExternalProcessToBlockAccessToTemporaryFilesSwitchName, false);
6363
LocalAppContext.DefineSwitchDefault(CoreAppContextSwitches.EnableHardwareAccelerationInRdpSwitchName, false);
64+
LocalAppContext.DefineSwitchDefault(CoreAppContextSwitches.DisableSpecialCharacterLigatureSwitchName, false);
6465
}
6566
}
6667
#pragma warning restore 436

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs

+9
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ public HwndTarget(IntPtr hwnd)
276276
// DPI_AWARENESS_CONTEXT (DpiAwarenessContext property)
277277
// Window DPI scale (CurrentDpiScale field)
278278
InitializeDpiAwarenessAndDpiScales();
279+
CheckAndDisableSpecialCharacterLigature();
279280

280281
_worldTransform = new MatrixTransform(
281282
new Matrix(
@@ -311,6 +312,14 @@ public HwndTarget(IntPtr hwnd)
311312
}
312313
}
313314

315+
/// <summary>
316+
/// Disables hyphen ligatures if user has exlicitly wants it
317+
/// </summary>
318+
private void CheckAndDisableSpecialCharacterLigature()
319+
{
320+
NativeMethodsSetLastError.LsDisableSpecialCharacterLigature(CoreAppContextSwitches.DisableSpecialCharacterLigature);
321+
}
322+
314323
/// <summary>
315324
/// Ensures the system/primary monitor's DPI scale. Get the process DPI awareness.
316325
/// </summary>

src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsSetLastError.cs

+3
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,8 @@ internal static class NativeMethodsSetLastError
161161
public static extern IntPtr SetWindowLongPtrWndProc(HandleRef hWnd, int nIndex, NativeMethods.WndProc dwNewLong);
162162

163163
#endif
164+
165+
[DllImport(PresentationNativeDll, EntryPoint="LsDisableSpecialCharacterLigature")]
166+
public static extern void LsDisableSpecialCharacterLigature(bool fDisable);
164167
}
165168
}

0 commit comments

Comments
 (0)