From 276f258e5dfbe286db4cc4b48c6bc82d6b96a0d0 Mon Sep 17 00:00:00 2001 From: jghali Date: Tue, 3 Jul 2012 21:45:33 +0000 Subject: #9110: Non-breakable spaces export as underscores git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17673 11d20701-8431-0410-a711-e3c959e3b870 --- scribus/storyeditor.cpp | 2 +- scribus/text/storytext.cpp | 22 ++++++++++++++++++++++ scribus/text/storytext.h | 8 ++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/scribus/storyeditor.cpp b/scribus/storyeditor.cpp index ce9398e..76cb972 100644 --- a/scribus/storyeditor.cpp +++ b/scribus/storyeditor.cpp @@ -3289,7 +3289,7 @@ void StoryEditor::SaveTextFile() if (!fileName.isEmpty()) { dirs->set("story_save", fileName.left(fileName.lastIndexOf("/"))); - Serializer::writeWithEncoding(fileName, LoadEnc, Editor->toPlainText()); + Serializer::writeWithEncoding(fileName, LoadEnc, Editor->StyledText.plainText()); } blockUpdate = false; } diff --git a/scribus/text/storytext.cpp b/scribus/text/storytext.cpp index 76285a9..062015a 100644 --- a/scribus/text/storytext.cpp +++ b/scribus/text/storytext.cpp @@ -637,6 +637,28 @@ int StoryText::length() const return d->len; } +QString StoryText::plainText() const +{ + if (length() <= 0) + return QString(); + + QChar ch; + QString result; + + uint len = length(); + result.reserve(len); + + StoryText* that(const_cast(this)); + for (int i = 0; i < len; ++i) { + ch = that->d->at(i)->ch; + if (ch == SpecialChars::PARSEP) + ch = QLatin1Char('\n'); + result += ch; + } + + return result; +} + QChar StoryText::text() const { return text(d->cursorPosition); diff --git a/scribus/text/storytext.h b/scribus/text/storytext.h index 420c3c7..b77779b 100644 --- a/scribus/text/storytext.h +++ b/scribus/text/storytext.h @@ -137,7 +137,15 @@ class SCRIBUS_API StoryText : public QObject, public SaxIO void hyphenateWord(int pos, uint len, char* hyphens); + // Retrieve length of story text int length() const; + + // Get content at specific position as plain text + // Internal paragraph separator are converted to + // unix new lines for better compatibility with + // text editors + QString plainText() const; + // Get char at current cursor position QChar text() const; // Get char at specific position -- cgit