From kde-commits Tue Jul 31 23:03:50 2012 From: Inge Wallin Date: Tue, 31 Jul 2012 23:03:50 +0000 To: kde-commits Subject: [calligra/export-epub-moji] filters/words/epub: Even more cleaning. Message-Id: <20120731230350.36390A6094 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=134377610705805 Git commit 046447c35fc2a656e50b08001e9d2c0c39218e89 by Inge Wallin. Committed on 01/08/2012 at 01:03. Pushed by ingwa into branch 'export-epub-moji'. Even more cleaning. M +46 -35 filters/words/epub/htmlconvert.cpp http://commits.kde.org/calligra/046447c35fc2a656e50b08001e9d2c0c39218e89 diff --git a/filters/words/epub/htmlconvert.cpp b/filters/words/epub/htmlco= nvert.cpp index 4425330..225ed2b 100644 --- a/filters/words/epub/htmlconvert.cpp +++ b/filters/words/epub/htmlconvert.cpp @@ -420,34 +420,22 @@ QPair convertConten= t(KoStore *odfStore, QHash< //kDebug(30517) << nodeElement.tagName() <endElement(); - bodyWriter->endElement(); - // Save this node for next html file. - startNode =3D sibl; - // Return - odfStore->close(); - return qMakePair(KoFilter::OK, true); - } + // This paragraph is at top level so we should close the h= tml file and return. + bodyWriter->endElement(); + bodyWriter->endElement(); + // Save this node for next html file. + startNode =3D sibl; + // Return + odfStore->close(); + return qMakePair(KoFilter::OK, true); } = if (nodeElement.tagName() =3D=3D "p") @@ -524,36 +512,49 @@ QPair convertConten= t(KoStore *odfStore, QHash< childNode =3D childNode.nextSibling(); nodeElement =3D childNode.toElement(); } + else if (nodeElement.tagName() =3D=3D "table") { + // Handle table = - // Handle frames + handleTagTable(nodeElement, bodyWriter); + + // FIXME: I don't understand this at all. /IW + if (pFlag) { + if (childNode.nextSibling().isNull()) { + childNode =3D pNode; + nodeElement =3D childNode.toElement(); + pFlag =3D false; + } + } + } = else if (nodeElement.tagName() =3D=3D "frame") { + // Handle frame + if (!pFlag) { bodyWriter->startElement("div"); - bodyWriter->startElement("img"); } - else - bodyWriter->startElement("img"); + + bodyWriter->startElement("img"); bodyWriter->addAttribute("class", nodeElement.attribute("style= -name")); bodyWriter->addAttribute("alt", "(No Description)"); = // Check image tag to find image source - QDomNode imgNode =3D childNode.firstChild(); - QDomElement imgElement =3D imgNode.toElement(); + QDomElement imgElement =3D childNode.firstChild().toElement(); = QString imgSrc =3D imgElement.attribute("href").section('/', 1= ); // I like section :) bodyWriter->addAttribute("src", imgSrc); //bodyWriter->endElement(); = if (pFlag) { + // FIXME: What's going on here?? /IW if (childNode.nextSibling().isNull()) { - bodyWriter->endElement(); + bodyWriter->endElement(); // Why isn't the img tag *al= ways* ended? childNode =3D pNode; nodeElement =3D childNode.toElement(); pFlag =3D false; } } else - bodyWriter->endElement(); + bodyWriter->endElement(); // div } else if (nodeElement.tagName() =3D=3D "soft-page-break") { bodyWriter->addTextNode(nodeElement.text().toUtf8()); @@ -580,6 +581,15 @@ QPair convertContent= (KoStore *odfStore, QHash< nodeElement =3D childNode.toElement(); pFlag =3D false; } + + // FIXME: This is a bad optimization that makes the code super + // difficult to follow! Wherever there is a + // startElement() there should also be an + // endElement(). The calls to endElement() should not + // be optimized this way. It leads to bugs. For + // instance, the case "Ignore unknown tag" above has no + // call to startElement() at all. Yet we have this here + // endElement(). :( bodyWriter->endElement(); // tagName() = if (!pFlag) @@ -590,7 +600,6 @@ QPair convertContent(= KoStore *odfStore, QHash< } = bodyWriter->endElement(); // body - bodyWriter->endElement(); // html = odfStore->close(); @@ -718,5 +727,7 @@ void handleTagTable(QDomElement &nodeElement, KoXmlWrit= er *bodyWriter) tableElement =3D tableNode.toElement(); } // end while write tag row = - bodyWriter->endElement(); // table + // FIXME: Apparently the tag is ended in the main loop. = + // That "optimization" is bad and should be removed. + //bodyWriter->endElement(); // table }