weilitao
Topic Author
Posts: 22
Joined: 23 Feb 2016, 10:43

Strange font rendering problem.

12 Dec 2017, 02:38

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 "→".
Attachments
Jietu20171212-092126.jpg
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Strange font rendering problem.

12 Dec 2017, 18:28

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.
 
weilitao
Topic Author
Posts: 22
Joined: 23 Feb 2016, 10:43

Re: Strange font rendering problem.

13 Dec 2017, 04:07

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.
 
nokola
Posts: 188
Joined: 10 Mar 2015, 05:29

Re: Strange font rendering problem.

14 Dec 2017, 06:03

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
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: Strange font rendering problem.

19 Dec 2017, 05:03

Please try with the new b12. Thanks!
 
weilitao
Topic Author
Posts: 22
Joined: 23 Feb 2016, 10:43

Re: Strange font rendering problem.

25 Dec 2017, 10:25

Hi, I have tested b12 version. The problem is still here.
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Strange font rendering problem.

28 Dec 2017, 12:29

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.
 
weilitao
Topic Author
Posts: 22
Joined: 23 Feb 2016, 10:43

Re: Strange font rendering problem.

29 Dec 2017, 17:52

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.
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Strange font rendering problem.

02 Jan 2018, 12:44

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.

Who is online

Users browsing this forum: Google [Bot] and 92 guests