GlyphRun in WPF doesn't seem to display dot-matrix fonts

HoWe Yu 41 信誉分
2024-10-26T21:01:41.2266667+00:00

I placed two texts on the window, but the display effects are inconsistent. How can I make Glyphs achieve the same display effect as TextBlock?

Snipaste_2024-10-27_04-54-34

Windows Presentation Foundation
Windows Presentation Foundation
.NET Framework 的一部分,它提供统一的编程模型,用于在 Windows 上构建业务线桌面应用程序。
128 个问题
C#
C#
一种面向对象的类型安全的编程语言,它起源于 C 语言系列,包括对面向组件的编程的支持。
189 个问题
0 个注释 无注释
{count} 票

1 个答案

排序依据: 非常有帮助
  1. Hongrui Yu-MSFT 2,540 信誉分 Microsoft 供应商
    2024-10-29T05:47:46.5033333+00:00

    Hi,@HoWe Yu. Welcome to Microsoft Q&A. 

    If you want the text rendered by Glyphs and TextBlock to be consistent, you could refer to the following solution.

     

    You need to cancel the additional settings for TextBlock: you need to delete <Window>'s TextOptions.TextFormattingMode="Display".

    Related code

    <Window
    		...
            WindowStartupLocation="CenterScreen"      
            Background="#FFFFFF"
            TextOptions.TextRenderingMode="Aliased"
            Title="MainWindow" Height="720" Width="1280">
    
        <Grid x:Name="MainGrid">
            <Grid x:Name="PaperBox" Margin="0"></Grid>
    
            <Glyphs x:Name="MyGlyphs"  FontUri="C:\WINDOWS\Fonts\simsun.ttc" FontRenderingEmSize="13"  UnicodeString="Hello World!" Fill="Black" OriginX="100" OriginY="80" />
    
            <TextBlock x:Name="MyTextBlock" Text="Hello World!" FontFamily="NSimSun" FontSize="13" FontWeight="Normal" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="100"></TextBlock>
        </Grid>
    </Window>
    
    

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


你的答案

问题作者可以将答案标记为“接受的答案”,这有助于用户了解已解决作者问题的答案。