Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Override custom fonts, since some of them crash QtWebkit on OS X

  • Loading branch information...
commit 82ae0c298f11098e3393806a595d1ffa8615c4fc 1 parent d3b9b30
@jferris jferris authored
Showing with 38 additions and 0 deletions.
  1. +30 −0 spec/driver_spec.rb
  2. +7 −0 src/WebPage.cpp
  3. +1 −0  src/WebPage.h
View
30 spec/driver_spec.rb
@@ -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){
View
7 src/WebPage.cpp
@@ -6,6 +6,7 @@
WebPage::WebPage(QObject *parent) : QWebPage(parent) {
loadJavascript();
+ setUserStylesheet();
m_loading = false;
@@ -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;
View
1  src/WebPage.h
@@ -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.
Something went wrong with that request. Please try again.