Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix/work around QtWebKit's incorrect font fallback behavior?

Tags:

css

qt

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.

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.

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>

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

Font fallback problem in Chrome vs QtWebKit

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.

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".

like image 523
Yoni Rozenshein Avatar asked Oct 23 '22 07:10

Yoni Rozenshein


1 Answers

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.

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.

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 ;)

like image 91
Alexander Nassian Avatar answered Nov 01 '22 09:11

Alexander Nassian