Skip to content

Commit

Permalink
Override custom fonts, since some of them crash QtWebkit on OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Aug 12, 2011
1 parent d3b9b30 commit 82ae0c2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spec/driver_spec.rb
Expand Up @@ -786,6 +786,36 @@ def make_the_server_go_away
end
end

context "custom font app" do
before(:all) do
@app = lambda do |env|
body = <<-HTML
<html>
<head>
<style type="text/css">
p { font-family: "Verdana"; }
</style>
</head>
<body>
<p id="text">Hello</p>
</body>
</html>
HTML
[200,
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
[body]]
end
end

it "ignores custom fonts" do
font_family = subject.evaluate_script(<<-SCRIPT)
var element = document.getElementById("text");
element.ownerDocument.defaultView.getComputedStyle(element, null).getPropertyValue("font-family");
SCRIPT
font_family.should == "Arial"
end
end

context "with socket debugger" do
let(:socket_debugger_class){ Capybara::Driver::Webkit::SocketDebugger }
let(:browser_with_debugger){
Expand Down
7 changes: 7 additions & 0 deletions src/WebPage.cpp
Expand Up @@ -6,6 +6,7 @@

WebPage::WebPage(QObject *parent) : QWebPage(parent) {
loadJavascript();
setUserStylesheet();

m_loading = false;

Expand All @@ -30,6 +31,12 @@ void WebPage::loadJavascript() {
}
}

void WebPage::setUserStylesheet() {
QString data = QString("* { font-family: 'Arial' ! important; }").toUtf8().toBase64();
QUrl url = QUrl(QString("data:text/css;charset=utf-8;base64,") + data);
settings()->setUserStyleSheetUrl(url);
}

QString WebPage::userAgentForUrl(const QUrl &url ) const {
if (!m_userAgent.isEmpty()) {
return m_userAgent;
Expand Down
1 change: 1 addition & 0 deletions src/WebPage.h
Expand Up @@ -34,5 +34,6 @@ class WebPage : public QWebPage {
bool m_loading;
QString getLastAttachedFileName();
void loadJavascript();
void setUserStylesheet();
};

0 comments on commit 82ae0c2

Please sign in to comment.