~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to filters/kword/libexport/KWEFBaseWorker.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// $Header: /home/kde/koffice/filters/kword/libexport/KWEFBaseWorker.cc,v 1.26 2003/08/16 12:22:48 mueller Exp $
 
2
 
 
3
/*
 
4
   This file is part of the KDE project
 
5
   Copyright 2001, 2002, 2003 Nicolas GOUTTE <goutte@kde.org>
 
6
 
 
7
   This library is free software; you can redistribute it and/or
 
8
   modify it under the terms of the GNU Library General Public
 
9
   License as published by the Free Software Foundation; either
 
10
   version 2 of the License, or (at your option) any later version.
 
11
 
 
12
   This library is distributed in the hope that it will be useful,
 
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
   Library General Public License for more details.
 
16
 
 
17
   You should have received a copy of the GNU Library General Public License
 
18
   along with this library; see the file COPYING.LIB.  If not, write to
 
19
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
   Boston, MA 02111-1307, USA.
 
21
*/
 
22
 
 
23
#include <qbuffer.h>
 
24
#include <qimage.h>
 
25
 
 
26
#include <kdebug.h>
 
27
 
 
28
#include <koPicture.h>
 
29
 
 
30
#include "KWEFStructures.h"
 
31
#include "KWEFBaseWorker.h"
 
32
#include "KWEFKWordLeader.h"
 
33
 
 
34
void KWEFBaseWorker::registerKWordLeader(KWEFKWordLeader* leader)
 
35
{
 
36
    m_kwordLeader=leader;
 
37
}
 
38
 
 
39
//
 
40
// At first, define all methods that do something real!
 
41
//
 
42
 
 
43
bool KWEFBaseWorker::doAbortFile(void)
 
44
{
 
45
    // Mostly, aborting is the same than closing the file!
 
46
    return doCloseFile();
 
47
}
 
48
 
 
49
bool KWEFBaseWorker::doFullDocument (const QValueList<ParaData>& paraList)
 
50
{
 
51
    if (!doOpenTextFrameSet())
 
52
        return false;
 
53
    if (!doFullAllParagraphs(paraList))
 
54
        return false;
 
55
    if (!doCloseTextFrameSet())
 
56
        return false;
 
57
 
 
58
    return true;
 
59
}
 
60
 
 
61
bool KWEFBaseWorker::doFullAllParagraphs (const QValueList<ParaData>& paraList)
 
62
{
 
63
    QValueList<ParaData>::ConstIterator it;
 
64
    for (it=paraList.begin();it!=paraList.end();it++)
 
65
    {
 
66
        if (!doFullParagraph((*it).text,(*it).layout,(*it).formattingList))
 
67
            return false;
 
68
    }
 
69
    return true;
 
70
}
 
71
 
 
72
bool KWEFBaseWorker::loadSubFile(const QString& fileName, QByteArray& array) const
 
73
// return value:
 
74
//   true if the file is not empty
 
75
//   false if the file is empty or if an error occurred
 
76
{
 
77
    bool flag=false;
 
78
    if (m_kwordLeader)
 
79
    {
 
80
        flag=m_kwordLeader->loadSubFile(fileName,array);
 
81
    }
 
82
    else
 
83
    {
 
84
        kdWarning(30508) << "Leader is unknown! (KWEFBaseWorker::loadSubFile)" << endl;
 
85
    }
 
86
    return flag;
 
87
}
 
88
 
 
89
QIODevice* KWEFBaseWorker::getSubFileDevice(const QString& fileName) const
 
90
{
 
91
    if (!m_kwordLeader)
 
92
    {
 
93
        kdWarning(30508) << "Leader is unknown! (KWEFBaseWorker::getSubFileDevice)" << endl;
 
94
        return NULL;
 
95
    }
 
96
    return m_kwordLeader->getSubFileDevice(fileName);
 
97
}
 
98
 
 
99
QImage KWEFBaseWorker::loadAndConvertToImage(const QString& strName, const QString& inExtension) const
 
100
{
 
101
    QIODevice* io=getSubFileDevice(strName);
 
102
    if (!io)
 
103
    {
 
104
        // NO message error, as there must be already one
 
105
        return QImage();
 
106
    }
 
107
 
 
108
    kdDebug(30508) << "Picture " << strName << " has size: " << io->size() << endl;
 
109
    
 
110
    KoPicture picture;
 
111
    if (!picture.load(io, inExtension)) // we do not care about KoPictureKey
 
112
    {
 
113
        kdWarning(30508) << "Could not read picture: " << strName << " (KWEFBaseWorker::loadAndConvertToImage)" << endl;
 
114
        return QImage();
 
115
    }
 
116
    
 
117
    return picture.generateImage(picture.getOriginalSize()); // ### TODO: KoPicture::getOriginalSize is bad for cliparts
 
118
}
 
119
 
 
120
bool KWEFBaseWorker::loadAndConvertToImage(const QString& strName, const QString& inExtension, const QString& outExtension, QByteArray& image) const
 
121
{
 
122
    QImage qimage(loadAndConvertToImage(strName,inExtension));
 
123
    
 
124
    if (qimage.isNull())
 
125
    {
 
126
        kdWarning(30508) << "Could not load image (KWEFBaseWorker::loadAndConvertToImage)" <<endl;
 
127
        return false;
 
128
    }
 
129
    
 
130
    QImageIO imageIO;
 
131
    imageIO.setImage(qimage);
 
132
 
 
133
    QBuffer buffer(image); // A QBuffer is a QIODevice
 
134
    if (!buffer.open(IO_WriteOnly))
 
135
    {
 
136
        kdWarning(30508) << "Could not open buffer! (KWEFBaseWorker::loadAndConvertToImage)" << endl;
 
137
        return false;
 
138
    }
 
139
 
 
140
    imageIO.setIODevice(&buffer);
 
141
    imageIO.setFormat(outExtension.utf8());
 
142
 
 
143
    if (!imageIO.write())
 
144
    {
 
145
        kdWarning(30508) << "Could not write converted image! (KWEFBaseWorker::loadAndConvertToImage)" << endl;
 
146
        return false;
 
147
    }
 
148
    buffer.close();
 
149
 
 
150
    return true;
 
151
}
 
152
 
 
153
 
 
154
//
 
155
// Secondly, define all methods returning false
 
156
//
 
157
 
 
158
#define DO_FALSE_DEFINITION(string) \
 
159
    bool KWEFBaseWorker::string \
 
160
    {\
 
161
        kdWarning(30508) << "KWEFBaseWorker::" << #string << " was called (Worker not correctly defined?)" << endl; \
 
162
        return false;\
 
163
    }
 
164
 
 
165
DO_FALSE_DEFINITION (doOpenFile (const QString& , const QString& ))
 
166
DO_FALSE_DEFINITION (doCloseFile (void))
 
167
DO_FALSE_DEFINITION (doOpenDocument (void))
 
168
DO_FALSE_DEFINITION (doCloseDocument (void))
 
169
 
 
170
// The following is not generated by the leader
 
171
DO_FALSE_DEFINITION (doFullParagraph(const QString&, const LayoutData&, const ValueListFormatData&))
 
172
 
 
173
//
 
174
// Thirdly, define all methods returning true
 
175
//
 
176
 
 
177
#define DO_TRUE_DEFINITION(string) \
 
178
    bool KWEFBaseWorker::string \
 
179
    {\
 
180
        return true;\
 
181
    }
 
182
 
 
183
DO_TRUE_DEFINITION (doFullDocumentInfo (const KWEFDocumentInfo&))
 
184
DO_TRUE_DEFINITION (doVariableSettings (const VariableSettingsData &))
 
185
DO_TRUE_DEFINITION (doFullPaperFormat (const int, const double, const double, const int))
 
186
DO_TRUE_DEFINITION (doFullPaperBorders (const double, const double, const double, const double))
 
187
DO_TRUE_DEFINITION (doPageInfo(int,int))
 
188
DO_TRUE_DEFINITION (doOpenHead (void))
 
189
DO_TRUE_DEFINITION (doCloseHead (void))
 
190
DO_TRUE_DEFINITION (doOpenBody (void))
 
191
DO_TRUE_DEFINITION (doCloseBody (void))
 
192
DO_TRUE_DEFINITION (doOpenStyles (void))
 
193
DO_TRUE_DEFINITION (doCloseStyles (void))
 
194
DO_TRUE_DEFINITION (doFullDefineStyle (LayoutData&))
 
195
DO_TRUE_DEFINITION (doOpenSpellCheckIgnoreList (void))
 
196
DO_TRUE_DEFINITION (doCloseSpellCheckIgnoreList (void))
 
197
DO_TRUE_DEFINITION (doFullSpellCheckIgnoreWord (const QString&))
 
198
DO_TRUE_DEFINITION (doHeader(const HeaderData&))
 
199
DO_TRUE_DEFINITION (doFooter(const FooterData&))
 
200
 
 
201
//  The following are not generated by the leader
 
202
DO_TRUE_DEFINITION (doOpenTextFrameSet (void))
 
203
DO_TRUE_DEFINITION (doCloseTextFrameSet (void))