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

Commit 03d0103

Browse files
committed
Implement basic font rendering tuning for code editor. (1/2: Main+AddIns part)
Ability to disable anti-aliasing for 'pixel-perfect' fonts like Courier New. Ability to disable hinting to forget about jagged default WPF rendering.
1 parent d6ebb70 commit 03d0103

File tree

4 files changed

+158
-1
lines changed

4 files changed

+158
-1
lines changed

data/resources/StringResources.resx

+6
Original file line numberDiff line numberDiff line change
@@ -8445,5 +8445,11 @@ Press Esc to cancel this operation.</value>
84458445
</data>
84468446
<data name="ICSharpCode.WpfDesign.AddIn.Options.EnableAppXamlParsing" xml:space="preserve">
84478447
<value>Enable App.xaml parsing</value>
8448+
</data>
8449+
<data name="Dialog.Options.IDEOptions.TextEditor.General.EnableTextAntialiasing" xml:space="preserve">
8450+
<value>Enable anti-aliasing</value>
8451+
</data>
8452+
<data name="Dialog.Options.IDEOptions.TextEditor.General.EnableTextHinting" xml:space="preserve">
8453+
<value>Enable hinting</value>
84488454
</data>
84498455
</root>

src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/GeneralEditorOptions.xaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
<StackPanel>
55
<GroupBox
66
Header="{core:Localize Dialog.Options.IDEOptions.TextEditor.General.FontGroupBox}">
7-
<gui:FontSelector x:Name="fontSelectionPanel" />
7+
<widgets:StackPanelWithSpacing SpaceBetweenItems="5">
8+
<gui:FontSelector x:Name="fontSelectionPanel" />
9+
<CheckBox
10+
IsChecked="{core:OptionBinding local:CodeEditorOptions.EnableTextAntialiasing}"
11+
Content="{core:Localize Dialog.Options.IDEOptions.TextEditor.General.EnableTextAntialiasing}" />
12+
<CheckBox
13+
IsChecked="{core:OptionBinding local:CodeEditorOptions.EnableTextHinting}"
14+
Content="{core:Localize Dialog.Options.IDEOptions.TextEditor.General.EnableTextHinting}" />
15+
</widgets:StackPanelWithSpacing>
816
</GroupBox>
917
<GroupBox
1018
Header="{core:Localize Dialog.Options.IDEOptions.TextEditor.General.GeneralOptionsGroupBox}">

src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ZoomScrollViewer.cs

+120
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,124 @@ public object ConvertBack(object value, Type targetType, object parameter, Syste
186186
throw new NotImplementedException();
187187
}
188188
}
189+
190+
sealed class ZoomToTextFormattingModeConverter : IMultiValueConverter
191+
{
192+
public static readonly ZoomToTextFormattingModeConverter Instance = new ZoomToTextFormattingModeConverter();
193+
194+
public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
195+
{
196+
var zoom = value[0] != null ? (double) value[0] : 1.0;
197+
var antialiasing = value[1] != DependencyProperty.UnsetValue ? (bool) value[1] : true;
198+
var hinting = value[2] != DependencyProperty.UnsetValue ? (bool) value[2] : true;
199+
200+
if (antialiasing)
201+
{
202+
if (hinting)
203+
{
204+
if (zoom == 1.0)
205+
{
206+
return TextFormattingMode.Display;
207+
}
208+
else
209+
{
210+
return TextFormattingMode.Ideal;
211+
}
212+
}
213+
else
214+
{
215+
return TextFormattingMode.Ideal;
216+
}
217+
}
218+
else
219+
{
220+
return TextFormattingMode.Display;
221+
}
222+
}
223+
224+
public object[] ConvertBack(object value, Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
225+
{
226+
throw new NotImplementedException();
227+
}
228+
}
229+
230+
sealed class ZoomToTextRenderingModeConverter : IMultiValueConverter
231+
{
232+
public static readonly ZoomToTextRenderingModeConverter Instance = new ZoomToTextRenderingModeConverter();
233+
234+
public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
235+
{
236+
var zoom = value[0] != null ? (double) value[0] : 1.0;
237+
var antialiasing = value[1] != DependencyProperty.UnsetValue ? (bool) value[1] : true;
238+
var hinting = value[2] != DependencyProperty.UnsetValue ? (bool) value[2] : true;
239+
240+
if (antialiasing)
241+
{
242+
if (hinting)
243+
{
244+
if (zoom == 1.0)
245+
{
246+
return TextRenderingMode.ClearType;
247+
}
248+
else
249+
{
250+
return TextRenderingMode.Grayscale;
251+
}
252+
}
253+
else
254+
{
255+
return TextRenderingMode.Grayscale;
256+
}
257+
}
258+
else
259+
{
260+
return TextRenderingMode.Aliased;
261+
}
262+
}
263+
264+
public object[] ConvertBack(object value, Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
265+
{
266+
throw new NotImplementedException();
267+
}
268+
}
269+
270+
sealed class ZoomToTextHintingModeConverter : IMultiValueConverter
271+
{
272+
public static readonly ZoomToTextHintingModeConverter Instance = new ZoomToTextHintingModeConverter();
273+
274+
public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
275+
{
276+
var zoom = value[0] != null ? (double) value[0] : 1.0;
277+
var antialiasing = value[1] != DependencyProperty.UnsetValue ? (bool) value[1] : true;
278+
var hinting = value[2] != DependencyProperty.UnsetValue ? (bool) value[2] : true;
279+
280+
if (antialiasing)
281+
{
282+
if (hinting)
283+
{
284+
if (zoom == 1.0)
285+
{
286+
return TextHintingMode.Fixed;
287+
}
288+
else
289+
{
290+
return TextHintingMode.Fixed;
291+
}
292+
}
293+
else
294+
{
295+
return TextHintingMode.Animated;
296+
}
297+
}
298+
else
299+
{
300+
return TextHintingMode.Fixed;
301+
}
302+
}
303+
304+
public object[] ConvertBack(object value, Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
305+
{
306+
throw new NotImplementedException();
307+
}
308+
}
189309
}

src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ZoomScrollViewer.xaml

+23
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@
2424
<ScrollContentPresenter.LayoutTransform>
2525
<ScaleTransform ScaleX="{Binding Path=CurrentZoom, RelativeSource={RelativeSource Mode=TemplatedParent}}" ScaleY="{Binding Path=CurrentZoom, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
2626
</ScrollContentPresenter.LayoutTransform>
27+
<TextOptions.TextFormattingMode>
28+
<MultiBinding Converter="{x:Static Controls:ZoomToTextFormattingModeConverter.Instance}">
29+
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="CurrentZoom" />
30+
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="Content.Options.EnableTextAntialiasing" />
31+
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="Content.Options.EnableTextHinting" />
32+
</MultiBinding>
33+
</TextOptions.TextFormattingMode>
34+
<TextOptions.TextRenderingMode>
35+
<MultiBinding Converter="{x:Static Controls:ZoomToTextRenderingModeConverter.Instance}">
36+
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="CurrentZoom" />
37+
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="Content.Options.EnableTextAntialiasing" />
38+
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="Content.Options.EnableTextHinting" />
39+
<Binding RelativeSource="{RelativeSource Mode=Self}" />
40+
</MultiBinding>
41+
</TextOptions.TextRenderingMode>
42+
<TextOptions.TextHintingMode>
43+
<MultiBinding Converter="{x:Static Controls:ZoomToTextHintingModeConverter.Instance}">
44+
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="CurrentZoom" />
45+
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="Content.Options.EnableTextAntialiasing" />
46+
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="Content.Options.EnableTextHinting" />
47+
<Binding RelativeSource="{RelativeSource Mode=Self}" />
48+
</MultiBinding>
49+
</TextOptions.TextHintingMode>
2750
</ScrollContentPresenter>
2851
<ScrollBar Name="PART_VerticalScrollBar" Grid.Column="2" Grid.Row="0" Minimum="0" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Value="{TemplateBinding VerticalOffset}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" />
2952
<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}" />

0 commit comments

Comments
 (0)