mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
fix: dsl max width image (#1217)
* fix: dsl max width image * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
c3df1dc729
commit
64529805ff
|
@ -444,9 +444,8 @@ string ArticleMaker::makeEmptyPageHtml() const
|
|||
|
||||
sptr< Dictionary::DataRequest > ArticleMaker::makePicturePage( string const & url ) const
|
||||
{
|
||||
string const result = makeHtmlHeader( tr( "(picture)" ), QString(), true )
|
||||
+ R"lit(<a href="javascript: if(history.length>2) history.go(-1)">)lit" + R"(<img src=")" + url + R"(" /></a>)"
|
||||
+ "</body></html>";
|
||||
string const result =
|
||||
makeHtmlHeader( tr( "(picture)" ), QString(), true ) + R"(<img src=")" + url + R"(" />)" + "</body></html>";
|
||||
|
||||
sptr< Dictionary::DataRequestInstant > r = std::make_shared< Dictionary::DataRequestInstant >( true );
|
||||
|
||||
|
|
|
@ -840,61 +840,12 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
|
|||
url.setHost( QString::fromUtf8( getId().c_str() ) );
|
||||
url.setPath( Utils::Url::ensureLeadingSlash( QString::fromUtf8( filename.c_str() ) ) );
|
||||
|
||||
vector< char > imgdata;
|
||||
bool resize = false;
|
||||
string maxWidthStyle = " style=\"max-width:100%;\" ";
|
||||
|
||||
try {
|
||||
File::loadFromFile( n, imgdata );
|
||||
}
|
||||
catch ( File::exCantOpen & ) {
|
||||
try {
|
||||
n = resourceDir2 + filename;
|
||||
File::loadFromFile( n, imgdata );
|
||||
}
|
||||
catch ( File::exCantOpen & ) {
|
||||
try {
|
||||
n = getContainingFolder().toStdString() + Utils::Fs::separator() + filename;
|
||||
File::loadFromFile( n, imgdata );
|
||||
}
|
||||
catch ( File::exCantOpen & ) {
|
||||
// Try reading from zip file
|
||||
if ( resourceZip.isOpen() ) {
|
||||
QMutexLocker _( &resourceZipMutex );
|
||||
resourceZip.loadFile( Utf8::decode( filename ), imgdata );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( ... ) {
|
||||
}
|
||||
|
||||
if ( !imgdata.empty() ) {
|
||||
if ( Filetype::isNameOfSvg( filename ) ) {
|
||||
// We don't need to render svg file now
|
||||
|
||||
QSvgRenderer svg;
|
||||
svg.load( QByteArray::fromRawData( imgdata.data(), imgdata.size() ) );
|
||||
if ( svg.isValid() ) {
|
||||
QSize imgsize = svg.defaultSize();
|
||||
resize = maxPictureWidth > 0 && imgsize.width() > maxPictureWidth;
|
||||
}
|
||||
}
|
||||
else {
|
||||
QImage img = QImage::fromData( (unsigned char *)&imgdata.front(), imgdata.size() );
|
||||
|
||||
resize = maxPictureWidth > 0 && img.width() > maxPictureWidth;
|
||||
}
|
||||
}
|
||||
|
||||
if ( resize ) {
|
||||
string link( url.toEncoded().data() );
|
||||
link.replace( 0, 4, "gdpicture" );
|
||||
result += string( "<a href=\"" ) + link + "\">" + "<img src=\"" + url.toEncoded().data() + "\" alt=\""
|
||||
+ Html::escape( filename ) + "\"" + "width=\"" + QString::number( maxPictureWidth ).toStdString() + "\"/>"
|
||||
+ "</a>";
|
||||
}
|
||||
else
|
||||
result += string( "<img src=\"" ) + url.toEncoded().data() + "\" alt=\"" + Html::escape( filename ) + "\"/>";
|
||||
string link( url.toEncoded().data() );
|
||||
link.replace( 0, 4, "gdpicture" );
|
||||
result += string( "<a href=\"" ) + link + "\">" + "<img src=\"" + url.toEncoded().data() + "\" " + maxWidthStyle
|
||||
+ " alt=\"" + Html::escape( filename ) + "\"/>" + "</a>";
|
||||
}
|
||||
else if ( Filetype::isNameOfVideo( filename ) ) {
|
||||
QUrl url;
|
||||
|
|
|
@ -182,14 +182,15 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
GlobalBroadcaster::instance()->setPreference( &cfg.preferences );
|
||||
|
||||
localSchemeHandler = new LocalSchemeHandler( articleNetMgr, this );
|
||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "gdlookup", localSchemeHandler );
|
||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "bword", localSchemeHandler );
|
||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "entry", localSchemeHandler );
|
||||
QStringList htmlScheme = { "gdlookup", "bword", "entry", "gdpicture" };
|
||||
for ( const auto & localScheme : htmlScheme ) {
|
||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( localScheme.toLatin1(), localSchemeHandler );
|
||||
}
|
||||
|
||||
iframeSchemeHandler = new IframeSchemeHandler( this );
|
||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "ifr", iframeSchemeHandler );
|
||||
|
||||
QStringList localSchemes = { "gdau", "gico", "qrcx", "bres", "gdprg", "gdvideo", "gdpicture", "gdtts" };
|
||||
QStringList localSchemes = { "gdau", "gico", "qrcx", "bres", "gdprg", "gdvideo", "gdtts" };
|
||||
resourceSchemeHandler = new ResourceSchemeHandler( articleNetMgr, this );
|
||||
for ( const auto & localScheme : localSchemes ) {
|
||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( localScheme.toLatin1(), resourceSchemeHandler );
|
||||
|
|
Loading…
Reference in a new issue