19#include "KWOasisLoader.h"
20#include "KWDocument.h"
21#include "KWTextDocument.h"
22#include "KWTextFrameSet.h"
23#include "KWFrameSet.h"
24#include "KWPictureFrameSet.h"
25#include "KWLoadingInfo.h"
26#include "KWTableFrameSet.h"
27#include "KWPartFrameSet.h"
28#include "KWPageManager.h"
29#include "KWFormulaFrameSet.h"
32#include <KoOasisContext.h>
33#include <KoOasisStyles.h>
34#include <KoOasisStore.h>
35#include <KoOasisSettings.h>
43#include <tqvaluelist.h>
46KWOasisLoader::KWOasisLoader( KWDocument* doc )
53TQValueList<KWFrame *> KWOasisLoader::insertOasisData( KoStore* store, KoTextCursor* cursor )
55 TQValueList<KWFrame *> frames;
56 if ( store->bad() || !store->hasFile(
"content.xml" ) )
58 kdError(32001) <<
"Invalid ZIP store in memory" << endl;
59 if ( !store->hasFile(
"content.xml" ) )
60 kdError(32001) <<
"No content.xml file" << endl;
63 store->disallowNameExpansion();
65 KoOasisStore oasisStore( store );
66 TQDomDocument contentDoc;
67 TQString errorMessage;
68 bool ok = oasisStore.loadAndParse(
"content.xml", contentDoc, errorMessage );
70 kdError(32001) <<
"Error parsing content.xml: " << errorMessage << endl;
74 KoOasisStyles oasisStyles;
75 TQDomDocument stylesDoc;
76 (void)oasisStore.loadAndParse(
"styles.xml", stylesDoc, errorMessage );
78 oasisStyles.createStyleMap( stylesDoc,
true );
80 oasisStyles.createStyleMap( contentDoc,
false );
82 m_doc->createLoadingInfo();
84 TQDomElement content = contentDoc.documentElement();
86 TQDomElement body( KoDom::namedItemNS( content, KoXmlNS::office,
"body" ) );
87 if ( body.isNull() ) {
88 kdError(32001) <<
"No office:body found!" << endl;
93 TQDomElement iter, realBody;
94 forEachElement( iter, body ) {
97 if ( realBody.isNull() ) {
98 kdError(32001) <<
"No element found inside office:body!" << endl;
102 KoOasisContext context( m_doc, *m_doc->variableCollection(), oasisStyles, store );
108 *cursor = textFs->
textObject()->pasteOasisText( realBody, context, *cursor, m_doc->styleCollection() );
110 textFs->
textObject()->setNeedSpellCheck(
true );
117 forEachElement( tag, realBody )
119 context.styleStack().save();
120 const TQString bodyTagLocalName = tag.localName();
121 kdDebug() << k_funcinfo << bodyTagLocalName << endl;
122 if ( bodyTagLocalName ==
"frame" && tag.namespaceURI() == KoXmlNS::draw )
124 KWFrame * frame = loadFrame( tag, context, KoPoint( 10, 10 ) );
127 frames.append( frame );
131 else if ( bodyTagLocalName ==
"table" && tag.namespaceURI() == KoXmlNS::table )
138 m_doc->completeOasisPasting();
139 m_doc->deleteLoadingInfo();
143void KWOasisLoader::loadOasisSettings(
const TQDomDocument& settingsDoc )
145 KoOasisSettings settings( settingsDoc );
146 KoOasisSettings::Items viewSettings = settings.itemSet(
"view-settings" );
147 if ( !viewSettings.isNull() )
149 m_doc->setUnit( KoUnit::unit(viewSettings.parseConfigItemString(
"unit")) );
151 loadOasisIgnoreList( settings );
152 m_doc->variableCollection()->variableSetting()->loadOasis( settings );
155static TQString headerTypeToFramesetName(
const TQString& localName,
bool hasEvenOdd )
157 if ( localName ==
"header" )
158 return hasEvenOdd ? i18n(
"Odd Pages Header") : i18n(
"Header" );
159 if ( localName ==
"header-left" )
160 return i18n(
"Even Pages Header");
161 if ( localName ==
"footer" )
162 return hasEvenOdd ? i18n(
"Odd Pages Footer") : i18n(
"Footer" );
163 if ( localName ==
"footer-left" )
164 return i18n(
"Even Pages Footer");
165 if ( localName ==
"header-first" )
166 return i18n(
"First Page Header");
167 if ( localName ==
"footer-first" )
168 return i18n(
"First Page Footer");
169 kdWarning(32001) <<
"Unknown tag in headerTypeToFramesetName: " << localName << endl;
173static KWFrameSet::Info headerTypeToFrameInfo(
const TQString& localName,
bool )
175 if ( localName ==
"header" )
176 return KWFrameSet::FI_ODD_HEADER;
177 if ( localName ==
"header-left" )
178 return KWFrameSet::FI_EVEN_HEADER;
179 if ( localName ==
"footer" )
180 return KWFrameSet::FI_ODD_FOOTER;
181 if ( localName ==
"footer-left" )
182 return KWFrameSet::FI_EVEN_FOOTER;
186 if ( localName ==
"header-first" )
187 return KWFrameSet::FI_FIRST_HEADER;
188 if ( localName ==
"footer-first" )
189 return KWFrameSet::FI_FIRST_FOOTER;
190 return KWFrameSet::FI_BODY;
193void KWOasisLoader::loadOasisHeaderFooter(
const TQDomElement& headerFooter,
bool hasEvenOdd, TQDomElement& style, KoOasisContext& context )
195 const TQString localName = headerFooter.localName();
196 bool isHeader = localName.startsWith(
"header" );
200 m_doc->addFrameSet( fs,
false );
202 if ( !style.isNull() )
203 context.styleStack().push( style );
204 KWFrame* frame =
new KWFrame( fs, 29, isHeader?0:567, 798-29, 41 );
205 frame->loadCommonOasisProperties( context, fs,
"header-footer" );
206 const TQString minHeight = context.styleStack().attributeNS( KoXmlNS::fo,
"min-height" );
207 if ( !minHeight.isEmpty() )
210 frame->setFrameBehavior( KWFrame::AutoExtendFrame );
211 frame->setNewFrameBehavior( KWFrame::Copy );
212 fs->addFrame( frame );
213 if ( !style.isNull() )
214 context.styleStack().pop();
216 context.setUseStylesAutoStyles(
true );
218 context.setUseStylesAutoStyles(
false );
221 m_doc->m_headerVisible =
true;
223 m_doc->m_footerVisible =
true;
226void KWOasisLoader::loadOasisIgnoreList(
const KoOasisSettings& settings )
228 KoOasisSettings::Items configurationSettings = settings.itemSet(
"configuration-settings" );
229 if ( !configurationSettings.isNull() )
231 const TQString ignorelist = configurationSettings.parseConfigItemString(
"SpellCheckerIgnoreList" );
232 kdDebug()<<
" ignorelist :"<<ignorelist<<endl;
233 m_doc->setSpellCheckIgnoreList( TQStringList::split(
',', ignorelist ) );
237KWFrame* KWOasisLoader::loadFrame(
const TQDomElement& frameTag, KoOasisContext& context,
const KoPoint& offset )
241 forEachElement( elem, frameTag )
243 if ( elem.namespaceURI() != KoXmlNS::draw )
245 const TQString localName = elem.localName();
246 if ( localName ==
"text-box" )
249 frame = loadOasisTextBox( frameTag, elem, context );
252 else if ( localName ==
"image" )
254 KWFrameSet* fs =
new KWPictureFrameSet( m_doc, frameTag, elem, context );
255 m_doc->addFrameSet( fs,
false );
256 frame = fs->
frame(0);
258 }
else if ( localName ==
"object" )
260 TQDomElement mathElem;
261 TQDomElement childElem;
262 forEachElement( childElem, elem )
264 if ( childElem.localName() ==
"math"
265 && childElem.namespaceURI() == KoXmlNS::math ) {
266 mathElem = childElem;
269 if ( !mathElem.isNull() ) {
270 KWFormulaFrameSet* fs =
new KWFormulaFrameSet( m_doc, frameTag, mathElem, context );
271 m_doc->addFrameSet( fs,
false );
272 frame = fs->frame(0);
275 m_doc->addFrameSet( fs,
false );
276 frame = fs->
frame(0);
282 const TQString anchorType = frameTag.attributeNS( KoXmlNS::text,
"anchor-type", TQString() );
283 if ( anchorType ==
"page" ) {
284 double x = KoUnit::parseValue( frameTag.attributeNS( KoXmlNS::svg,
"x", TQString() ) );
285 double y = KoUnit::parseValue( frameTag.attributeNS( KoXmlNS::svg,
"y", TQString() ) );
286 int pageNum = frameTag.attributeNS( KoXmlNS::text,
"anchor-page-number", TQString() ).toInt();
291 frame->moveTopLeft( KoPoint( x, y + pageManager->
topOfPage(pageNum) ) );
293 frame->moveBy( offset.x(), offset.y() );
298KWFrame* KWOasisLoader::loadOasisTextBox(
const TQDomElement& frameTag,
const TQDomElement& tag,
299 KoOasisContext& context )
310 TQString frameName = frameTag.attributeNS( KoXmlNS::draw,
"name", TQString() );
311 TQString chainNextName = tag.attributeNS( KoXmlNS::draw,
"chain-next-name", TQString() );
312 if ( !chainNextName.isEmpty() && loadingInfo ) {
313 kdDebug(32001) <<
"Loading " << frameName <<
" : next-in-chain=" << chainNextName << endl;
315 KWFrame* nextFrame = loadingInfo->frameByName( chainNextName );
318 chainNextName = TQString();
319 kdDebug(32001) <<
" found " << nextFrame <<
" -> frameset " << ( fs ? fs->
name() : TQString() ) << endl;
322 KWFrame* prevFrame = loadingInfo->chainPrevFrame( frameName );
326 Q_ASSERT( fs == prevFrame->
frameSet() );
333 m_doc->addFrameSet( fs,
false );
334 frame = fs->
loadOasis( frameTag, tag, context );
336 context.styleStack().
save();
337 context.fillStyleStack( frameTag, KoXmlNS::draw,
"style-name",
"graphic" );
339 context.styleStack().restore();
342 loadingInfo->storeFrameName( frame, frameName );
344 if ( !chainNextName.isEmpty() ) {
345 loadingInfo->storeNextFrame( frame, chainNextName );
350KWTableFrameSet* KWOasisLoader::loadOasisTable(
const TQDomElement& tag,
351 KoOasisContext& context )
353 const TQString name = tag.attributeNS( KoXmlNS::table,
"name", i18n(
"Unnamed Table" ) );
355 table->loadOasis( tag, context );
356 m_doc->addFrameSet(table,
false);
Class: KWFrameSet Base type, a frameset holds content as well as frames to show that content.
Info
The different types of textFramesets (that TEXT is important here!) FI_BODY = normal text frames.
KWFrame * frame(unsigned int _num) const
get a frame by number
TQString name() const
get/set frameset name. For tables in particular, this must be unique
void setFrameSetInfo(Info fi)
Set the type of TextFrameSet this is.
This class represents a single frame.
KWFrameSet * frameSet() const
Data stucture methods.
void setMinimumFrameHeight(double h)
The property minimum frame height is used to make the automatic frame shrinking code stop.
void save(TQDomElement &frameElem)
create XML to describe yourself
Temporary information used only during loading.
The Page Manager manages all the pages a document contains and separates all the frames the document ...
double topOfPage(int pageNumber) const
Return the y-offset in this document of the top of page with pageNumber Note that pageNumber is NOT a...
KWPage * appendPage()
Append a new page at the end of the document.
int lastPageNumber() const
return the highest page number we have in this document.
A frameset that contains an embedded object (a KWDocumentChild)
This class implements tables by acting as the manager for the frame(set)s which make up the table cel...
This is our KoTextDocument reimplementation, to create KWTextParag instead of KoTextParags,...
KWTextFrameSet * textFrameSet() const
Return the text frameset in which this document is.
Class: KWTextFrameSet Contains text (KoTextObject) and frames to display that text.
KoTextObject * textObject() const
Return the contained text object.
KWFrame * loadOasisTextFrame(const TQDomElement &frameTag, const TQDomElement &tag, KoOasisContext &context)
Load a frame and add it to this frameset - called by KWOasisLoader.
KWFrame * loadOasis(const TQDomElement &frame, const TQDomElement &bodyElem, KoOasisContext &context)
Load a complete textbox (frame and text)
void loadOasisContent(const TQDomElement &bodyElem, KoOasisContext &context)
Load the contents of a frame (i.e. the text)