23125

Strange characters appear when using WPF webbrowser, and HTML with italic tag and arabic text

<h3>Question</h3>

I cannot figure this one but I have made a simple demo below. When this page is viewed in IE or Edge it renders properly. I have tried different encodings like utf-16, Windows-1252 but did not work. Looks like an issue with WebBrowser control to me. Can someone figure this out ?

ArabicPage.html

<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title></title> </head> <body>

<i>اتفاقية</i>

اتفاقية

</body> </html>

LayoutTest.xaml

<Page x:Class="WpfApp1.LayoutTest" 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" xmlns:local="clr-namespace:WpfApp1" mc:Ignorable="d" Background="Yellow" d:DesignHeight="450" d:DesignWidth="800" Loaded="Page_Loaded" Title="LayoutTest"> <WebBrowser x:Name="MyWebBrowser" Margin="20,5,0,5"/> </Page>

LayoutTest.xaml.cs

using System; using System.Text; using System.Windows; using System.IO; using System.Windows.Controls; namespace WpfApp1 { public partial class LayoutTest : Page { public LayoutTest() { InitializeComponent(); } private void Page_Loaded(object sender, RoutedEventArgs e) { string dirPath = AppDomain.CurrentDomain.BaseDi‌rectory; string fileName = "ArabicPage.html"; string filename = Path.GetFullPath(Path.Combine(dirPath, fileName)); string content = File.ReadAllText(fileName, Encoding.UTF8); MyWebBrowser.NavigateToString(content); } } }

Without italic tag it renders properly:

Render in Edge browser:

Update:

I have tested this with UWP webview and it works properly there.


<h3>Answer1:</h3>

You can avoid it by using a font that properly supports Arabic characters, as an example Tahoma:

<html lang="ar" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title></title> </head> <body style = "font-family:Tahoma,serif">

<i style = "font-size:26px;">اتفاقية</i>

<p style = "font-size:26px;">اتفاقية

</body> </html>

By default the font in windows 10 is Segoe UI. It seems that it is a Windows 10 issue more details from microsoft here.

EDIT:

Reply to comment

In fact you can see at windows 10 settings/fonts page (filter by Arabic), that Segoe UI font has a separate italic face font from the Regular face, on the opposite Tahoma italic is included in the regular face. Although when I tried an Arabic word sample in this settings with Segoe UI as a selected font it was surprisingly properly rendering characters with all the font styles available.

来源:https://stackoverflow.com/questions/61678871/strange-characters-appear-when-using-wpf-webbrowser-and-html-with-italic-tag-an

Recommend

  • How to remove all element from array except the first one in javascript
  • SwiftUI Hide TabView bar inside NavigationLink views
  • IntelliJ apply inspection fix throughout entire file
  • WPF menu tab navigation
  • When using the ABC module, are keyword arguments a good practice?
  • Flat File source Error Output connection in SSIS
  • Enable CORS in Nodejs with expressjs4
  • Spring Mockito @injectmocks not working
  • TortoiseGit revert failed - unable to revert local changes
  • Anything new for WinForms in .NET 4.0
  • Is there a way to press a button without touching it on tkinter / python?
  • Assign array to variable
  • ets:foldl vs deleted elements
  • How to EXCLUDE MasterPage items when bulk exporting all text Frames
  • how to print a web page [duplicate]
  • pip installation of gmpy2
  • Inject Javascript code into a web page
  • Updating price of in app purchase
  • Is there a generic TableModel we can use in JTables?
  • std::future returned from std::async hangs while going out of scope
  • What is the behavior of document.createElement when passed as an argument?
  • MySQL Query Select where id does not exist in the JOIN table
  • C# mvc3 redirect sitemap.xml to controller action
  • Encode string to Base64 in Inno Setup (Unicode Version of Inno Setup)
  • MySql tables, error #1064 & error #1068 Multiple primary key defined [closed]
  • Unknown type name with typedef struct in C
  • UIImage to UIColor array of pixel colors
  • Detect when MathJax has finished loading in UIWebView
  • Sorting Custom Listview Items Using Spinner Android
  • Nested AJAX Calls using .done
  • Threads and Concurrent Modification Exception working with a list
  • can you use embedded ruby in custom javascript files in rails?
  • Error processing job: Project has not enabled BigQuery
  • $this->a->b->c->d calling methods from a superclass in php
  • How to select multiple items from a List view - JavaFX 8
  • How to join two tables from different databases
  • concise way of flattening multiindex columns
  • Excel VBA : conditional formatting of sheet1 cells from sheet2 values in excel 2007
  • Sign a Pdf using custom digital signature in Java
  • How to use FirstOrDefault inside Include