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 <QByteArray>
#include <QBuffer> #include <QBuffer>
// For SVG handling
#include <QtSvg/QSvgRenderer>
namespace Dsl { namespace Dsl {
using namespace Details; using namespace Details;
@ -821,10 +824,26 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
if( !imgdata.empty() ) if( !imgdata.empty() )
{ {
QImage img = QImage::fromData( (unsigned char *) &imgdata.front(), if( Filetype::isNameOfSvg( filename ) )
imgdata.size() ); {
resize = maxPictureWidth > 0 // We don't need to render svg file now
&& img.width() > maxPictureWidth;
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 ) if( resize )

View file

@ -102,4 +102,12 @@ bool isNameOfCSS( string const & name )
endsWith( s, ".css" ); 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 & ); bool isNameOfTiff( string const & );
/// Returns true if the name resembles the one of a .css file /// Returns true if the name resembles the one of a .css file
bool isNameOfCSS( string const & ); 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 += webkit
QT += xml QT += xml
QT += network QT += network
QT += svg
CONFIG += exceptions \ CONFIG += exceptions \
rtti \ rtti \
stl stl