Page 1 of 1

Strange font rendering problem.

Posted: 12 Dec 2017, 02:38
by weilitao
Hi,

Recently I have updated Noesis from 2.0.2f2 to 2.1.0b10. There are some problems when I try to display chinese characters. When I set FontFamily from a global resource xaml. Not all part of my page xaml can display chinese characters correctly. for example, this is my sample page xaml file:
<UserControl x:Class="Menus.Pages.DeckPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d"
        d:DesignHeight="720" d:DesignWidth="1280">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources/PageResources.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <ItemsPanelTemplate x:Key="StoriesPanelTemplate">
                <WrapPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
            <DataTemplate x:Key="StoriesTemplate">
                <Border Width="200" Height="350" Margin="10" BorderBrush="Black" BorderThickness="2"
                        CornerRadius="5">
                    <Grid>
                        <TextBlock x:Name="textblock2" Text="中文" FontSize="50" TextAlignment="Center"
                                Margin="0,50,0,0" />
                        <TextBlock Text="{Binding Name}" FontSize="18" TextAlignment="Center"
                                Margin="0,100,0,0" />
                    </Grid>
                </Border>
            </DataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>
    <StackPanel Margin="0,20,0,0">
        <ItemsControl ItemsSource="{Binding Stories}"
                ItemsPanel="{StaticResource StoriesPanelTemplate}"
                ItemTemplate="{StaticResource StoriesTemplate}" />
        <Button x:Name="button1" Content="[BACK]" Command="{Binding BackCommand}" FontSize="30" />
        <Button x:Name="button2" Content="按钮测试1" FontSize="30" />
        <Button x:Name="button3" Content="按钮测试2" FontSize="30" FontFamily="{StaticResource DefaultFontFamily}"/>
		<TextBlock x:Name="textblock1" Text="中文测试" FontSize="30" />
    </StackPanel>
</UserControl>
And here is my resource file:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	 xmlns:System="clr-namespace:System;assembly=mscorlib"
	 xmlns:Converters="clr-namespace:Menus.Converters">
	<!-- DEFAULT FONTS -->
	<FontFamily x:Key="DefaultFontFamily">../Fonts/#Noto Sans CJK SC</FontFamily>
	<Style TargetType="{x:Type TextElement}">
		<Setter Property="FontFamily" Value="{StaticResource DefaultFontFamily}" />
	</Style>
	<Style TargetType="{x:Type TextBlock}">
		<Setter Property="FontFamily" Value="{StaticResource DefaultFontFamily}" />
	</Style>
	<Style TargetType="{x:Type TextBox}">
		<Setter Property="FontFamily" Value="{StaticResource DefaultFontFamily}" />
	</Style>
......
As the attached image shows, some characters can display correctly (textblock1), some can't (textblock2). All button cannot display correctly unless I set fontfamily embed. Also, please note the character "[" and "]" inside "button1" would been displayed like "→".

Re: Strange font rendering problem.

Posted: 12 Dec 2017, 18:28
by sfernandez
Try setting the FontFamily also for UserControl style in your resources and let me know if that fixes your problems.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     ...
    <Style TargetType="{x:Type UserControl}">
        <Setter Property="FontFamily" Value="{StaticResource DefaultFontFamily}" />
    </Style>
    ...
</ResourceDictionary>
In 2.0.2f2 and previous versions we had a bug related with text styles that made Noesis differ from WPF behavior.

To override FontFamily in your application you can set it only in the root of main xaml and the property should be inherited by all the texts and controls.

Re: Strange font rendering problem.

Posted: 13 Dec 2017, 04:07
by weilitao
Hi Sfernandez,
I have done as your said. No matter I set the FontFamily of UserControl in global resources or just inside the current wpf file, the chinese characters can not be displayed.

Re: Strange font rendering problem.

Posted: 14 Dec 2017, 06:03
by nokola
Just noticed this post. Might be similar issue to what I'm seeing with fonts in beta 10:
http://www.noesisengine.com/forums/viewtopic.php?f=3&t=1170&p=7265#p7265

Re: Strange font rendering problem.

Posted: 19 Dec 2017, 05:03
by jsantos
Please try with the new b12. Thanks!

Re: Strange font rendering problem.

Posted: 25 Dec 2017, 10:25
by weilitao
Hi, I have tested b12 version. The problem is still here.

Re: Strange font rendering problem.

Posted: 28 Dec 2017, 12:29
by sfernandez
I tested it in b12 and it works as I explained in my previous post.

You have 2 options:

- Set in your Resources file a Style for the type of your root element (a UserControl) where you set the global font. You can remove other FontFamily setters you have in other styles, they are not required unless you want a specific style to change your global font:
<Style TargetType="{x:Type UserControl}">
    <Setter Property="FontFamily" Value="{StaticResource DefaultFontFamily}" />
</Style>
- Set the FontFamily directly in the root of your xaml. Remove other FontFamily setters you have in other styles:
<UserControl x:Class="Menus.Pages.DeckPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d"
        d:DesignHeight="720" d:DesignWidth="1280"
        FontFamily="../Fonts/#Noto Sans CJK SC">
...
</UserControl>
FontFamily property will be inherited down all your UI elements and correctly applied.

Re: Strange font rendering problem.

Posted: 29 Dec 2017, 17:52
by weilitao
Hi sfernandez,

Thanks for your reply.
I have tested your 2 options. Option 2 works for me.
I wondered why option 1 not work in my project, as your said it should work. Then I have fingered out the key point.
In my xaml file, the header part is:
<UserControl x:Class="Menus.Pages.TaskPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
So it is not the class *UserControl*, but a descendent class named *Menus.Pages.TaskPage*.
It I set the style in my global resource file as:
    <Style TargetType="{x:Type Menus.Pages.TaskPage}">
        <Setter Property="FontFamily" Value="{StaticResource DefaultFontFamily}" />
    </Style>
It then works. But if I set to UserControl as you said, it doesn't work.

I guess in standard XAML, it should work. If so, I hope Noesis would support this feature.

Re: Strange font rendering problem.

Posted: 02 Jan 2018, 12:44
by sfernandez
I guess in standard XAML, it should work. If so, I hope Noesis would support this feature.
No, standard XAML behaves exactly like this: implicit styles are only applied for the exact type. So if your root class is Menus.Pages.TaskPage, then you need to specify that type in the style.