r18084 by jghali - #11358: import of lists and notes from ODT file

scribus-commit scribus-commit at lists.scribus.net
Fri Jan 11 23:39:52 UTC 2013


Author: jghali
Date: Fri Jan 11 23:39:52 2013
New Revision: 18084

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=18084
Log:
#11358: import of lists and notes from ODT file

Modified:
    trunk/Scribus/scribus/gtaction.cpp
    trunk/Scribus/scribus/gtaction.h
    trunk/Scribus/scribus/gtparagraphstyle.cpp
    trunk/Scribus/scribus/gtparagraphstyle.h
    trunk/Scribus/scribus/gtwriter.cpp
    trunk/Scribus/scribus/gtwriter.h
    trunk/Scribus/scribus/plugins/gettext/odtim/contentreader.cpp
    trunk/Scribus/scribus/plugins/gettext/odtim/contentreader.h
    trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp
    trunk/Scribus/scribus/util_text.cpp
    trunk/Scribus/scribus/util_text.h

Modified: trunk/Scribus/scribus/gtaction.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18084&path=/trunk/Scribus/scribus/gtaction.cpp
==============================================================================
--- trunk/Scribus/scribus/gtaction.cpp (original)
+++ trunk/Scribus/scribus/gtaction.cpp Fri Jan 11 23:39:52 2013
@@ -37,16 +37,19 @@
 
 #include "color.h"
 #include "commonstrings.h"
+#include "hyphenator.h"
+#include "marks.h"
+#include "notesstyles.h"
+#include "pageitem_textframe.h"
 #include "prefsmanager.h"
-#include "hyphenator.h"
 #include "scclocale.h"
 #include "selection.h"
 #include "sccolorengine.h"
 #include "scribus.h"
 #include "undomanager.h"
-#include "pageitem_textframe.h"
 
 #include "util_icon.h"
+#include "util_text.h"
 #include "ui/propertiespalette.h"
 #include "ui/propertiespalette_text.h"
 #include "ui/missing.h"
@@ -83,6 +86,8 @@
 	updateParagraphStyles = false;
 	overridePStyleFont = true;
 	undoManager = UndoManager::instance();
+	noteStory = NULL;
+	note = NULL;
 }
 
 void gtAction::setProgressInfo()
@@ -109,10 +114,10 @@
 	textFrame->itemText.clear();
 }
 
-void gtAction::writeUnstyled(const QString& text)
+void gtAction::writeUnstyled(const QString& text, bool isNote)
 {
 	UndoTransaction* activeTransaction = NULL;
-	if (isFirstWrite)
+	if (isFirstWrite && it->itemText.length() > 0)
 	{
 		if (!doAppend)
 		{
@@ -141,16 +146,73 @@
 	textStr.replace(ch5,ch13);
 	textStr.replace(QString(0x2028),SpecialChars::LINEBREAK);
 	textStr.replace(QString(0x2029),SpecialChars::PARSEP);
-	int pos = it->itemText.length();
-	if (UndoManager::undoEnabled())
-	{
-		SimpleState *ss = new SimpleState(Um::AppendText,"",Um::ICreate);
+	if (isNote)
+	{
+		if (note == NULL)
+		{
+			note = it->m_Doc->newNote(it->m_Doc->m_docNotesStylesList.at(0));
+			Q_ASSERT(noteStory == NULL);
+			noteStory = new StoryText(it->m_Doc);
+		}
+		if (textStr == SpecialChars::OBJECT)
+		{
+			NotesStyle* nStyle = note->notesStyle();
+			QString label = "NoteMark_" + nStyle->name();
+			if (nStyle->range() == NSRsection)
+				label += " in section " + it->m_Doc->getSectionNameForPageIndex(it->OwnPage) + " page " + QString::number(it->OwnPage +1);
+			else if (nStyle->range() == NSRpage)
+				label += " on page " + QString::number(it->OwnPage +1);
+			else if (nStyle->range() == NSRstory)
+				label += " in " + it->firstInChain()->itemName();
+			else if (nStyle->range() == NSRframe)
+				label += " in frame" + it->itemName();
+			if (it->m_Doc->getMarkDefinied(label + "_1", MARKNoteMasterType) != NULL)
+				getUniqueName(label,it->m_Doc->marksLabelsList(MARKNoteMasterType), "_"); //FIX ME here user should be warned that inserted mark`s label was changed
+			else
+				label = label + "_1";
+			Mark* mrk = it->m_Doc->newMark();
+			mrk->label = label;
+			mrk->setType(MARKNoteMasterType);
+			mrk->setNotePtr(note);
+			note->setMasterMark(mrk);
+			if (noteStory->text(noteStory->length() -1) == SpecialChars::PARSEP)
+				noteStory->removeChars(noteStory->length() -1, 1);
+			note->setSaxedText(saxedText(noteStory));
+			mrk->setString("");
+			mrk->OwnPage = it->OwnPage;
+			it->itemText.insertMark(mrk);
+			if (UndoManager::undoEnabled())
+			{
+				ScItemsState* is = new ScItemsState(UndoManager::InsertNote);
+				is->set("ETEA", mrk->label);
+				is->set("MARK", QString("new"));
+				is->set("label", mrk->label);
+				is->set("type", (int) MARKNoteMasterType);
+				is->set("strtxt", QString(""));
+				is->set("nStyle", nStyle->name());
+				is->set("at", it->itemText.cursorPosition() -1);
+				is->insertItem("inItem", it);
+				undoManager->action(it->m_Doc, is);
+			}
+			note = NULL;
+			delete noteStory;
+		}
+		else
+			noteStory->insertChars(noteStory->length(), textStr);
+	}
+	else
+	{
+		int pos = it->itemText.length();
+		if (UndoManager::undoEnabled())
+		{
+			SimpleState *ss = new SimpleState(Um::AppendText,"",Um::ICreate);
 			ss->set("INSERT_FRAMETEXT", "insert_frametext");
 			ss->set("TEXT_STR",textStr);
 			ss->set("START", pos);
 			undoManager->action(it, ss);
-	}
-	it->itemText.insertChars(pos, textStr);
+		}
+		it->itemText.insertChars(pos, textStr);
+	}
 	lastCharWasLineChange = text.right(1) == "\n";
 	isFirstWrite = false;
 	if (activeTransaction)
@@ -161,7 +223,7 @@
 	}
 }
 
-void gtAction::write(const QString& text, gtStyle *style)
+void gtAction::write(const QString& text, gtStyle *style, bool isNote)
 {
 	if (isFirstWrite)
 	{
@@ -226,6 +288,18 @@
 
 	lastStyle = newStyle;
 	lastStyleStart = it->itemText.length();
+	StoryText* story = NULL;
+	if (isNote)
+	{
+		if (noteStory == NULL)
+		{
+			note = it->m_Doc->newNote(it->m_Doc->m_docNotesStylesList.at(0));
+			noteStory = new StoryText(it->m_Doc);
+		}
+		story = noteStory;
+	}
+	else
+		story = &it->itemText;
 
 	QChar ch0(0), ch5(5), ch10(10), ch13(13); 
 	for (int a = 0; a < text.length(); ++a)
@@ -236,29 +310,77 @@
 		if ((ch == ch10) || (ch == ch5))
 			ch = ch13;
 		
-		int pos = it->itemText.length();
-		it->itemText.insertChars(pos, QString(ch));
+		int pos = story->length();
+		if (isNote && ch == SpecialChars::OBJECT)
+		{
+			NotesStyle* nStyle = note->notesStyle();
+			QString label = "NoteMark_" + nStyle->name();
+			if (nStyle->range() == NSRsection)
+				label += " in section " + it->m_Doc->getSectionNameForPageIndex(it->OwnPage) + " page " + QString::number(it->OwnPage +1);
+			else if (nStyle->range() == NSRpage)
+				label += " on page " + QString::number(it->OwnPage +1);
+			else if (nStyle->range() == NSRstory)
+				label += " in " + it->firstInChain()->itemName();
+			else if (nStyle->range() == NSRframe)
+				label += " in frame" + it->itemName();
+			if (it->m_Doc->getMarkDefinied(label + "_1", MARKNoteMasterType) != NULL)
+				getUniqueName(label,it->m_Doc->marksLabelsList(MARKNoteMasterType), "_"); //FIX ME here user should be warned that inserted mark`s label was changed
+			else
+				label = label + "_1";
+			Mark* mrk = it->m_Doc->newMark();
+			mrk->label = label;
+			mrk->setType(MARKNoteMasterType);
+			mrk->setNotePtr(note);
+			note->setMasterMark(mrk);
+			mrk->setString("");
+			mrk->OwnPage = it->OwnPage;
+			it->itemText.insertMark(mrk);
+			story->applyCharStyle(lastStyleStart, story->length()-lastStyleStart, lastStyle);
+			if (paraStyle.hasName())
+			{
+				ParagraphStyle pStyle;
+				pStyle.setParent(paraStyle.name());
+				story->applyStyle(qMax(0,story->length()-1), pStyle);
+			}
+			else
+				story->applyStyle(qMax(0,story->length()-1), paraStyle);
+			
+			lastCharWasLineChange = text.right(1) == "\n";
+			inPara = style->target() == "paragraph";
+			lastParagraphStyle = paragraphStyle;
+			if (isFirstWrite)
+				isFirstWrite = false;
+			if (story->text(pos -1) == SpecialChars::PARSEP)
+				story->removeChars(pos-1, 1);
+			note->setSaxedText(saxedText(story));
+			note = NULL;
+			delete noteStory;
+			noteStory = NULL;
+			return;
+		}
+		else
+			story->insertChars(pos, QString(ch));
 		if (ch == SpecialChars::PARSEP) 
 		{
 			if (paraStyle.hasName())
 			{
 				ParagraphStyle pstyle;
 				pstyle.setParent(paraStyle.name());
-				it->itemText.applyStyle(pos, pstyle);
+				story->applyStyle(pos, pstyle);
 			}
 			else
-				it->itemText.applyStyle(pos, paraStyle);
-		}
-	}
-	it->itemText.applyCharStyle(lastStyleStart, it->itemText.length()-lastStyleStart, lastStyle);
+				story->applyStyle(pos, paraStyle);
+		}
+	}
+	story->applyCharStyle(lastStyleStart, story->length()-lastStyleStart, lastStyle);
 	if (paraStyle.hasName())
 	{
 		ParagraphStyle pStyle;
 		pStyle.setParent(paraStyle.name());
-		it->itemText.applyStyle(qMax(0,it->itemText.length()-1), pStyle);
+		story->applyStyle(qMax(0,story->length()-1), pStyle);
 	}
 	else
-		it->itemText.applyStyle(qMax(0,it->itemText.length()-1), paraStyle);
+		story->applyStyle(qMax(0,story->length()-1), paraStyle);
 	
 	lastCharWasLineChange = text.right(1) == "\n";
 	inPara = style->target() == "paragraph";

Modified: trunk/Scribus/scribus/gtaction.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18084&path=/trunk/Scribus/scribus/gtaction.h
==============================================================================
--- trunk/Scribus/scribus/gtaction.h (original)
+++ trunk/Scribus/scribus/gtaction.h Fri Jan 11 23:39:52 2013
@@ -41,6 +41,9 @@
 class ParagraphStyle;
 class ScribusDoc;
 class ScribusMainWindow;
+class StoryText;
+class TextNote;
+
 class UndoManager;
 
 class gtStyle;
@@ -81,6 +84,8 @@
 	QColor  parseColorN(const QString &rgbColor);
 	void finalize();
 	PrefsManager *prefsManager;
+	StoryText* noteStory;
+	TextNote* note;
 public:
 //	gtAction(bool append);
 	gtAction(bool append, PageItem *pageitem);
@@ -93,8 +98,8 @@
 	void clearFrame();
 	void getFrameFont(gtFont *font);
 	void getFrameStyle(gtFrameStyle *fstyle);
-	void write(const QString& text, gtStyle *style);
-	void writeUnstyled(const QString& text);
+	void write(const QString& text, gtStyle *style, bool isNote);
+	void writeUnstyled(const QString& text, bool isNote);
 	void applyFrameStyle(gtFrameStyle* fstyle);
 	void createParagraphStyle(gtParagraphStyle* pstyle);
 	void setCharStyleAttributes(gtFont *font, CharStyle& style);

Modified: trunk/Scribus/scribus/gtparagraphstyle.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18084&path=/trunk/Scribus/scribus/gtparagraphstyle.cpp
==============================================================================
--- trunk/Scribus/scribus/gtparagraphstyle.cpp (original)
+++ trunk/Scribus/scribus/gtparagraphstyle.cpp Fri Jan 11 23:39:52 2013
@@ -250,7 +250,10 @@
 void gtParagraphStyle::setBullet(bool newBullet, QString str)
 {
 	m_bullet = newBullet;
-	m_bulletStr = str;
+	if (str != "")
+		m_bulletStr = str;
+	else
+		m_bulletStr = QString(QChar(0x2022));
 	flags |= bulletWasSet;
 }
 

Modified: trunk/Scribus/scribus/gtparagraphstyle.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18084&path=/trunk/Scribus/scribus/gtparagraphstyle.h
==============================================================================
--- trunk/Scribus/scribus/gtparagraphstyle.h (original)
+++ trunk/Scribus/scribus/gtparagraphstyle.h Fri Jan 11 23:39:52 2013
@@ -129,7 +129,7 @@
 	~gtParagraphStyle();
 	QString target();
 	bool hasBullet();
-	void setBullet(bool newBullet, QString str = QString(QChar(0x2022)));
+	void setBullet(bool newBullet, QString str);
 	QString getBullet();
 	bool hasNum();
 	void setNum(bool newNum, int format=0, int level=0, int start = 1, QString prefix = "", QString suffix = "");

Modified: trunk/Scribus/scribus/gtwriter.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18084&path=/trunk/Scribus/scribus/gtwriter.cpp
==============================================================================
--- trunk/Scribus/scribus/gtwriter.cpp (original)
+++ trunk/Scribus/scribus/gtwriter.cpp Fri Jan 11 23:39:52 2013
@@ -52,6 +52,8 @@
 	setDefaultStyle();
 	unsetCharacterStyle();
 	unsetParagraphStyle();
+	inNote = false;
+	inNoteBody = false;
 }
 
 gtFrameStyle* gtWriter::getDefaultStyle()
@@ -107,17 +109,19 @@
 		return;
 	if (text.length() == 0)
 		return;
+	if (inNote && !inNoteBody)
+		return;
 	if (characterStyle != NULL)
 	{
-		action->write(text, characterStyle);
+		action->write(text, characterStyle, inNote);
 	}
 	else if (paragraphStyle != NULL)
 	{
-		action->write(text, paragraphStyle);
+		action->write(text, paragraphStyle, inNote);
 	}
 	else
 	{
-		action->write(text, frameStyle);
+		action->write(text, frameStyle, inNote);
 	}
 }
 
@@ -127,7 +131,9 @@
 		return;
 	if (text.length() == 0)
 		return;
-	action->writeUnstyled(text);
+	if (inNote && !inNoteBody)
+		return;
+	action->writeUnstyled(text, inNote);
 }
 
 double gtWriter::getFrameWidth()
@@ -142,6 +148,8 @@
 
 void gtWriter::append(const QString& text, gtStyle *style)
 {
+	if (inNote && !inNoteBody)
+		return;
 	if (style == NULL)
 	{
 		append(text);
@@ -149,7 +157,7 @@
 	}
 
 	currentStyle = style;
-	action->write(text, style);
+	action->write(text, style, inNote);
 	currentStyle = NULL;
 }
 

Modified: trunk/Scribus/scribus/gtwriter.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18084&path=/trunk/Scribus/scribus/gtwriter.h
==============================================================================
--- trunk/Scribus/scribus/gtwriter.h (original)
+++ trunk/Scribus/scribus/gtwriter.h Fri Jan 11 23:39:52 2013
@@ -60,6 +60,9 @@
 	void setUpdateParagraphStyles(bool newUPS);
 	bool getOverridePStyleFont();
 	void setOverridePStyleFont(bool newOPSF);
+	bool inNote;
+	bool inNoteBody;
+
 private:
 	gtAction *action;
 	gtFrameStyle* defaultStyle;

Modified: trunk/Scribus/scribus/plugins/gettext/odtim/contentreader.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18084&path=/trunk/Scribus/scribus/plugins/gettext/odtim/contentreader.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/odtim/contentreader.cpp (original)
+++ trunk/Scribus/scribus/plugins/gettext/odtim/contentreader.cpp Fri Jan 11 23:39:52 2013
@@ -47,9 +47,7 @@
 	defaultStyle = NULL;
 	currentStyle = NULL;
 	inList = false;
-	inNote = false;
 	inAnnotation = false;
-	inNoteBody = false;
 	inSpan = false;
 	append = 0;
 	listIndex = 0;
@@ -116,7 +114,9 @@
 		for (int i = 0; i < attrs.count(); ++i)
 		{
 			if (attrs.localName(i) == "text:style-name")
+			{
 				currentList = attrs.value(i);
+			}
 		}
 		currentStyle = sreader->getStyle(QString(currentList + "_%1").arg(listLevel));
 		currentListStyle = sreader->getList(currentList);
@@ -136,9 +136,9 @@
 	else if (name == "office:annotation")
 		inAnnotation = true;
 	else if (name == "text:note")
-		inNote = true;
+		writer->inNote = true;
 	else if (name == "text:note-body")
-		inNoteBody = true;
+		writer->inNoteBody = true;
 	else if (name == "style:style")
 	{
 		QString sname = "";
@@ -206,7 +206,7 @@
 // 		qDebug("TPTH");
 		write("\n");
 		--append;
-		if (inList || inAnnotation || inNote || inNoteBody)
+		if (inList || inAnnotation)
 		{
 			if(static_cast<int>(styleNames.size()) > 0)
 				styleNames.pop_back();
@@ -230,12 +230,13 @@
 	else if (name == "text:note")
 	{
 // 		qDebug("TN");
-		inNote = false;
+		writer->inNote = false;
 	}
 	else if (name == "text:note-body")
 	{
 // 		qDebug("TNB");
-		inNoteBody = false;
+		write(SpecialChars::OBJECT);
+		writer->inNoteBody = false;
 	}
 	else if (name == "text:line-break")
 	{
@@ -280,7 +281,7 @@
 
 void ContentReader::write(const QString& text)
 {
-	if (!inNote && !inNoteBody && !inAnnotation) // Disable notes import for now
+	if (!inAnnotation)
 	{
 		if (importTextOnly)
 			writer->appendUnstyled(text);

Modified: trunk/Scribus/scribus/plugins/gettext/odtim/contentreader.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18084&path=/trunk/Scribus/scribus/plugins/gettext/odtim/contentreader.h
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/odtim/contentreader.h (original)
+++ trunk/Scribus/scribus/plugins/gettext/odtim/contentreader.h Fri Jan 11 23:39:52 2013
@@ -62,8 +62,6 @@
 	bool importTextOnly;
 	bool inList;
 	bool inAnnotation;
-	bool inNote;
-	bool inNoteBody;
 	bool inSpan;
 	int  append;
 	int  listLevel;

Modified: trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18084&path=/trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp (original)
+++ trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp Fri Jan 11 23:39:52 2013
@@ -134,8 +134,8 @@
 				prefix = attrs.value(i);
 			else if (attrs.localName(i) == "style:num-suffix")
 				suffix = attrs.value(i);
-			/*else if (attrs.localName(i) == "text:bullet-char")
-				bullet = attrs.value(i);*/
+			else if (attrs.localName(i) == "text:bullet-char")
+				bullet = attrs.value(i);
 			else if (attrs.localName(i) == "style:num-format") {
 				QString tmp = attrs.value(i);
 				if (tmp == "i")
@@ -171,11 +171,13 @@
 		gtParagraphStyle* s = dynamic_cast<gtParagraphStyle*>(currentStyle);
 		assert(s != NULL);
 		if (bstyle == Bullet || bstyle == Graphic)
-			s->setBullet(true);
+		{
+			s->setBullet(true, bullet);
+		}
 		else
 		{
 			Q_ASSERT(((int) bstyle > 0) && ((int) bstyle < 6));
-			s->setNum(true, (int) bstyle -1, 0, startAt+1, prefix, suffix);
+			s->setNum(true, (int) bstyle -1, ulevel, startAt+1, prefix, suffix);
 		}
  	}
  	else if ((name == "style:drop-cap") && (readProperties))
@@ -508,18 +510,18 @@
  			  (name == "text:list-level-style-number") ||
 			  (name == "text:list-level-style-image")) && (currentStyle != NULL))
  	{
-//		if ((name == "text:list-level-style-bullet"))
-//		{
-//			gtParagraphStyle* s = dynamic_cast<gtParagraphStyle*>(currentStyle);
-//			if (s)
-//				s->setBullet(true);
-//		}
-//		else if ((name == "text:list-level-style-number"))
-//		{
-//			gtParagraphStyle* s = dynamic_cast<gtParagraphStyle*>(currentStyle);
-//			if (s)
-//				s->setNum(true);
-//		}
+		if ((name == "text:list-level-style-bullet"))
+		{
+			gtParagraphStyle* s = dynamic_cast<gtParagraphStyle*>(currentStyle);
+			if (s)
+				s->setBullet(true, "");
+		}
+		else if ((name == "text:list-level-style-number"))
+		{
+			gtParagraphStyle* s = dynamic_cast<gtParagraphStyle*>(currentStyle);
+			if (s)
+				s->setNum(true);
+		}
  		setStyle(currentStyle->getName(), currentStyle);
  		currentStyle = NULL;
  		parentStyle = NULL;
@@ -595,6 +597,13 @@
  		nameByAttrs += QString("%1-").arg(s->getAlignment());
  		nameByAttrs += QString("%1-").arg(s->hasDropCap());
 		nameByAttrs += QString("%1-").arg(s->hasBullet());
+		nameByAttrs += QString("%1-").arg(s->getBullet());
+		nameByAttrs += QString("%1-").arg(s->hasNum());
+		nameByAttrs += QString("%1-").arg(s->getNumFormat());
+		nameByAttrs += QString("%1-").arg(s->getNumLevel());
+		nameByAttrs += QString("%1-").arg(s->getNumPrefix());
+		nameByAttrs += QString("%1-").arg(s->getNumStart());
+		nameByAttrs += QString("%1-").arg(s->getNumSuffix());
  		nameByAttrs += QString("%1-").arg(s->getFont()->getColor());
  		nameByAttrs += QString("%1-").arg(s->getFont()->getStrokeColor());
 // TODO is this important ??
@@ -1072,23 +1081,23 @@
 {
 	uint displayLevels = levels[m_currentLevel]->displayLevels();
 	if (displayLevels == 1)
-		return QString(levels[m_currentLevel]->bullet() + " ");
+		return QString(levels[m_currentLevel]->bullet());
 
 	QString prefix = levels[m_currentLevel]->prefix();
 	QString suffix = levels[m_currentLevel]->suffix();
 	QString bullet = "";
 	int start = m_currentLevel - displayLevels + 1;
 	if (start < 1)
-		return QString(levels[m_currentLevel]->bullet() + " ");
+		return QString(levels[m_currentLevel]->bullet());
 	while (static_cast<uint>(start) <= m_currentLevel)
 	{
 		if (static_cast<uint>(start) == m_currentLevel)
 			bullet += levels[start]->bulletString();
 		else
-			bullet += levels[start]->bulletString() + ".";
+			bullet += levels[start]->bulletString();
 		++start;
 	}
-	return QString(prefix + bullet + suffix + " ");
+	return QString(prefix + bullet + suffix);
 }
 
 void ListStyle::advance()

Modified: trunk/Scribus/scribus/util_text.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18084&path=/trunk/Scribus/scribus/util_text.cpp
==============================================================================
--- trunk/Scribus/scribus/util_text.cpp (original)
+++ trunk/Scribus/scribus/util_text.cpp Fri Jan 11 23:39:52 2013
@@ -1,68 +1,82 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-//#include <QDebug>
-
-#include "scribusdoc.h"
-#include "util_text.h"
-#include "serializer.h"
-
-int findParagraphStyle(ScribusDoc* doc, const ParagraphStyle& parStyle)
-{
-	bool named = !parStyle.name().isEmpty();
-	//qDebug() << QString("looking up %1/ %2").arg(parStyle.name()).arg(parStyle.alignment()); 
-	if (named) {
-		for (int i=0; i < doc->paragraphStyles().count(); ++i)
-		{
-			//qDebug() << QString("%1 %2").arg(i).arg(doc->paragraphStyles()[i].name());
-			if (parStyle.name() == doc->paragraphStyles()[i].name()) {
-				return i;
-			}
-		}
-		assert(false);
-		return -1;
-	}
-	else {
-		return -1;
-	}
-}
-
-int findParagraphStyle(ScribusDoc* doc, const QString &name)
-{
-	for (int i=0; i < doc->paragraphStyles().count(); ++i)
-	{
-		if (name == doc->paragraphStyles()[i].name()) {
-			return i;
-		}
-	}
-	assert(false);
-	return -1;
-}
-
-StoryText desaxeString(ScribusDoc* doc, QString saxedString)
-{
-	assert(!saxedString.isEmpty());
-
-	Serializer* dig = doc->textSerializer();
-	dig->parseMemory(saxedString.toStdString().c_str(), saxedString.length());
-
-	StoryText* story = dig->result<StoryText>();
-	assert (story != NULL);
-
-	StoryText res = *story;
-	delete story;
-	return res;
-}
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+//#include <QDebug>
+
+#include <sstream>
+#include "desaxe/saxXML.h"
+#include "scribusdoc.h"
+#include "util_text.h"
+#include "serializer.h"
+
+int findParagraphStyle(ScribusDoc* doc, const ParagraphStyle& parStyle)
+{
+	bool named = !parStyle.name().isEmpty();
+	//qDebug() << QString("looking up %1/ %2").arg(parStyle.name()).arg(parStyle.alignment()); 
+	if (named) {
+		for (int i=0; i < doc->paragraphStyles().count(); ++i)
+		{
+			//qDebug() << QString("%1 %2").arg(i).arg(doc->paragraphStyles()[i].name());
+			if (parStyle.name() == doc->paragraphStyles()[i].name()) {
+				return i;
+			}
+		}
+		assert(false);
+		return -1;
+	}
+	else {
+		return -1;
+	}
+}
+
+int findParagraphStyle(ScribusDoc* doc, const QString &name)
+{
+	for (int i=0; i < doc->paragraphStyles().count(); ++i)
+	{
+		if (name == doc->paragraphStyles()[i].name()) {
+			return i;
+		}
+	}
+	assert(false);
+	return -1;
+}
+
+StoryText desaxeString(ScribusDoc* doc, QString saxedString)
+{
+	assert(!saxedString.isEmpty());
+
+	Serializer* dig = doc->textSerializer();
+	dig->parseMemory(saxedString.toStdString().c_str(), saxedString.length());
+
+	StoryText* story = dig->result<StoryText>();
+	assert (story != NULL);
+
+	StoryText res = *story;
+	delete story;
+	return res;
+}
+
+QString saxedText(StoryText* story)
+{
+	std::ostringstream xmlString;
+	SaxXML xmlStream(xmlString);
+	xmlStream.beginDoc();
+	story->saxx(xmlStream, "SCRIBUSTEXT");
+	xmlStream.endDoc();
+	std::string xml(xmlString.str());
+	return QString(xml.c_str());
+}
+

Modified: trunk/Scribus/scribus/util_text.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18084&path=/trunk/Scribus/scribus/util_text.h
==============================================================================
--- trunk/Scribus/scribus/util_text.h (original)
+++ trunk/Scribus/scribus/util_text.h Fri Jan 11 23:39:52 2013
@@ -1,28 +1,31 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-#ifndef _UTIL_TEXT_H
-#define _UTIL_TEXT_H
-
-#include <QString>
-
-#include "style.h"
-#include "styles/charstyle.h"
-#include "styles/paragraphstyle.h"
-#include "scribusapi.h"
-#include "text/storytext.h"
-
-class  ScribusDoc;
-
-#ifndef NLS_CONFORMANCE
-int SCRIBUS_API findParagraphStyle(ScribusDoc* doc, const ParagraphStyle& parStyle);
-int SCRIBUS_API findParagraphStyle(ScribusDoc* doc, const QString &name);
-#endif
-
-// returns StoryText from saxed string
-StoryText SCRIBUS_API desaxeString(ScribusDoc* doc, QString saxedString);
-
-#endif
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+#ifndef _UTIL_TEXT_H
+#define _UTIL_TEXT_H
+
+#include <QString>
+
+#include "style.h"
+#include "styles/charstyle.h"
+#include "styles/paragraphstyle.h"
+#include "scribusapi.h"
+#include "text/storytext.h"
+
+class  ScribusDoc;
+
+#ifndef NLS_CONFORMANCE
+int SCRIBUS_API findParagraphStyle(ScribusDoc* doc, const ParagraphStyle& parStyle);
+int SCRIBUS_API findParagraphStyle(ScribusDoc* doc, const QString &name);
+#endif
+
+// returns StoryText from saxed string
+StoryText SCRIBUS_API desaxeString(ScribusDoc* doc, QString saxedString);
+
+//returns string with saxed story
+QString SCRIBUS_API saxedText(StoryText* story);
+
+#endif




More information about the scribus-commit mailing list