Commit b546f335 authored by Matus Uzak's avatar Matus Uzak
Browse files

DOC: Updated support for nested shapes.

BUG:274903
parent 0ee2ffbd
......@@ -118,10 +118,10 @@ Document::Document(const std::string& fileName,
this, SLOT(slotHeadersFound(const wvWare::FunctorBase*, int)));
connect(m_textHandler, SIGNAL(tableFound(KWord::Table*)),
this, SLOT(slotTableFound(KWord::Table*)));
connect(m_textHandler, SIGNAL(inlineObjectFound(const wvWare::PictureData&,KoXmlWriter*)),
connect(m_textHandler, SIGNAL(inlineObjectFound(const wvWare::PictureData&, KoXmlWriter*)),
this, SLOT(slotInlineObjectFound(const wvWare::PictureData&, KoXmlWriter*)));
connect(m_textHandler, SIGNAL(floatingObjectFound(unsigned int, KoXmlWriter* )),
this, SLOT(slotFloatingObjectFound(unsigned int, KoXmlWriter* )));
connect(m_textHandler, SIGNAL(floatingObjectFound(unsigned int, KoXmlWriter*)),
this, SLOT(slotFloatingObjectFound(unsigned int, KoXmlWriter*)));
connect(m_graphicsHandler, SIGNAL(textBoxFound(unsigned int, bool)),
this, SLOT(slotTextBoxFound(unsigned int, bool)));
......@@ -927,29 +927,19 @@ void Document::slotTableFound(KWord::Table* table)
void Document::slotInlineObjectFound(const wvWare::PictureData& data, KoXmlWriter* writer)
{
kDebug(30513) ;
//if we have a temp writer, tell the graphicsHandler
if (writer) {
m_graphicsHandler->setBodyWriter(writer);
}
Q_UNUSED(writer);
m_graphicsHandler->setCurrentWriter(m_textHandler->currentWriter());
m_graphicsHandler->handleInlineObject(data);
if (writer) {
m_graphicsHandler->setBodyWriter(m_bodyWriter);
}
m_graphicsHandler->setCurrentWriter(m_textHandler->currentWriter());
}
void Document::slotFloatingObjectFound(unsigned int globalCP, KoXmlWriter* writer)
{
kDebug(30513) ;
//if we have a temp writer, tell the graphicsHandler
if (writer) {
m_graphicsHandler->setBodyWriter(writer);
}
Q_UNUSED(writer);
m_graphicsHandler->setCurrentWriter(m_textHandler->currentWriter());
m_graphicsHandler->handleFloatingObject(globalCP);
if (writer) {
m_graphicsHandler->setBodyWriter(m_bodyWriter);
}
m_graphicsHandler->setCurrentWriter(m_textHandler->currentWriter());
}
void Document::slotTextBoxFound(unsigned int index, bool stylesxml)
......
......@@ -155,14 +155,15 @@ void DrawingWriter::setChildRectangle(MSO::OfficeArtChildAnchor& anchor)
* ************************************************
*/
KWordGraphicsHandler::KWordGraphicsHandler(Document* doc,
KoXmlWriter* bodyWriter, KoXmlWriter* manifestWriter,
KoXmlWriter* bodyWriter,
KoXmlWriter* manifestWriter,
KoStore* store, KoGenStyles* mainStyles,
const wvWare::Drawings* p_drawings,
const wvWare::Word97::FIB& fib)
: QObject()
, m_document(doc)
, m_store(store)
, m_bodyWriter(bodyWriter)
, m_currentWriter(bodyWriter)
, m_manifestWriter(manifestWriter)
, m_mainStyles(mainStyles)
, m_drawings(p_drawings)
......@@ -222,11 +223,6 @@ void KWordGraphicsHandler::emitTextBoxFound(unsigned int index, bool stylesxml)
emit textBoxFound(index, stylesxml);
}
void KWordGraphicsHandler::setBodyWriter(KoXmlWriter* writer)
{
m_bodyWriter = writer;
}
DrawStyle KWordGraphicsHandler::getBgDrawStyle()
{
const OfficeArtSpContainer* shape = 0;
......@@ -250,7 +246,7 @@ void KWordGraphicsHandler::handleInlineObject(const wvWare::PictureData& data)
//the picture is store in some external file
if (data.picf->mfp.mm == MM_SHAPEFILE) {
DrawingWriter out(*m_bodyWriter, *m_mainStyles, m_document->writingHeader());
DrawingWriter out(*m_currentWriter, *m_mainStyles, m_document->writingHeader());
m_objectType = Inline;
m_picf = data.picf;
insertEmptyInlineFrame(out);
......@@ -323,7 +319,7 @@ void KWordGraphicsHandler::handleInlineObject(const wvWare::PictureData& data)
m_store->leaveDirectory();
bool inStylesXml = m_document->writingHeader();
DrawingWriter out(*m_bodyWriter, *m_mainStyles, inStylesXml);
DrawingWriter out(*m_currentWriter, *m_mainStyles, inStylesXml);
//global attributes
m_objectType = Inline;
......@@ -372,7 +368,7 @@ void KWordGraphicsHandler::handleFloatingObject(unsigned int globalCP)
if ((it.currentStart() + threshold) == globalCP) {
bool inStylesXml = m_document->writingHeader();
DrawingWriter out(*m_bodyWriter, *m_mainStyles, inStylesXml);
DrawingWriter out(*m_currentWriter, *m_mainStyles, inStylesXml);
//global attributes
m_objectType = Floating;
......
......@@ -119,12 +119,20 @@ private:
DrawClient(KWordGraphicsHandler* p) :gh(p) {}
};
public:
KWordGraphicsHandler(Document* doc, KoXmlWriter* bodyWriter, KoXmlWriter* manifestWriter,
KWordGraphicsHandler(Document* document,
KoXmlWriter* bodyWriter,
KoXmlWriter* manifestWriter,
KoStore* store, KoGenStyles* mainStyles,
const wvWare::Drawings* p_drawings,
const wvWare::Word97::FIB& fib);
~KWordGraphicsHandler();
/**
* Set the appropriate writer for object properties and content.
* @param writer KoXmlWriter provided by the Document class
*/
void setCurrentWriter(KoXmlWriter* writer) { m_currentWriter = writer; };
/**
* This method gets called when a floating object is found by wv2 parser.
* @param globalCP actual character position in the WordDocument stream.
......@@ -137,12 +145,6 @@ public:
*/
virtual void handleInlineObject(const wvWare::PictureData& data);
/**
* Set the appropriate writer for object properties and content.
* @param writer KoXmlWriter provided by the Document class
*/
void setBodyWriter(KoXmlWriter* writer);
/**
* Get the DrawStyle to access document backgroud properties and defaults.
*
......@@ -275,7 +277,7 @@ private:
Document* m_document;
KoStore* m_store;
KoXmlWriter* m_bodyWriter;
KoXmlWriter* m_currentWriter;
KoXmlWriter* m_manifestWriter;
KoGenStyles* m_mainStyles;
......
......@@ -662,13 +662,17 @@ void KWordTextHandler::inlineObjectFound(const wvWare::PictureData& data)
return;
}
m_insideDrawing = true;
//save the state of tables/paragraphs/lists (text-box)
saveState();
//create temporary writer for the picture tags
//Create temporary writer for the picture tags.
KoXmlWriter* writer = 0;
QBuffer buf;
buf.open(QIODevice::WriteOnly);
m_drawingWriter = new KoXmlWriter(&buf);
KoXmlWriter* writer = m_drawingWriter;
writer = new KoXmlWriter(&buf);
m_drawingWriter = writer;
m_insideDrawing = true;
//frame or drawing shape acting as a hyperlink
if (m_fld->m_hyperLinkActive) {
......@@ -677,30 +681,27 @@ void KWordTextHandler::inlineObjectFound(const wvWare::PictureData& data)
writer->addAttribute("xlink:href", QUrl(m_fld->m_hyperLinkUrl).toEncoded());
}
//save the state of tables/paragraphs/lists (text-box)
saveState();
emit inlineObjectFound(data, m_drawingWriter);
emit inlineObjectFound(data, writer);
//TODO: we should really improve processing of lists somehow
if (listIsOpen()) {
closeList();
}
restoreState();
if (m_fld->m_hyperLinkActive) {
writer->endElement();
m_fld->m_hyperLinkActive = false;
}
//cleanup
delete m_drawingWriter;
m_drawingWriter = 0;
m_insideDrawing = false;
//restore the state
restoreState();
//now add content to our current paragraph
QString contents = QString::fromUtf8(buf.buffer(), buf.buffer().size());
m_paragraph->addRunOfText(contents, 0, QString(""), m_parser->styleSheet(), true);
m_insideDrawing = false;
//cleanup
delete m_drawingWriter;
m_drawingWriter = 0;
}
void KWordTextHandler::floatingObjectFound(unsigned int globalCP)
......@@ -715,13 +716,17 @@ void KWordTextHandler::floatingObjectFound(unsigned int globalCP)
return;
}
m_insideDrawing = true;
//save the state of tables/paragraphs/lists (text-box)
saveState();
//create temporary writer for the picture tags
QBuffer drawingBuffer;
drawingBuffer.open(QIODevice::WriteOnly);
m_drawingWriter = new KoXmlWriter(&drawingBuffer);
KoXmlWriter* writer = m_drawingWriter;
//Create temporary writer for the picture tags.
KoXmlWriter* writer = 0;
QBuffer buf;
buf.open(QIODevice::WriteOnly);
writer = new KoXmlWriter(&buf);
m_drawingWriter = writer;
m_insideDrawing = true;
//frame or drawing shape acting as a hyperlink
if (m_fld->m_hyperLinkActive) {
......@@ -730,30 +735,27 @@ void KWordTextHandler::floatingObjectFound(unsigned int globalCP)
writer->addAttribute("xlink:href", QUrl(m_fld->m_hyperLinkUrl).toEncoded());
}
//save the state of tables/paragraphs/lists (text-box)
saveState();
emit floatingObjectFound(globalCP, m_drawingWriter);
emit floatingObjectFound(globalCP, writer);
//TODO: we should really improve processing of lists somehow
if (listIsOpen()) {
closeList();
}
restoreState();
if (m_fld->m_hyperLinkActive) {
writer->endElement();
m_fld->m_hyperLinkActive = false;
}
//now add content to our current paragraph
QString contents = QString::fromUtf8(drawingBuffer.buffer(), drawingBuffer.buffer().size());
m_paragraph->addRunOfText(contents, 0, QString(""), m_parser->styleSheet());
m_insideDrawing = false;
//cleanup
delete m_drawingWriter;
m_drawingWriter = 0;
m_insideDrawing = false;
//restore the state
restoreState();
//now add content to our current paragraph
QString contents = QString::fromUtf8(buf.buffer(), buf.buffer().size());
m_paragraph->addRunOfText(contents, 0, QString(""), m_parser->styleSheet(), true);
}
// Sets m_currentStyle with PAP->istd (index to STSH structure)
......@@ -2220,13 +2222,17 @@ void KWordTextHandler::saveState()
{
kDebug(30513);
m_oldStates.push(State(m_currentTable, m_paragraph, m_listStyleName,
m_currentListDepth, m_currentListID, m_previousLists));
m_currentListDepth, m_currentListID, m_previousLists,
m_drawingWriter, m_insideDrawing));
m_currentTable = 0;
m_paragraph = 0;
m_listStyleName = "";
m_currentListDepth = -1;
m_currentListID = 0;
m_previousLists.clear();
m_drawingWriter = 0;
m_insideDrawing = false;
}
void KWordTextHandler::restoreState()
......@@ -2242,17 +2248,24 @@ void KWordTextHandler::restoreState()
//warn if pointers weren't reset properly, but restore state anyway
if (m_paragraph != 0) {
kWarning() << "m_paragraph pointer wasn't reset";
kWarning() << "Warning: m_paragraph pointer wasn't reset!";
}
m_paragraph = s.paragraph;
if (m_currentTable != 0) {
kWarning() << "m_currentTable pointer wasn't reset";
kWarning() << "Warning: m_currentTable pointer wasn't reset!";
}
if (m_drawingWriter != 0) {
kWarning() << "Warning: m_drawingWriter pointer wasn't reset!";
}
m_currentTable = s.currentTable;
m_paragraph = s.paragraph;
m_currentTable = s.table;
m_listStyleName = s.listStyleName;
m_currentListDepth = s.currentListDepth;
m_currentListID = s.currentListID;
m_currentListDepth = s.listDepth;
m_currentListID = s.listID;
m_previousLists = s.previousLists;
m_drawingWriter = s.drawingWriter;
m_insideDrawing = s.insideDrawing;
}
void KWordTextHandler::fld_saveState()
......
......@@ -103,7 +103,7 @@ public:
virtual void bookmarkEnd( const wvWare::BookmarkData& data );
virtual void inlineObjectFound(const wvWare::PictureData& data);
virtual void floatingObjectFound(unsigned int globalCP );
virtual void floatingObjectFound(unsigned int globalCP);
///////// Our own interface
......@@ -198,20 +198,31 @@ private:
// State
// ************************************************
//save/restore for processing footnotes (very similar to the wv2 method)
//save/restore (very similar to the wv2 method)
struct State {
State(KWord::Table* curTab, Paragraph* para, QString lStyleName,
int curListDepth, int curListID, const QMap<int, QString> &preLists) :
currentTable(curTab), paragraph(para), listStyleName(lStyleName),
currentListDepth(curListDepth), currentListID(curListID),
previousLists(preLists) {}
KWord::Table* currentTable;
State(KWord::Table* table, Paragraph* paragraph,
QString listStyleName, int listDepth, int listID,
const QMap<int, QString> &prevLists,
KoXmlWriter* drawingWriter, bool insideDrawing) :
table(table),
paragraph(paragraph),
listStyleName(listStyleName),
listDepth(listDepth),
listID(listID),
previousLists(prevLists),
drawingWriter(drawingWriter),
insideDrawing(insideDrawing)
{}
KWord::Table* table;
Paragraph* paragraph;
QString listStyleName;
int currentListDepth; //tells us which list level we're on (-1 if not in a list)
int currentListID; //tracks the id of the current list - 0 if no list
int listDepth; //tells us which list level we're on (-1 if not in a list)
int listID; //tracks the id of the current list - 0 if no list
QMap<int, QString> previousLists; //remember previous lists, to continue numbering
KoXmlWriter* drawingWriter;
bool insideDrawing;
};
std::stack<State> m_oldStates;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment