mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Dsl: Handle SVG images
This commit is contained in:
parent
525a539b7e
commit
7669d4f788
19
dsl.cc
19
dsl.cc
|
@ -45,6 +45,9 @@
|
|||
#include <QByteArray>
|
||||
#include <QBuffer>
|
||||
|
||||
// For SVG handling
|
||||
#include <QtSvg/QSvgRenderer>
|
||||
|
||||
namespace Dsl {
|
||||
|
||||
using namespace Details;
|
||||
|
@ -820,12 +823,28 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
|
|||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
|
|
|
@ -102,4 +102,12 @@ bool isNameOfCSS( string const & name )
|
|||
endsWith( s, ".css" );
|
||||
}
|
||||
|
||||
bool isNameOfSvg( string const & name )
|
||||
{
|
||||
string s = simplifyString( name );
|
||||
|
||||
return
|
||||
endsWith( s, ".svg" );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ bool isNameOfPicture( string const & );
|
|||
bool isNameOfTiff( string const & );
|
||||
/// Returns true if the name resembles the one of a .css file
|
||||
bool isNameOfCSS( string const & );
|
||||
/// Returns true if the name resembles the one of a .svg file
|
||||
bool isNameOfSvg( string const & name );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ INCLUDEPATH += .
|
|||
QT += webkit
|
||||
QT += xml
|
||||
QT += network
|
||||
QT += svg
|
||||
CONFIG += exceptions \
|
||||
rtti \
|
||||
stl
|
||||
|
|
Loading…
Reference in a new issue