Bug Report T880621
Visible to All Users

Usability - There is no API to specify a preferable font for font substitution

created 5 years ago

Hello,

I have an issue with the RichEditControl. I use databinding to bind an html fragement. For all text that has no specific font I want to use the default font. I set this in a event handler using the DefaultCharacterProperties.FontName property of the document. But this does not work for Chinese characters. As soon as I have the (attached) FZShuTi font installed, this is always the default font, regardless of the DefaultCharacterProperties.FontName and DefaultCharacterProperties.FontNameEastAsia properties.

As seen in the screenshot and in the attached sample project the FZShuTi font is used instead of the SimSun font. The default non-Chinese font is applied correctly.

C#
RichEditControl.ContentChanged += RichEditControl_ContentChanged; private void RichEditControl_ContentChanged(object sender, EventArgs e) { var richtEditControl = (RichEditControl)sender; var doc = richtEditControl.Document; // First try // doc.DefaultCharacterProperties.FontName = "SimSun"; // doc.DefaultCharacterProperties.FontSize = 12; // Second try, which would be better doc.DefaultCharacterProperties.FontName = "Courier New"; doc.DefaultCharacterProperties.FontSize = 12; doc.DefaultCharacterProperties.FontNameEastAsia = "SimSun"; } HtmlText = @" <style> .cs95E872D0{text-align:left;text-indent:0pt;margin:0pt 0pt 0pt 0pt;} .cs29BB0978{color:#000000;background-color:transparent;font-weight:normal;font-style:normal;} .useDefault{color:#000000;background-color:transparent;font-weight:normal;font-style:normal;} .useSimSun{color:#000000;background-color:transparent;font-weight:normal;font-style:normal;font-family:SimSun} .useFZShuTi{color:#000000;background-color:transparent;font-weight:normal;font-style:normal;font-family:FZShuTi} .useJhengHei{color:#000000;background-color:transparent;font-weight:normal;font-style:normal;font-family:Microsoft JhengHei} </style> <body> <p class=""cs95E872D0""> <span class=""cs29BB0978"">Use default font (should be SimSun): </span> <span class=""useDefault"">途的酸催化剂</span> </p> <p class=""cs95E872D0""> <span class=""cs29BB0978"">SimSun: </span> <span class=""useSimSun"">途的酸催化剂</span> </p> <p class=""cs95E872D0""> <span class=""cs29BB0978"">FZShuTi: </span> <span class=""useFZShuTi"">途的酸催化剂</span> </p> <p class=""cs95E872D0""> <span class=""cs29BB0978"">Microsoft JhengHei: </span> <span class=""useJhengHei"">途的酸催化剂</span> </p> </body>";
XAML
<dxre:RichEditControl x:Name="RichEditControl" Content="{Binding Path=HtmlText, Mode=OneWay, Converter={StaticResource CustomHtmlConverter}}" ActiveViewType="Simple" />

Thanks for any help,
G.

Answers approved by DevExpress Support

created 4 years ago

We have addressed the issue described in this ticket and will include a fix in our next maintenance update. To apply this solution before official release, request a hotfix by clicking the appropriate version link.

Note: Hotfixes may be unavailable for betas/updates set for release within a week.

Additional information:

With this fix, we implemented RichEditControl.Options.Behavior.FontSubstitution.Ascii, Options.Behavior.FontSubstitution.HighAnsi, RichEditControl.Options.Behavior.FontSubstitution.ComplexScript, and RichEditControl.Options.Behavior.FontSubstitution.EastAsia properties to define a preferable font for substituting glyphs.

Set the RichEditControl.Options.Behavior.FontSubstitution.EastAsia property to "SimSun" to achieve the goal.

    created 5 years ago

    Hello,

    The RichEditControl imports Html text with the "Times New Roman, 12" font (default). If this font does not contain required glyphs, it is substituted with another font. This behavior is managed by the RichEditControl.BehaviorOptions.UseFontSubstitution property.

    Our algorithm uses GDI API to find a font for replacement. The RichEditControl and Microsoft Word use different algorithms for font substitution, so substituted fonts may differ.

    With the current RichEditControl design, a font for substitution is calculated dynamically, and there is no public API to specify a particular replacement font. I have informed our developers of your request. However, I cannot give you any promises regarding this functionality, as it is not included into our immediate development plans.

      Comments (2)
      GM GM
      Gerhard Meglitsch 5 years ago

        Thanks for the reply.

        But then I do not understand the properties FontName (which is working for "normal" fonts) and FontNameEastAsia (what is this for then?). So there is a way of changing the behavior, but it is not working in all cases.

        This is still confusing to me.

        G.

        DevExpress Support Team 5 years ago

          I will pass this thread to our developers. They will check if it is possible to redesign RichEditControl's font substitution mechanism to take into account the DefaultCharacterProperties.FontNameEastAsia property value.

          It may take some time to research this subject and find a solution, since we also need to find a way to avoid a breaking change for the existing customers. We will update this thread once we have any results.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.