Dsl: Handle SVG images

This commit is contained in:
Abs62 2013-05-25 16:07:49 +04:00
parent 525a539b7e
commit 7669d4f788
4 changed files with 34 additions and 4 deletions

27
dsl.cc
View file

@ -45,6 +45,9 @@
#include <QByteArray>
#include <QBuffer>
// For SVG handling
#include <QtSvg/QSvgRenderer>
namespace Dsl {
using namespace Details;
@ -821,10 +824,26 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
if( !imgdata.empty() )
{
QImage img = QImage::fromData( (unsigned char *) &imgdata.front(),
imgdata.size() );
resize = maxPictureWidth > 0
&& img.width() > maxPictureWidth;
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 )

View file

@ -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" );
}
}

View file

@ -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 );
}

View file

@ -22,6 +22,7 @@ INCLUDEPATH += .
QT += webkit
QT += xml
QT += network
QT += svg
CONFIG += exceptions \
rtti \
stl