Subversion Repositories Scribus

Rev

Rev 22631 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14472 fschmid 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
  *   Copyright (C) 2009 by Andreas Vox                                     *
9
  *   avox@scribus.info                                                     *
10
  *                                                                         *
11
  *   This program is free software; you can redistribute it and/or modify  *
12
  *   it under the terms of the GNU General Public License as published by  *
13
  *   the Free Software Foundation; either version 2 of the License, or     *
14
  *   (at your option) any later version.                                   *
15
  *                                                                         *
16
  *   This program is distributed in the hope that it will be useful,       *
17
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
18
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
19
  *   GNU General Public License for more details.                          *
20
  *                                                                         *
21
  *   You should have received a copy of the GNU General Public License     *
22
  *   along with this program; if not, write to the                         *
23
  *   Free Software Foundation, Inc.,                                       *
18122 mrdocs 24
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
14472 fschmid 25
  ***************************************************************************/
26
 
27
#include "pageitem.h"
28
#include "scribusdoc.h"
29
#include "text/storytext.h"
25158 craig 30
#include "textwriter.h"
14472 fschmid 31
 
32
TextWriter::TextWriter(ScribusDoc *doc)
33
{
20691 craig 34
        m_document = doc;
22631 craig 35
        m_frame = nullptr;
20883 jghali 36
        m_styledUptoPos = 0;
14472 fschmid 37
}
38
 
39
void TextWriter::open(PageItem *textframe)
40
{
20691 craig 41
        m_frame = textframe;
42
        m_charStyleMap.clear();
43
        m_parStyleMap.clear();
44
        m_fontMap.clear();
45
        m_colorMap.clear();
14472 fschmid 46
 
20691 craig 47
        m_styledUptoPos = m_frame->itemText.length();
14472 fschmid 48
 
20691 craig 49
        m_currentCharStyle.erase();
50
        m_currentParStyle.erase();
14472 fschmid 51
}
52
 
53
void TextWriter::appendText(const QString &text)
54
{
20691 craig 55
        m_frame->itemText.insertChars(m_frame->itemText.length(), text);
14472 fschmid 56
}
57
 
58
void TextWriter::setStyles()
59
{
20691 craig 60
        StoryText& story(m_frame->itemText);
14472 fschmid 61
 
20691 craig 62
        if (story.length() > m_styledUptoPos)
14472 fschmid 63
        {
20691 craig 64
                story.setCharStyle(m_styledUptoPos, story.length() - m_styledUptoPos, m_currentCharStyle);
65
                for (int i = m_styledUptoPos; i < story.length()-1; ++i)
14472 fschmid 66
                        if (story.text(i) == SpecialChars::PARSEP)
20691 craig 67
                                story.setStyle(i+1, m_currentParStyle);
68
                m_styledUptoPos = story.length();
14472 fschmid 69
        }
70
}
71
 
72
void TextWriter::close()
73
{
74
        setStyles();
20691 craig 75
        m_document->redefineCharStyles(m_charStyles, false);
76
        m_document->redefineStyles(m_parStyles, false);
14472 fschmid 77
}
78
 
79
void TextWriter::setCharStyle(const CharStyle &cstyle)
80
{
20691 craig 81
        if (m_currentCharStyle != cstyle)
14472 fschmid 82
                setStyles();
20691 craig 83
        m_currentCharStyle = cstyle;
14472 fschmid 84
}
85
 
86
void TextWriter::setCharStyle(const QString &name)
87
{
88
        CharStyle cstyle;
89
        cstyle.setParent(name);
90
        setCharStyle(cstyle);
91
}
92
 
93
void TextWriter::setStyle(const ParagraphStyle &pstyle)
94
{
20691 craig 95
        if (m_currentParStyle != pstyle)
14472 fschmid 96
                setStyles();
20691 craig 97
        m_currentParStyle = pstyle;
14472 fschmid 98
}
99
 
100
void TextWriter::setStyle(const QString &name)
101
{
102
        ParagraphStyle pstyle;
103
        pstyle.setParent(name);
104
        setStyle(pstyle);
105
}
106
 
22631 craig 107
void TextWriter::defineCharStyle(const QString& name, const CharStyle &cstyle)
14472 fschmid 108
{
20691 craig 109
        CharStyle* newStyle = m_charStyles.create(cstyle);
14472 fschmid 110
        newStyle->setName(name);
111
}
112
 
113
void TextWriter::defineStyle(const QString& name, const ParagraphStyle& pstyle)
114
{
20691 craig 115
        ParagraphStyle* newStyle = m_parStyles.create(pstyle);
14472 fschmid 116
        newStyle->setName(name);
117
}
118
 
119
void TextWriter::defineFont(const QString &name, const QString& family, const QString& variant, bool bold, bool italic)
120
{
20691 craig 121
        m_document->AddFont(name);
14472 fschmid 122
}
123
 
124
void TextWriter::defineColor(const QString &name, const ScColor& color)
125
{
20691 craig 126
        m_document->PageColors.insert(name, color);
14472 fschmid 127
}
128
 
129
CharStyle TextWriter::getCurrentCharStyle()
130
{
20691 craig 131
        return m_currentCharStyle;
14472 fschmid 132
}
133
 
134
ParagraphStyle TextWriter::getCurrentStyle()
135
{
20691 craig 136
        return m_currentParStyle;
14472 fschmid 137
}
138
 
139
ScribusDoc* TextWriter::currentDoc()
140
{
20691 craig 141
        return m_document;
22631 craig 142
}