1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 
8 /***************************************************************************
9  *                                                                         *
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; either version 2 of the License, or     *
13  *   (at your option) any later version.                                   *
14  *                                                                         *
15  ***************************************************************************/
16 
17 //#include <QDebug>
18 
19 #include <sstream>
20 #include "desaxe/saxXML.h"
21 #include "scribusdoc.h"
22 #include "util_text.h"
23 #include "serializer.h"
24 
findParagraphStyle(ScribusDoc * doc,const ParagraphStyle & parStyle)25 int findParagraphStyle(ScribusDoc* doc, const ParagraphStyle& parStyle)
26 {
27 	bool named = !parStyle.name().isEmpty();
28 	//qDebug() << QString("looking up %1/ %2").arg(parStyle.name()).arg(parStyle.alignment());
29 	if (named)
30 	{
31 		for (int i=0; i < doc->paragraphStyles().count(); ++i)
32 		{
33 			//qDebug() << QString("%1 %2").arg(i).arg(doc->paragraphStyles()[i].name());
34 			if (parStyle.name() == doc->paragraphStyles()[i].name()) {
35 				return i;
36 			}
37 		}
38 		assert(false);
39 	}
40 	return -1;
41 }
42 
findParagraphStyle(ScribusDoc * doc,const QString & name)43 int findParagraphStyle(ScribusDoc* doc, const QString &name)
44 {
45 	for (int i=0; i < doc->paragraphStyles().count(); ++i)
46 	{
47 		if (name == doc->paragraphStyles()[i].name())
48 			return i;
49 	}
50 	assert(false);
51 	return -1;
52 }
53 
localeAwareLessThan(const QString & s1,const QString & s2)54 bool SCRIBUS_API localeAwareLessThan(const QString& s1, const QString& s2)
55 {
56 	int result = QString::localeAwareCompare(s1, s2);
57 	return (result < 0);
58 }
59 
desaxeString(ScribusDoc * doc,const QString & saxedString)60 StoryText desaxeString(ScribusDoc* doc, const QString& saxedString)
61 {
62 	assert(!saxedString.isEmpty());
63 
64 	Serializer* dig = doc->textSerializer();
65 	dig->reset();
66 	dig->store<ScribusDoc>("<scribusdoc>", doc);
67 
68 	dig->parseMemory(saxedString);
69 
70 	StoryText* story = dig->result<StoryText>();
71 	assert (story != nullptr);
72 
73 	StoryText res = *story;
74 	res.setDoc(doc);
75 
76 	delete story;
77 	return res;
78 }
79 
saxedText(StoryText * story)80 QString saxedText(StoryText* story)
81 {
82 	std::ostringstream xmlString;
83 	SaxXML xmlStream(xmlString);
84 	xmlStream.beginDoc();
85 	story->saxx(xmlStream, "SCRIBUSTEXT");
86 	xmlStream.endDoc();
87 	std::string xml(xmlString.str());
88 	return QString(xml.c_str());
89 }
90 
91