From f6bdbd5e218d4346ffe07700bea48c1f0112095d Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 8 Dec 2013 13:52:47 +0000 Subject: [PATCH] removed HandleRichText.cpp from last commit git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6931 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/util/HandleRichText.cpp | 61 +++------------------- 1 file changed, 6 insertions(+), 55 deletions(-) diff --git a/retroshare-gui/src/util/HandleRichText.cpp b/retroshare-gui/src/util/HandleRichText.cpp index f246dfdfb..f9ac089b6 100644 --- a/retroshare-gui/src/util/HandleRichText.cpp +++ b/retroshare-gui/src/util/HandleRichText.cpp @@ -333,37 +333,6 @@ void RsHtml::embedHtml(QTextDocument *textDocument, QDomDocument& doc, QDomEleme } } -/** - * Save space and tab out of bracket that XML loose. - * - * @param[in] text The text to save space. - * @return Text with space saved. - */ -static QString saveSpace(const QString text) -{ - QString savedSpaceText=text; - bool outBrackets=false, echapChar=false; - - for(int i=0;i')) { - if(!echapChar && i>0) outBrackets=true; - } else if(cursChar==QLatin1Char('\t')) { - if(outBrackets) savedSpaceText.replace(i, 1, "  "); - } else if(cursChar==QLatin1Char(' ')) { - if(outBrackets) savedSpaceText.replace(i, 1, " "); - } else if(cursChar==QLatin1Char('<')) { - if(!echapChar) outBrackets=false; - } - - echapChar=(cursChar==QLatin1Char('\\')); - - } - - return savedSpaceText; -} - QString RsHtml::formatText(QTextDocument *textDocument, const QString &text, ulong flag, const QColor &backgroundColor, qreal desiredContrast) { if (flag == 0 || text.isEmpty()) { @@ -371,24 +340,12 @@ QString RsHtml::formatText(QTextDocument *textDocument, const QString &text, ulo return text; } - QString formattedText=text; - //remove all prepend char that make doc.setContent() fail - formattedText.remove(0,text.indexOf("<")); - // Save Space and Tab because doc loose it. - formattedText=saveSpace(formattedText); - - QString errorMsg; int errorLine; int errorColumn; - QDomDocument doc; - if (doc.setContent(formattedText, &errorMsg, &errorLine, &errorColumn) == false) { - + if (doc.setContent(text) == false) { // convert text with QTextBrowser QTextBrowser textBrowser; textBrowser.setText(text); - formattedText=textBrowser.toHtml(); - formattedText.remove(0,formattedText.indexOf("<")); - formattedText=saveSpace(formattedText); - doc.setContent(formattedText, &errorMsg, &errorLine, &errorColumn); + doc.setContent(textBrowser.toHtml()); } QDomElement body = doc.documentElement(); @@ -400,7 +357,7 @@ QString RsHtml::formatText(QTextDocument *textDocument, const QString &text, ulo embedHtml(textDocument, doc, body, defEmbedAhref, flag); } - formattedText = doc.toString(-1); // -1 removes any annoying carriage return misinterpreted by QTextEdit + QString formattedText = doc.toString(-1); // -1 removes any annoying carriage return misinterpreted by QTextEdit if (flag & RSHTML_OPTIMIZEHTML_MASK) { optimizeHtml(formattedText, flag & RSHTML_OPTIMIZEHTML_MASK, backgroundColor, desiredContrast); @@ -439,13 +396,12 @@ static void findElements(QDomDocument& doc, QDomElement& currentElement, const Q bool RsHtml::findAnchors(const QString &text, QStringList& urls) { - QString errorMsg; int errorLine; int errorColumn; QDomDocument doc; - if (doc.setContent(text, &errorMsg, &errorLine, &errorColumn) == false) { + if (doc.setContent(text) == false) { // convert text with QTextBrowser QTextBrowser textBrowser; textBrowser.setText(text); - doc.setContent(textBrowser.toHtml(), &errorMsg, &errorLine, &errorColumn); + doc.setContent(textBrowser.toHtml()); } QDomElement body = doc.documentElement(); @@ -752,14 +708,9 @@ void RsHtml::optimizeHtml(QString &text, unsigned int flag, const QColor &backgr // remove doctype text.remove(QRegExp("]*>")); - //remove all prepend char that make doc.setContent() fail - text.remove(0,text.indexOf("<")); - // Save Space and Tab because doc loose it. - text=saveSpace(text); - QString errorMsg; int errorLine; int errorColumn; QDomDocument doc; - if (doc.setContent(text, &errorMsg, &errorLine, &errorColumn) == false) { + if (doc.setContent(text) == false) { return; }