Strange font rendering problem.
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:
And here is my resource file:
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 "→".
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:
Code: Select all
<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>
Code: Select all
<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>
......
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Strange font rendering problem.
Try setting the FontFamily also for UserControl style in your resources and let me know if that fixes your problems.
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.
Code: Select all
<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>
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.
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.
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.
Just noticed this post. Might be similar issue to what I'm seeing with fonts in beta 10:
Code: Select all
http://www.noesisengine.com/forums/viewtopic.php?f=3&t=1170&p=7265#p7265
Re: Strange font rendering problem.
Please try with the new b12. Thanks!
Re: Strange font rendering problem.
Hi, I have tested b12 version. The problem is still here.
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Strange font rendering problem.
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:
- Set the FontFamily directly in the root of your xaml. Remove other FontFamily setters you have in other styles:
FontFamily property will be inherited down all your UI elements and correctly applied.
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:
Code: Select all
<Style TargetType="{x:Type UserControl}">
<Setter Property="FontFamily" Value="{StaticResource DefaultFontFamily}" />
</Style>
Code: Select all
<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>
Re: Strange font rendering problem.
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:
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:
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.
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:
Code: Select all
<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">
It I set the style in my global resource file as:
Code: Select all
<Style TargetType="{x:Type Menus.Pages.TaskPage}">
<Setter Property="FontFamily" Value="{StaticResource DefaultFontFamily}" />
</Style>
I guess in standard XAML, it should work. If so, I hope Noesis would support this feature.
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Strange font rendering problem.
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.I guess in standard XAML, it should work. If so, I hope Noesis would support this feature.
Who is online
Users browsing this forum: Google [Bot] and 92 guests