Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Implement basic font rendering tuning for code editor. #733

Open
wants to merge 1 commit 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions data/resources/StringResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -8445,5 +8445,11 @@ Press Esc to cancel this operation.</value>
</data>
<data name="ICSharpCode.WpfDesign.AddIn.Options.EnableAppXamlParsing" xml:space="preserve">
<value>Enable App.xaml parsing</value>
</data>
<data name="Dialog.Options.IDEOptions.TextEditor.General.EnableTextAntialiasing" xml:space="preserve">
<value>Enable anti-aliasing</value>
</data>
<data name="Dialog.Options.IDEOptions.TextEditor.General.EnableTextHinting" xml:space="preserve">
<value>Enable hinting</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
<StackPanel>
<GroupBox
Header="{core:Localize Dialog.Options.IDEOptions.TextEditor.General.FontGroupBox}">
<gui:FontSelector x:Name="fontSelectionPanel" />
<widgets:StackPanelWithSpacing SpaceBetweenItems="5">
<gui:FontSelector x:Name="fontSelectionPanel" />
<CheckBox
IsChecked="{core:OptionBinding local:CodeEditorOptions.EnableTextAntialiasing}"
Content="{core:Localize Dialog.Options.IDEOptions.TextEditor.General.EnableTextAntialiasing}" />
<CheckBox
IsChecked="{core:OptionBinding local:CodeEditorOptions.EnableTextHinting}"
Content="{core:Localize Dialog.Options.IDEOptions.TextEditor.General.EnableTextHinting}" />
</widgets:StackPanelWithSpacing>
</GroupBox>
<GroupBox
Header="{core:Localize Dialog.Options.IDEOptions.TextEditor.General.GeneralOptionsGroupBox}">
Expand Down
120 changes: 120 additions & 0 deletions src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ZoomScrollViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,124 @@ public object ConvertBack(object value, Type targetType, object parameter, Syste
throw new NotImplementedException();
}
}

sealed class ZoomToTextFormattingModeConverter : IMultiValueConverter
{
public static readonly ZoomToTextFormattingModeConverter Instance = new ZoomToTextFormattingModeConverter();

public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var zoom = value[0] != null ? (double) value[0] : 1.0;
var antialiasing = value[1] != DependencyProperty.UnsetValue ? (bool) value[1] : true;
var hinting = value[2] != DependencyProperty.UnsetValue ? (bool) value[2] : true;

if (antialiasing)
{
if (hinting)
{
if (zoom == 1.0)
{
return TextFormattingMode.Display;
}
else
{
return TextFormattingMode.Ideal;
}
}
else
{
return TextFormattingMode.Ideal;
}
}
else
{
return TextFormattingMode.Display;
}
}

public object[] ConvertBack(object value, Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}

sealed class ZoomToTextRenderingModeConverter : IMultiValueConverter
{
public static readonly ZoomToTextRenderingModeConverter Instance = new ZoomToTextRenderingModeConverter();

public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var zoom = value[0] != null ? (double) value[0] : 1.0;
var antialiasing = value[1] != DependencyProperty.UnsetValue ? (bool) value[1] : true;
var hinting = value[2] != DependencyProperty.UnsetValue ? (bool) value[2] : true;

if (antialiasing)
{
if (hinting)
{
if (zoom == 1.0)
{
return TextRenderingMode.ClearType;
}
else
{
return TextRenderingMode.Grayscale;
}
}
else
{
return TextRenderingMode.Grayscale;
}
}
else
{
return TextRenderingMode.Aliased;
}
}

public object[] ConvertBack(object value, Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}

sealed class ZoomToTextHintingModeConverter : IMultiValueConverter
{
public static readonly ZoomToTextHintingModeConverter Instance = new ZoomToTextHintingModeConverter();

public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var zoom = value[0] != null ? (double) value[0] : 1.0;
var antialiasing = value[1] != DependencyProperty.UnsetValue ? (bool) value[1] : true;
var hinting = value[2] != DependencyProperty.UnsetValue ? (bool) value[2] : true;

if (antialiasing)
{
if (hinting)
{
if (zoom == 1.0)
{
return TextHintingMode.Fixed;
}
else
{
return TextHintingMode.Fixed;
}
}
else
{
return TextHintingMode.Animated;
}
}
else
{
return TextHintingMode.Fixed;
}
}

public object[] ConvertBack(object value, Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@
<ScrollContentPresenter.LayoutTransform>
<ScaleTransform ScaleX="{Binding Path=CurrentZoom, RelativeSource={RelativeSource Mode=TemplatedParent}}" ScaleY="{Binding Path=CurrentZoom, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
</ScrollContentPresenter.LayoutTransform>
<TextOptions.TextFormattingMode>
<MultiBinding Converter="{x:Static Controls:ZoomToTextFormattingModeConverter.Instance}">
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="CurrentZoom" />
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="Content.Options.EnableTextAntialiasing" />
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="Content.Options.EnableTextHinting" />
</MultiBinding>
</TextOptions.TextFormattingMode>
<TextOptions.TextRenderingMode>
<MultiBinding Converter="{x:Static Controls:ZoomToTextRenderingModeConverter.Instance}">
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="CurrentZoom" />
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="Content.Options.EnableTextAntialiasing" />
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="Content.Options.EnableTextHinting" />
</MultiBinding>
</TextOptions.TextRenderingMode>
<TextOptions.TextHintingMode>
<MultiBinding Converter="{x:Static Controls:ZoomToTextHintingModeConverter.Instance}">
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="CurrentZoom" />
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="Content.Options.EnableTextAntialiasing" />
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="Content.Options.EnableTextHinting" />
</MultiBinding>
</TextOptions.TextHintingMode>
</ScrollContentPresenter>
<ScrollBar Name="PART_VerticalScrollBar" Grid.Column="2" Grid.Row="0" Minimum="0" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Value="{TemplateBinding VerticalOffset}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" />
<ScrollBar Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Column="1" Grid.Row="1" Minimum="0" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}" Value="{TemplateBinding HorizontalOffset}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" />
Expand Down