lib

KoOasisContext.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004-2006 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "KoOasisContext.h"
21#include <KoOasisStyles.h>
22#include <KoOasisStore.h>
23#include <KoXmlNS.h>
24#include <KoXmlWriter.h>
25#include <kdebug.h>
26#include <KoDom.h>
27
28KoOasisContext::KoOasisContext( KoDocument* doc, KoVariableCollection& varColl,
29 KoOasisStyles& styles, KoStore* store )
30 : KoOasisLoadingContext( doc, styles, store ),
31 m_varColl( varColl ),
32 m_cursorTextParagraph( 0 )
33{
34}
35
36static TQDomElement findListLevelStyle( const TQDomElement& fullListStyle, int level )
37{
38 for ( TQDomNode n = fullListStyle.firstChild(); !n.isNull(); n = n.nextSibling() )
39 {
40 const TQDomElement listLevelItem = n.toElement();
41 if ( listLevelItem.attributeNS( KoXmlNS::text, "level", TQString() ).toInt() == level )
42 return listLevelItem;
43 }
44 return TQDomElement();
45}
46
47bool KoOasisContext::pushListLevelStyle( const TQString& listStyleName, int level )
48{
49 TQDomElement* fullListStyle = oasisStyles().listStyles()[listStyleName];
50 if ( !fullListStyle ) {
51 kdWarning(32500) << "List style " << listStyleName << " not found!" << endl;
52 return false;
53 }
54 else
55 return pushListLevelStyle( listStyleName, *fullListStyle, level );
56}
57
59{
60 TQDomElement outlineStyle = KoDom::namedItemNS( oasisStyles().officeStyle(), KoXmlNS::text, "outline-style" );
61 return pushListLevelStyle( "<outline-style>", outlineStyle, level );
62}
63
64bool KoOasisContext::pushListLevelStyle( const TQString& listStyleName, // for debug only
65 const TQDomElement& fullListStyle, int level )
66{
67 // Find applicable list-level-style for level
68 int i = level;
69 TQDomElement listLevelStyle;
70 while ( i > 0 && listLevelStyle.isNull() ) {
71 listLevelStyle = findListLevelStyle( fullListStyle, i );
72 --i;
73 }
74 if ( listLevelStyle.isNull() ) {
75 kdWarning(32500) << "List level style for level " << level << " in list style " << listStyleName << " not found!" << endl;
76 return false;
77 }
78 //kdDebug(32500) << "Pushing list-level-style from list-style " << listStyleName << " level " << level << endl;
79 m_listStyleStack.push( listLevelStyle );
80 return true;
81}
82
83void KoOasisContext::setCursorPosition( KoTextParag* cursorTextParagraph,
84 int cursorTextIndex )
85{
86 m_cursorTextParagraph = cursorTextParagraph;
87 m_cursorTextIndex = cursorTextIndex;
88}
89
90KoOasisContext::~KoOasisContext()
91{
92}
93
95
96KoSavingContext::KoSavingContext( KoGenStyles& mainStyles, KoVariableSettings* settings, bool hasColumns, SavingMode savingMode )
97 : m_mainStyles( mainStyles ),
98 m_savingMode( savingMode ),
99 m_cursorTextParagraph( 0 ),
100 m_variableSettings( settings ),
101 m_hasColumns( hasColumns )
102{
103}
104
105
106KoSavingContext::~KoSavingContext()
107{
108}
109
110void KoSavingContext::setCursorPosition( KoTextParag* cursorTextParagraph,
111 int cursorTextIndex )
112{
113 m_cursorTextParagraph = cursorTextParagraph;
114 m_cursorTextIndex = cursorTextIndex;
115}
116
117void KoSavingContext::addFontFace( const TQString& fontName )
118{
119 m_fontFaces[fontName] = true;
120}
121
122void KoSavingContext::writeFontFaces( KoXmlWriter& writer )
123{
124 writer.startElement( "office:font-face-decls" );
125 const TQStringList fontFaces = m_fontFaces.keys();
126 for ( TQStringList::const_iterator ffit = fontFaces.begin(), ffend = fontFaces.end() ; ffit != ffend ; ++ffit ) {
127 writer.startElement( "style:font-face" );
128 writer.addAttribute( "style:name", *ffit );
129 writer.addAttribute( "svg:font-family", *ffit );
130 // TODO style:font-family-generic
131 // TODO style:font-pitch
132 writer.endElement(); // style:font-face
133 }
134 writer.endElement(); // office:font-face-decls
135}
The KOffice document class.
Definition KoDocument.h:61
Repository of styles used during saving of OASIS/OOo file.
Definition KoGenStyles.h:60
bool pushListLevelStyle(const TQString &listStyleName, int level)
Used for lists (numbered paragraphs).
bool pushOutlineListLevelStyle(int level)
Used for outline levels.
KoOasisContext(KoDocument *doc, KoVariableCollection &varColl, KoOasisStyles &styles, KoStore *store)
Stores reference to the KoOasisStyles parsed by KoDocument.
void setCursorPosition(KoTextParag *cursorTextParagraph, int cursorTextIndex)
Set cursor position (set by KoTextParag upon finding the processing instruction).
KoOasisLoadingContext(KoDocument *doc, KoOasisStyles &styles, KoStore *store)
Stores reference to the KoOasisStyles and stored passed by KoDocument.
Repository of styles used during loading of OASIS/OOo file.
SavingMode savingMode() const
void setCursorPosition(KoTextParag *cursorTextParagraph, int cursorTextIndex)
Set cursor position (so that KoTextParag can insert a processing instruction).
KoSavingContext(KoGenStyles &mainStyles, KoVariableSettings *settings=0, bool hasColumns=false, SavingMode savingMode=Store)
Constructor.
Saves and loads KOffice documents using various backends.
Definition KoStore.h:40
A class for writing out XML (to any TQIODevice), with a special attention on performance.
Definition KoXmlWriter.h:37
void startElement(const char *tagName, bool indentInside=true)
Start a new element, as a child of the current element.
void endElement()
Terminate the current element.
void addAttribute(const char *attrName, const TQString &value)
Overloaded version of addAttribute( const char*, const char* ), which is a bit slower because it need...
Definition KoXmlWriter.h:76
KOFFICECORE_EXPORT TQDomElement namedItemNS(const TQDomNode &node, const char *nsURI, const char *localName)
A namespace-aware version of TQDomNode::namedItem(), which also takes care of casting to a TQDomEleme...
Definition KoDom.cpp:22