[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-bugs-dist
Subject:    [Bug 74601] kword doesn't recognize PRE-tags in HTML
From:       Helge Deller <deller () kde ! org>
Date:       2006-03-04 23:11:57
Message-ID: 20060304231157.4348.qmail () ktown ! kde ! org
[Download RAW message or body]

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
         
http://bugs.kde.org/show_bug.cgi?id=74601         




------- Additional Comments From deller kde org  2006-03-05 00:11 -------
SVN commit 515811 by deller:

some work on Bug #74601 (normal): kword doesn't recognize PRE-tags in
  HTML
CCBUG:74601


 M  +13 -1     khtmlreader.cpp  
 M  +1 -0      khtmlreader.h  
 M  +20 -7     kwdwriter.cpp  
 M  +1 -1      kwdwriter.h  


--- trunk/koffice/filters/kword/html/import/khtmlreader.cpp #515810:515811
 @ -75,6 +75,7  @
 		s->paragraph = _writer->addParagraph(s->frameset);
 		s->format=_writer->currentFormat(s->paragraph,true);
 		s->layout=_writer->currentLayout(s->paragraph);
+		s->in_pre_mode = false;
 		_state.push(s);
 	}
 	return _state.top();
 @ -86,6 +87,7  @
         s->paragraph=state()->paragraph;
         s->format=state()->format;
         s->layout=state()->layout;
+	s->in_pre_mode=state()->in_pre_mode;
         _writer->cleanUpParagraph(s->paragraph);
         _state.push(s);
         return s;
 @ -161,7 +163,7  @
         // check if this is a text node.
 	DOM::Text t=node;
 	if (!t.isNull()) {
-	   _writer->addText(state()->paragraph,t.data().string());
+	   _writer->addText(state()->paragraph,t.data().string(),state()->in_pre_mode);
 	   return; // no children anymore...
 	}
 
 @ -543,6 +545,7  @
 }
 
 bool KHTMLReader::parse_pre(DOM::Element e) {
+#if 0 // see Bug #74601 (normal): kword doesn't recognize PRE-tags in HTML
 	//pushNewState();
 	/// \todo set fixed width font
 	DOM::HTMLElement htmlelement(e);
 @ -551,6 +554,15  @
 	startNewParagraph();
 	//popState();
 	return false; // children are already handled.
+#else
+	pushNewState();
+	state()->in_pre_mode=true;
+	for (DOM::Node q=e.firstChild(); !q.isNull(); q=q.nextSibling()) {
+		parseNode(q); // parse everything...
+	}
+	popState();
+	return false; // children are already handled.
+#endif
 }
 
 bool KHTMLReader::parse_ol(DOM::Element e) {
--- trunk/koffice/filters/kword/html/import/khtmlreader.h #515810:515811
 @ -40,6 +40,7  @
   QDomElement frameset;
   QDomElement paragraph;
   QDomElement layout;
+  bool in_pre_mode; // keep formatting as is.
 };
 
 class KHTMLReader: public QObject {
--- trunk/koffice/filters/kword/html/import/kwdwriter.cpp #515810:515811
 @ -419,16 +419,29  @
 	}
 }
 
-void KWDWriter::addText(QDomElement paragraph, QString text, int format_id) {
+void KWDWriter::addText(QDomElement paragraph, QString text, int format_id, bool keep_formatting) {
 	QDomNode temp=paragraph.elementsByTagName("TEXT").item(0).firstChild();
 	QDomText currentText=temp.toText();
 	if (temp.isNull()) { kdDebug(30503) << "no text" << endl; return; }
-	int oldLength=currentText.data().length();
-	if (oldLength)
-		++oldLength; // add new trailing space char
-	text=text.simplifyWhiteSpace(); // drop all unprintable chars
-	QString newtext=currentText.data() + " " + text;
-	newtext=newtext.simplifyWhiteSpace(); // strip possible new space at beginning.
+	QString oldtext=currentText.data();
+	int oldLength=oldtext.length();
+	if (keep_formatting) {
+		if (oldLength) {
+			++oldLength;
+			oldtext.append('\n');
+		}
+	} else {
+		if (oldLength)
+			++oldLength; // add new trailing space char
+		text=text.simplifyWhiteSpace(); // drop all unprintable chars
+	}
+	QString newtext;
+	if (keep_formatting)
+		newtext=oldtext + text;
+	else {
+		newtext=oldtext + " " + text;
+		newtext=newtext.simplifyWhiteSpace(); // strip possible new space at beginning.
+	}
 	currentText.setData(newtext);
 	int newLength=text.length();
 	QDomElement lastformat=currentFormat(paragraph,true);
--- trunk/koffice/filters/kword/html/import/kwdwriter.h #515810:515811
 @ -150,7 +150,7  @
 	/**
 	 * adds some text to the current format in this paragraph
 	 **/
-	void addText(QDomElement paragraph, QString text, int format_id=1);
+	void addText(QDomElement paragraph, QString text, int format_id=1, bool keep_formatting=false);
 
 	/**
 	 * returns the current format
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic