odt_import_fix.diff (21,020 bytes)
diff --git a/Scribus/scribus/gtaction.cpp b/Scribus/scribus/gtaction.cpp
index 0c17130..61e3781 100644
--- a/Scribus/scribus/gtaction.cpp
+++ b/Scribus/scribus/gtaction.cpp
@@ -37,16 +37,19 @@ for which a new license (GPL+exception) is in place.
#include "color.h"
#include "commonstrings.h"
-#include "prefsmanager.h"
#include "hyphenator.h"
+#include "marks.h"
+#include "notesstyles.h"
+#include "pageitem_textframe.h"
+#include "prefsmanager.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 @@ gtAction::gtAction(bool append, PageItem* pageitem)
updateParagraphStyles = false;
overridePStyleFont = true;
undoManager = UndoManager::instance();
+ noteStory = NULL;
+ note = NULL;
}
void gtAction::setProgressInfo()
@@ -109,10 +114,10 @@ void gtAction::clearFrame()
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 @@ void gtAction::writeUnstyled(const QString& text)
textStr.replace(ch5,ch13);
textStr.replace(QString(0x2028),SpecialChars::LINEBREAK);
textStr.replace(QString(0x2029),SpecialChars::PARSEP);
- int pos = it->itemText.length();
- if (UndoManager::undoEnabled())
+ 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
{
- SimpleState *ss = new SimpleState(Um::AppendText,"",Um::ICreate);
+ 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::writeUnstyled(const QString& text)
}
}
-void gtAction::write(const QString& text, gtStyle *style)
+void gtAction::write(const QString& text, gtStyle *style, bool isNote)
{
if (isFirstWrite)
{
@@ -226,6 +288,18 @@ void gtAction::write(const QString& text, gtStyle *style)
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 @@ void gtAction::write(const QString& text, gtStyle *style)
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);
+ story->applyStyle(pos, paraStyle);
}
}
- it->itemText.applyCharStyle(lastStyleStart, it->itemText.length()-lastStyleStart, lastStyle);
+ 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";
diff --git a/Scribus/scribus/gtaction.h b/Scribus/scribus/gtaction.h
index a8949ee..058b585 100644
--- a/Scribus/scribus/gtaction.h
+++ b/Scribus/scribus/gtaction.h
@@ -41,6 +41,9 @@ class CharStyle;
class ParagraphStyle;
class ScribusDoc;
class ScribusMainWindow;
+class StoryText;
+class TextNote;
+
class UndoManager;
class gtStyle;
@@ -81,6 +84,8 @@ private:
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 @@ public:
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);
diff --git a/Scribus/scribus/gtparagraphstyle.cpp b/Scribus/scribus/gtparagraphstyle.cpp
index f5a2548..a1b8683 100644
--- a/Scribus/scribus/gtparagraphstyle.cpp
+++ b/Scribus/scribus/gtparagraphstyle.cpp
@@ -250,7 +250,10 @@ QString gtParagraphStyle::getBullet()
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;
}
diff --git a/Scribus/scribus/gtparagraphstyle.h b/Scribus/scribus/gtparagraphstyle.h
index 4165fdb..939a0ba 100644
--- a/Scribus/scribus/gtparagraphstyle.h
+++ b/Scribus/scribus/gtparagraphstyle.h
@@ -129,7 +129,7 @@ public:
~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 = "");
diff --git a/Scribus/scribus/gtwriter.cpp b/Scribus/scribus/gtwriter.cpp
index a9ce16b..a7a30a7 100644
--- a/Scribus/scribus/gtwriter.cpp
+++ b/Scribus/scribus/gtwriter.cpp
@@ -52,6 +52,8 @@ gtWriter::gtWriter(bool append, PageItem *pageitem)
setDefaultStyle();
unsetCharacterStyle();
unsetParagraphStyle();
+ inNote = false;
+ inNoteBody = false;
}
gtFrameStyle* gtWriter::getDefaultStyle()
@@ -107,17 +109,19 @@ void gtWriter::append(const QString& text)
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 @@ void gtWriter::appendUnstyled(const QString& text)
return;
if (text.length() == 0)
return;
- action->writeUnstyled(text);
+ if (inNote && !inNoteBody)
+ return;
+ action->writeUnstyled(text, inNote);
}
double gtWriter::getFrameWidth()
@@ -142,6 +148,8 @@ QString gtWriter::getFrameName()
void gtWriter::append(const QString& text, gtStyle *style)
{
+ if (inNote && !inNoteBody)
+ return;
if (style == NULL)
{
append(text);
@@ -149,7 +157,7 @@ void gtWriter::append(const QString& text, gtStyle *style)
}
currentStyle = style;
- action->write(text, style);
+ action->write(text, style, inNote);
currentStyle = NULL;
}
diff --git a/Scribus/scribus/gtwriter.h b/Scribus/scribus/gtwriter.h
index 2259763..16e8fa6 100644
--- a/Scribus/scribus/gtwriter.h
+++ b/Scribus/scribus/gtwriter.h
@@ -60,6 +60,9 @@ public:
void setUpdateParagraphStyles(bool newUPS);
bool getOverridePStyleFont();
void setOverridePStyleFont(bool newOPSF);
+ bool inNote;
+ bool inNoteBody;
+
private:
gtAction *action;
gtFrameStyle* defaultStyle;
diff --git a/Scribus/scribus/plugins/gettext/odtim/contentreader.cpp b/Scribus/scribus/plugins/gettext/odtim/contentreader.cpp
index a6ff041..f6a4533 100644
--- a/Scribus/scribus/plugins/gettext/odtim/contentreader.cpp
+++ b/Scribus/scribus/plugins/gettext/odtim/contentreader.cpp
@@ -47,9 +47,7 @@ ContentReader::ContentReader(QString documentName, StyleReader *s, gtWriter *w,
defaultStyle = NULL;
currentStyle = NULL;
inList = false;
- inNote = false;
inAnnotation = false;
- inNoteBody = false;
inSpan = false;
append = 0;
listIndex = 0;
@@ -116,7 +114,9 @@ bool ContentReader::startElement(const QString&, const QString&, const QString &
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 @@ bool ContentReader::startElement(const QString&, const QString&, const QString &
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 @@ bool ContentReader::endElement(const QString&, const QString&, const QString &na
// 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 @@ bool ContentReader::endElement(const QString&, const QString&, const QString &na
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 @@ bool ContentReader::endElement(const QString&, const QString&, const QString &na
void ContentReader::write(const QString& text)
{
- if (!inNote && !inNoteBody && !inAnnotation) // Disable notes import for now
+ if (!inAnnotation)
{
if (importTextOnly)
writer->appendUnstyled(text);
diff --git a/Scribus/scribus/plugins/gettext/odtim/contentreader.h b/Scribus/scribus/plugins/gettext/odtim/contentreader.h
index 27c74c1..36338ec 100644
--- a/Scribus/scribus/plugins/gettext/odtim/contentreader.h
+++ b/Scribus/scribus/plugins/gettext/odtim/contentreader.h
@@ -62,8 +62,6 @@ private:
bool importTextOnly;
bool inList;
bool inAnnotation;
- bool inNote;
- bool inNoteBody;
bool inSpan;
int append;
int listLevel;
diff --git a/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp b/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp
index d9a0866..175feb4 100644
--- a/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp
+++ b/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp
@@ -134,8 +134,8 @@ StyleReader::StyleReader(QString documentName, gtWriter *w,
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 @@ StyleReader::StyleReader(QString documentName, gtWriter *w,
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 @@ StyleReader::StyleReader(QString documentName, gtWriter *w,
(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 @@ StyleReader::StyleReader(QString documentName, gtWriter *w,
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 @@ QString ListStyle::bullet()
{
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()
diff --git a/Scribus/scribus/util_text.cpp b/Scribus/scribus/util_text.cpp
index 49e31d9..a2348fe 100644
--- a/Scribus/scribus/util_text.cpp
+++ b/Scribus/scribus/util_text.cpp
@@ -16,6 +16,8 @@ for which a new license (GPL+exception) is in place.
//#include <QDebug>
+#include <sstream>
+#include "desaxe/saxXML.h"
#include "scribusdoc.h"
#include "util_text.h"
#include "serializer.h"
@@ -66,3 +68,15 @@ StoryText desaxeString(ScribusDoc* doc, QString saxedString)
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());
+}
+
diff --git a/Scribus/scribus/util_text.h b/Scribus/scribus/util_text.h
index 281a116..ee1989b 100644
--- a/Scribus/scribus/util_text.h
+++ b/Scribus/scribus/util_text.h
@@ -25,4 +25,7 @@ int SCRIBUS_API findParagraphStyle(ScribusDoc* doc, const QString &name);
// 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