如何修复/解决QtWebKit错误的字体回退行为? [英] How to fix/work around QtWebKit's incorrect font fallback behavior?

查看:32
本文介绍了如何修复/解决QtWebKit错误的字体回退行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,其中一些页面包含用户生成的内容.我使用phantomjs(基于QtWebKit)拍摄页面的屏幕截图,因此它们必须在QtWebKit中完美呈现.

I have a website in which some pages have user-generated content. I use phantomjs (based on QtWebKit) to take screenshots of the pages, so they must render perfectly in QtWebKit.

当内容不是英语时,问题就开始了.然后,流行的浏览器(例如Chrome和Firefox)会退回到CSS字体家族中的下一个字体,直到默认字体为止.但是,在我的测试中,QtWebKit似乎表现出不同的行为:它错误地选择了无法呈现内容的字体.

The problem starts when the content is not in English. Then, popular browsers (such as Chrome and Firefox) fall back to the next font in the CSS font-family, up to the default font. However, in my tests, QtWebKit seems to exhibit different behavior: it incorrectly picks a font that's unable to render the content.

请考虑以下示例文件"fonts.html":

Consider this example file, "fonts.html":

calibri, arial:
<div style="font-family: calibri, arial; font-size: 36px;">
ฝ่ายอีเว้นท์พร้อมแล้วกับงานปาร์ตี้ที่สนุกที่สุดในกทม
</div>

calibri:
<div style="font-family: calibri; font-size: 36px;">
ฝ่ายอีเว้นท์พร้อมแล้วกับงานปาร์ตี้ที่สนุกที่สุดในกทม
</div>

arial:
<div style="font-family: arial; font-size: 36px;">
ฝ่ายอีเว้นท์พร้อมแล้วกับงานปาร์ตี้ที่สนุกที่สุดในกทม
</div>

default:
<div style="font-size: 36px;">
ฝ่ายอีเว้นท์พร้อมแล้วกับงานปาร์ตี้ที่สนุกที่สุดในกทม
</div>

这是它在Chrome和Arora(基于QtWebKit的浏览器,与我的phantomjs脚本具有相同结果)中呈现的方式:

Here's how it renders in Chrome and in Arora (a QtWebKit-based browser, that gives identical results to my phantomjs script):

我想要的是将文本用Calibri呈现,如果不适合某些字符,请退回Arial.

What I'd like to have is for the text to be rendered in Calibri and, if unsuitable for some characters, fall back to Arial.

我将接受一个解决方案,该解决方案告诉我如何配置QtWebKit以允许此操作(我在网络上找不到任何内容),或者如何将HTML/CSS更改为支持QtWebKit".

I'll accept either a solution that tells me how to configure QtWebKit to allow this (I couldn't find anything on the web), or how to change my HTML/CSS to "support QtWebKit".

推荐答案

如果问题是所选字体不包含指定字符,我建议您将字体嵌入到您的网站中.这样一来,您可以确保每个平台都能呈现您的内容.

If the problem is that the chosen font doesn't contain the specified characters, I would recommend that you embedd the font into you website. With that you can ensure that every platform is able to render your content.

您说Chrome没有您所描述的错误行为.因此,原因必须出在旧的WebKit实现中.您可能会尝试使用WebKit 2.0(例如Google Chrome)更新到Qt 5.Qt 4.x使用旧的WebKit 1.x版本.

You say that Chrome doens't have the behaviour you described as incorrectly. So the cause must be in your old WebKit implementation. You may try to update to Qt 5 wich uses WebKit 2.0, like Google Chrome. Qt 4.x uses the old WebKit 1.x versions.

固定WebKit代码是 非常 的一个坏主意.该代码库约为200万个LOC,您需要64位工具链来编译QtWebKit模块.如果不严格按照说明进行操作,很可能会出现编译器错误.由于GIF图像渲染器中的错误,我自己需要调试WebKit代码.这是地球上的真实地狱;)

Bugfixing the WebKit code is a very bad idea. The codebase is around 2 million LOC and you need a 64bit toolchain to compile the QtWebKit module. It is also very likely to get compiler errors if you do not follow the instructions exactly. I had my self the need to debug the WebKit code because of a bug in the GIF image renderer. This is the real hell on earth ;)

这篇关于如何修复/解决QtWebKit错误的字体回退行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆