2
votes

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:
difference win7/8

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
It probably has something to do with the Windows system theme, as you'll notice other elements also look different between the two versions of Windows, such as window style. - Rachel
A couple things to try: 1. turn off font smoothing (needs to be done at the OS level; apparently can't be done from WPF) 2. See if the difference is still consistent when you play around with ScaleTransform on the TextBlock. - nmclean

1 Answers

1
votes

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.