~ubuntu-branches/ubuntu/oneiric/koffice/oneiric-updates

« back to all changes in this revision

Viewing changes to kformula/flake/FormulaDocument.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
 
 
3
   Copyright 2008 Johannes Simon <johannes.simon@gmail.com>
 
4
   Copyright 2010 Inge Wallin <inge@lysator.liu.se>
 
5
 
 
6
   This library is free software; you can redistribute it and/or
 
7
   modify it under the terms of the GNU Library General Public
 
8
   License as published by the Free Software Foundation; either
 
9
   version 2 of the License, or (at your option) any later version.
 
10
 
 
11
   This library is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
   Library General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU Library General Public License
 
17
   along with this library; see the file COPYING.LIB.  If not, write to
 
18
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
 * Boston, MA 02110-1301, USA.
 
20
*/
 
21
 
 
22
// Own
 
23
#include "FormulaDocument.h"
 
24
 
 
25
// Qt
 
26
#include <QWidget>
 
27
#include <QIODevice>
 
28
#include <QDebug>
 
29
#include <QPainter>
 
30
 
 
31
// KOffice
 
32
#include <KoDocument.h>
 
33
#include <KoXmlWriter.h>
 
34
#include <KoOdfReadStore.h>
 
35
#include <KoOdfWriteStore.h>
 
36
#include <KoOdfLoadingContext.h>
 
37
#include <KoShapeLoadingContext.h>
 
38
#include <KoShapeSavingContext.h>
 
39
#include <KoXmlNS.h>
 
40
#include <KoOdfStylesReader.h>
 
41
#include <KoGenStyles.h>
 
42
#include <KoEmbeddedDocumentSaver.h>
 
43
#include <KoView.h>
 
44
#include <KComponentData>
 
45
#include <KDebug>
 
46
 
 
47
// KFormula
 
48
#include "KoFormulaShape.h"
 
49
 
 
50
 
 
51
class FormulaDocument::Private
 
52
{
 
53
public:
 
54
    Private();
 
55
    ~Private();
 
56
 
 
57
    KoFormulaShape *parent;
 
58
};
 
59
 
 
60
FormulaDocument::Private::Private()
 
61
{
 
62
}
 
63
 
 
64
FormulaDocument::Private::~Private()
 
65
{
 
66
}
 
67
 
 
68
FormulaDocument::FormulaDocument( KoFormulaShape *parent )
 
69
    : KoDocument( 0, 0 )
 
70
    , d ( new Private )
 
71
{
 
72
    d->parent = parent;
 
73
    // Needed by KoDocument::nativeOasisMimeType().
 
74
    // KoEmbeddedDocumentSaver uses that method to
 
75
    // get the mimetype of the embedded document.
 
76
    setComponentData( KComponentData( "math" ) );
 
77
}
 
78
 
 
79
FormulaDocument::~FormulaDocument()
 
80
{
 
81
    delete d;
 
82
}
 
83
 
 
84
 
 
85
bool FormulaDocument::loadOdf( KoOdfReadStore &odfStore )
 
86
{
 
87
    KoXmlDocument doc = odfStore.contentDoc();
 
88
    KoXmlElement  bodyElement = doc.documentElement();
 
89
 
 
90
    kDebug(31000) << bodyElement.nodeName();
 
91
 
 
92
    if (bodyElement.nodeName() != "math:math") {
 
93
        kError(35001) << "No <math:math> element found.";
 
94
        return false;
 
95
    }
 
96
 
 
97
    // When the formula is stored in an embedded document, it seems to
 
98
    // always have a <math:semantics> element that surrounds the
 
99
    // actual formula.  I have to check with the MathML spec what this
 
100
    // actually means and if it is obligatory.  /iw
 
101
    KoXmlNode semanticsNode = bodyElement.namedItemNS( KoXmlNS::math, "semantics" );
 
102
    if ( !semanticsNode.isNull() ) {
 
103
        bodyElement = semanticsNode.toElement();
 
104
    }
 
105
 
 
106
    KoOdfLoadingContext   odfLoadingContext( odfStore.styles(), odfStore.store() );
 
107
    KoShapeLoadingContext context(odfLoadingContext, d->parent->resourceManager());
 
108
 
 
109
    return d->parent->loadOdfEmbedded( bodyElement, context );
 
110
}
 
111
 
 
112
bool FormulaDocument::loadXML( const KoXmlDocument &doc, KoStore *)
 
113
{
 
114
    Q_UNUSED( doc );
 
115
 
 
116
    // We don't support the old XML format any more.
 
117
    return false;
 
118
}
 
119
 
 
120
bool FormulaDocument::saveOdf( SavingContext &context )
 
121
{
 
122
    // FIXME: This code is copied from ChartDocument, so it needs to
 
123
    // be adapted to the needs of the KoFormulaShape.
 
124
 
 
125
    KoOdfWriteStore &odfStore = context.odfStore;
 
126
    KoStore *store = odfStore.store();
 
127
    KoXmlWriter *manifestWriter = odfStore.manifestWriter();
 
128
    KoXmlWriter *contentWriter  = odfStore.contentWriter();
 
129
    if ( !contentWriter )
 
130
        return false;
 
131
 
 
132
    KoGenStyles mainStyles;
 
133
    KoXmlWriter *bodyWriter = odfStore.bodyWriter();
 
134
    if ( !bodyWriter )
 
135
        return false;
 
136
 
 
137
    KoEmbeddedDocumentSaver& embeddedSaver = context.embeddedSaver;
 
138
 
 
139
    KoShapeSavingContext savingContext( *bodyWriter, mainStyles, embeddedSaver );
 
140
 
 
141
    bodyWriter->startElement( "office:body" );
 
142
    bodyWriter->startElement( "office:formula" );
 
143
 
 
144
    d->parent->saveOdf( savingContext );
 
145
 
 
146
    bodyWriter->endElement(); // office:formula
 
147
    bodyWriter->endElement(); // office:body
 
148
 
 
149
    mainStyles.saveOdfStyles( KoGenStyles::DocumentAutomaticStyles, contentWriter );
 
150
    odfStore.closeContentWriter();
 
151
 
 
152
    // Add manifest line for content.xml and styles.xml
 
153
    manifestWriter->addManifestEntry( url().path() + "/content.xml", "text/xml" );
 
154
    manifestWriter->addManifestEntry( url().path() + "/styles.xml", "text/xml" );
 
155
 
 
156
    // save the styles.xml
 
157
    if ( !mainStyles.saveOdfStylesDotXml( store, manifestWriter ) )
 
158
        return false;
 
159
 
 
160
    if ( !savingContext.saveDataCenter( store, manifestWriter ) ) {
 
161
        return false;
 
162
    }
 
163
 
 
164
    return true;
 
165
}
 
166
 
 
167
KoView *FormulaDocument::createViewInstance( QWidget *parent )
 
168
{
 
169
    Q_UNUSED( parent );
 
170
 
 
171
    return 0;
 
172
}
 
173
 
 
174
void FormulaDocument::paintContent( QPainter &painter, const QRect &rect )
 
175
{
 
176
    Q_UNUSED( painter );
 
177
    Q_UNUSED( rect );
 
178
}
 
179
 
 
180