~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to filters/kformula/svg/svgexport.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
 
40
40
typedef KGenericFactory<SvgExport> SvgExportFactory;
41
 
K_EXPORT_COMPONENT_FACTORY( libkfosvgexport, SvgExportFactory( "svgexport" ) )
 
41
K_EXPORT_COMPONENT_FACTORY(libkfosvgexport, SvgExportFactory("svgexport"))
42
42
 
43
43
SvgExport::SvgExport(QObject* parent, const QStringList&)
44
 
    : KoFilter(parent)
 
44
        : KoFilter(parent)
45
45
{
46
46
}
47
47
 
54
54
SvgExport::convert(const QByteArray& from, const QByteArray& to)
55
55
{
56
56
    // Check for proper conversion.
57
 
    if ( from != "application/x-kformula" || to != "image/svg+xml" )
 
57
    if (from != "application/x-kformula" || to != "image/svg+xml")
58
58
        return KoFilter::NotImplemented;
59
59
 
60
60
    // Read the contents of the KFormula file
61
 
    KoStoreDevice* storeIn = m_chain->storageFile( "root", KoStore::Read );
62
 
    if ( !storeIn ) {
63
 
        KMessageBox::error( 0, i18n("Failed to read data." ),
64
 
                            i18n( "SVG Export Error" ) );
65
 
        return KoFilter::FileNotFound;
 
61
    KoStoreDevice* storeIn = m_chain->storageFile("root", KoStore::Read);
 
62
    if (!storeIn) {
 
63
        KMessageBox::error(0, i18n("Failed to read data."),
 
64
                           i18n("SVG Export Error"));
 
65
        return KoFilter::FileNotFound;
66
66
    }
67
67
 
68
68
    // Get the XML tree.
69
69
    QDomDocument  domIn;
70
 
    domIn.setContent( storeIn );
 
70
    domIn.setContent(storeIn);
71
71
    QDomElement   docNode = domIn.documentElement();
72
72
 
73
73
    // Read the document from the XML tree.
74
 
    KFormula::DocumentWrapper* wrapper = new KFormula::DocumentWrapper( KGlobal::config(), 0 );
 
74
    KFormula::DocumentWrapper* wrapper = new KFormula::DocumentWrapper(KGlobal::config(), 0);
75
75
    KFormula::Document* kformulaDoc = new KFormula::Document;
76
 
    wrapper->document( kformulaDoc );
 
76
    wrapper->document(kformulaDoc);
77
77
    KFormula::Container* formula = kformulaDoc->createFormula();
78
78
 
79
 
    if ( !kformulaDoc->loadXML( domIn ) ) {
80
 
        KMessageBox::error( 0, i18n( "Malformed XML data." ),
81
 
                            i18n( "SVG Export Error" ) );
 
79
    if (!kformulaDoc->loadXML(domIn)) {
 
80
        KMessageBox::error(0, i18n("Malformed XML data."),
 
81
                           i18n("SVG Export Error"));
82
82
        return KoFilter::WrongFormat;
83
83
    }
84
84
 
86
86
    Q3Picture  picture;
87
87
    QPainter  painter(&picture);
88
88
    QRect     rect(QPoint(0, 0), QPoint(500, 400));
89
 
    formula->draw( painter, rect, false );
 
89
    formula->draw(painter, rect, false);
90
90
    painter.end();
91
91
 
92
92
    // Save the image.
93
 
    if ( !picture.save( m_chain->outputFile(), "SVG" ) ) {
94
 
        KMessageBox::error( 0, i18n( "Failed to write file." ),
95
 
                            i18n( "SVG Export Error" ) );
 
93
    if (!picture.save(m_chain->outputFile(), "SVG")) {
 
94
        KMessageBox::error(0, i18n("Failed to write file."),
 
95
                           i18n("SVG Export Error"));
96
96
    }
97
97
 
98
98
    delete formula;