-->

WPF's TextBlock differences between Windows 7

2019-02-26 07:08发布

问题:

While investigating some unit tests which fail only on my machine, I noticed that TextBlock presents text differently on Windows 7 and Windows 8 machines. To inspect the issue, I created sample application containing just one TextBlock:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TextBlock Text="yo" FontSize="100" FontFamily="Verdana" />
    </Grid>
</Window>

You can see (or at least I hope so) that the text on Windows 7 is 1px longer - actually the kerning between the "y" and "o" is 1px thicker:

I inspected the Verdana.ttf font files on both machines with a font reader software, and the kerning between "y" and "o" listed there is one and the same: -18.
Also checked the versions of the .NET Framework, which are also identical: 4.5.50709.
...and I am still wondering what causes this difference?

回答1:

I'd rather think it is something to do with ClearType or Anti-Aliasing, Microsoft is constantly changing that code between every Windows release. Don't think there is anything you can do about that, just have to factor in those differences to your unit tests.