gpt4 book ai didi

html - Internet Explorer 字体渲染

转载 作者:太空宇宙 更新时间:2023-11-03 19:36:48 25 4
gpt4 key购买 nike

我有一个简单的 web page :

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title></title>
<style type="text/css">
body, p, span {
font-family: Verdana;
font-size: 9pt;
}
</style>
</head>
<body>
<p><span>Some sample text to show the font rendering</span></p>
</body>
</html>

网页文本在完整的 Internet Explorer 浏览器和托管 WebBrowser 控件的自定义 .NET 应用程序中呈现不同。众所周知,IE 和 WebBrowser 使用相同的 Trident 渲染引擎。这是使用 IE11、Windows 8.1 测试后的样子:

完整的 IE 浏览器(在 96 DPI、1376x768 的屏幕上,这个模糊的文本会伤害我的眼睛):

ie-font-rendering.png


完整的 IE 浏览器,放大:

ie-font-rendering-magnified.png


基于 WebBrowser 的应用(在 96 DPI、1376x768 屏幕上看起来不错):

weboc-font-rendering.png


基于 WebBrowser 的应用,放大:

weboc-font-rendering-magnified.png


显然,IE 使用灰度字体抗锯齿(对比 WebBrowser 控件使用的子像素抗锯齿)。

有没有办法让 IE 以与 WebBrowser 相同的视觉友好方式呈现文本,即使用相同的字体抗锯齿算法?也许是专有的 IE CSS 设置?

相反,如果我真的想要,如何为 WebBroser 控件启用灰度字体抗锯齿?

如果有人想玩 WebBrowser 应用程序,这里是源代码(在 C# 中,使用 WinForms):

using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WebBrowserApp
{
public partial class MainForm : Form
{
WebBrowser _webBrowser;

// set WebBrowser features, more info: http://stackoverflow.com/a/18333982/1768303
static void SetWebBrowserFeatures()
{
// don't change the registry if running in-proc inside Visual Studio
if (LicenseManager.UsageMode != LicenseUsageMode.Runtime)
return;

var appName = System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);

var featureControlRegKey = @"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\";

Registry.SetValue(featureControlRegKey + "FEATURE_BROWSER_EMULATION",
appName, GetBrowserEmulationMode(), RegistryValueKind.DWord);

// enable the features which are "On" for the full Internet Explorer browser

Registry.SetValue(featureControlRegKey + "FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION",
appName, 1, RegistryValueKind.DWord);

Registry.SetValue(featureControlRegKey + "FEATURE_AJAX_CONNECTIONEVENTS",
appName, 1, RegistryValueKind.DWord);

Registry.SetValue(featureControlRegKey + "FEATURE_GPU_RENDERING",
appName, 1, RegistryValueKind.DWord);

Registry.SetValue(featureControlRegKey + "FEATURE_WEBOC_DOCUMENT_ZOOM",
appName, 1, RegistryValueKind.DWord);

Registry.SetValue(featureControlRegKey + "FEATURE_NINPUT_LEGACYMODE",
appName, 0, RegistryValueKind.DWord);
}

static UInt32 GetBrowserEmulationMode()
{
int browserVersion = 7;
using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer",
RegistryKeyPermissionCheck.ReadSubTree,
System.Security.AccessControl.RegistryRights.QueryValues))
{
var version = ieKey.GetValue("svcVersion");
if (null == version)
{
version = ieKey.GetValue("Version");
if (null == version)
throw new ApplicationException("Microsoft Internet Explorer is required!");
}
int.TryParse(version.ToString().Split('.')[0], out browserVersion);
}

UInt32 mode = 11000; // Internet Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE11 Standards mode.

switch (browserVersion)
{
case 7:
mode = 7000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.
break;
case 8:
mode = 8000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.
break;
case 9:
mode = 9000; // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.
break;
case 10:
mode = 10000; // Internet Explorer 10.
break;
}

return mode;
}

// static constructor, runs first
static MainForm()
{
SetWebBrowserFeatures();
}

public MainForm()
{
InitializeComponent();

_webBrowser = new WebBrowser() { Dock = DockStyle.Fill };
this.Controls.Add(_webBrowser);

this.Size = new System.Drawing.Size(800, 600);
this.Load += MainForm_Load;
}

// start the task
async void MainForm_Load(object sender, EventArgs e)
{
try
{
dynamic document = await LoadWebPage("http://nozillium.com/temp/font-rendering.html",
CancellationToken.None);

MessageBox.Show(new { document.documentMode, document.compatMode }.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

// navigate and download
async Task<object> LoadWebPage(string url, CancellationToken token)
{
// navigate and await DocumentCompleted
var tcs = new TaskCompletionSource<bool>();
WebBrowserDocumentCompletedEventHandler handler = (s, arg) =>
tcs.TrySetResult(true);

using (token.Register(() => tcs.TrySetCanceled(), useSynchronizationContext: false))
{
this._webBrowser.DocumentCompleted += handler;
try
{
this._webBrowser.Navigate(url);
await tcs.Task; // wait for DocumentCompleted
}
finally
{
this._webBrowser.DocumentCompleted -= handler;
}
}

return this._webBrowser.Document.DomDocument;
}
}
}

最佳答案

尝试使用文本渲染:optimizeSpeed;

在你的CSS主体上

关于html - Internet Explorer 字体渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28655207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com