Subversion Repositories Scribus

Rev

Rev 14472 | Rev 20691 | Go to most recent revision | 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
#ifndef TEXTWRITER_H
28
#define TEXTWRITER_H
29
 
30
#include <QString>
31
#include <QMap>
32
#include "scconfig.h"
33
#include "scribusapi.h"
34
 
35
#include "styles/charstyle.h"
36
#include "styles/paragraphstyle.h"
37
#include "styles/styleset.h"
38
 
39
class ScribusDoc;
40
class PageItem;
41
class ScColor;
42
 
43
/**
44
 * Helper class for importing text
45
 */
46
class SCRIBUS_API TextWriter
47
{
48
public:
49
        TextWriter(ScribusDoc* doc);
50
        /**
51
         Sets the target for following set* and append operations.
52
         Only one pageitem of a linked chain may be opened at the same time,
53
         it's responsibility of the programmer to ensure that
54
         */
55
        void open(PageItem* textframe);
56
        /**
57
         Writes all pending information to the target. This method returns
58
         the document into a consistent state. Failing to call it may cause
59
         data loss or corruption.
60
        */
61
        void close();
62
        /**
63
        Return the current character style
64
        */
65
        CharStyle getCurrentCharStyle();
66
        /**
67
        Return the current character style
68
        */
69
        ParagraphStyle getCurrentStyle();
70
        /**
71
         Sets the character style for following append operations
72
         */
73
        void setCharStyle(const CharStyle& cstyle);
74
        void setCharStyle(const QString& name);
75
        /**
76
         Sets the paragraph style for following append operations, ie. the
77
         style to be used when the next paragraph separator (\n) is appended.
78
         The current paragraph style will not be changed
79
         */
80
        void setStyle(const ParagraphStyle& pstyle);
81
        void setStyle(const QString& name);
82
        /**
83
         Appends text using current character style and paragraph style
84
         */
85
        void appendText(const QString& text);
86
 
87
        /**
88
         Introduces a new named character style into the document
89
         */
90
        void defineCharStyle(const QString name, const CharStyle& cstyle);
91
        /**
92
         Introduces a new named paragraph style into the document
93
         */
94
        void defineStyle(const QString& name, const ParagraphStyle& pstyle);
95
        /**
96
         Introduces a new named font into the document.
97
         If the document already uses a font 'name', use that. Otherwise find a match
98
         using 'family', 'variant', 'bold' and 'italic'
99
         */
100
        void defineFont(const QString& name, const QString& family, const QString& variant, bool bold=false, bool italic=false);
101
        /**
102
         Introduces a new named color into the document
103
         */
104
        void defineColor(const QString& name, const ScColor& color);
105
        ScribusDoc* currentDoc();
106
 
107
private:
108
        ScribusDoc* document;
109
        PageItem* frame;
110
 
111
        CharStyle currentCharStyle;
112
        ParagraphStyle currentParStyle;
113
 
114
        int styledUptoPos;
115
        void setStyles();
116
 
117
        StyleSet<CharStyle> charStyles;
118
        StyleSet<ParagraphStyle> parStyles;
119
 
120
        // for resolving name conflicts:
121
        QMap<QString, QString> parStyleMap;
122
        QMap<QString, QString> charStyleMap;
123
        QMap<QString, QString> fontMap;
124
        QMap<QString, QString> colorMap;
125
};
126
 
127
#endif