From 0a59dd6e5b11f0cb4907d69a02326b7c2a5f5156 Mon Sep 17 00:00:00 2001 From: Abs62 Date: Wed, 2 Mar 2016 17:39:51 +0300 Subject: [PATCH] Stardict: Handle local url's in loaded .css --- stardict.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/stardict.cc b/stardict.cc index 96be6265..6966d3bb 100644 --- a/stardict.cc +++ b/stardict.cc @@ -1507,6 +1507,32 @@ void StardictResourceRequest::run() Mutex::Lock _( dataMutex ); QString css = QString::fromUtf8( data.data(), data.size() ); + + // Correct some url's + + QRegExp links( "url\\(\\s*(['\"])([^'\"]*)(['\"])\\s*\\)"); + QString id = QString::fromUtf8( dict.getId().c_str() ); + int pos = 0; + for( ; ; ) + { + pos = links.indexIn( css, pos ); + if( pos < 0 ) + break; + QString url = links.cap( 2 ); + + if( url.indexOf( "/" ) >= 0 ) + { + // External link + pos += links.cap().size(); + continue; + } + + QString newUrl = QString( "url(" ) + links.cap( 1 ) + "bres://" + + id + "/" + url + links.cap( 3 ) + ")"; + css.replace( pos, links.cap().size(), newUrl ); + pos += newUrl.size(); + } + dict.isolateCSS( css ); QByteArray bytes = css.toUtf8(); data.resize( bytes.size() );