Rev 18084 | Rev 20606 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4430 | cbradney | 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 | */ |
||
364 | Franz | 7 | /*************************************************************************** |
8 | * Copyright (C) 2004 by Riku Leino * |
||
1184 | tsoots | 9 | * tsoots@gmail.com * |
364 | Franz | 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. * |
364 | Franz | 25 | ***************************************************************************/ |
26 | |||
27 | #include "gtwriter.h" |
||
13805 | jghali | 28 | #include "gtframestyle.h" |
29 | |||
1702 | cbradney | 30 | #include "pageitem.h" |
2714 | craig | 31 | #include "scribusstructs.h" |
364 | Franz | 32 | |
5781 | cbradney | 33 | // gtWriter::gtWriter(bool append) |
34 | // { |
||
35 | // action = new gtAction(append, ScMW->doc->m_Selection->itemAt(0)); |
||
36 | // errorSet = false; |
||
37 | // action->setProgressInfo(); |
||
38 | // setDefaultStyle(); |
||
39 | // unsetCharacterStyle(); |
||
40 | // unsetParagraphStyle(); |
||
41 | // // if (!append) |
||
42 | // // action->clearFrame(); |
||
43 | // // else |
||
44 | // // this->append("\n"); |
||
45 | // } |
||
364 | Franz | 46 | |
1702 | cbradney | 47 | gtWriter::gtWriter(bool append, PageItem *pageitem) |
48 | { |
||
49 | action = new gtAction(append, pageitem); |
||
50 | errorSet = false; |
||
51 | action->setProgressInfo(); |
||
52 | setDefaultStyle(); |
||
53 | unsetCharacterStyle(); |
||
54 | unsetParagraphStyle(); |
||
18084 | jghali | 55 | inNote = false; |
56 | inNoteBody = false; |
||
1702 | cbradney | 57 | } |
58 | |||
364 | Franz | 59 | gtFrameStyle* gtWriter::getDefaultStyle() |
60 | { |
||
61 | return frameStyle; |
||
62 | } |
||
63 | |||
64 | void gtWriter::setFrameStyle(gtFrameStyle *fStyle) |
||
65 | { |
||
66 | frameStyle = fStyle; |
||
411 | Franz | 67 | action->applyFrameStyle(fStyle); |
364 | Franz | 68 | } |
69 | |||
70 | void gtWriter::setParagraphStyle(gtParagraphStyle *pStyle) |
||
71 | { |
||
72 | // @todo Start a new paragraph and add the style to the Paragraph Styles |
||
73 | paragraphStyle = pStyle; |
||
74 | } |
||
75 | |||
76 | void gtWriter::setCharacterStyle(gtStyle *cStyle) |
||
77 | { |
||
78 | characterStyle = cStyle; |
||
79 | } |
||
80 | |||
375 | Franz | 81 | void gtWriter::unsetFrameStyle() |
364 | Franz | 82 | { |
83 | frameStyle = defaultStyle; |
||
84 | } |
||
85 | |||
375 | Franz | 86 | void gtWriter::unsetParagraphStyle() |
364 | Franz | 87 | { |
88 | paragraphStyle = NULL; |
||
89 | } |
||
90 | |||
375 | Franz | 91 | void gtWriter::unsetCharacterStyle() |
364 | Franz | 92 | { |
93 | characterStyle = NULL; |
||
94 | } |
||
95 | |||
411 | Franz | 96 | double gtWriter::getPreferredLineSpacing(int fontSize) |
364 | Franz | 97 | { |
411 | Franz | 98 | return action->getLineSpacing(fontSize); |
99 | } |
||
100 | |||
101 | double gtWriter::getPreferredLineSpacing(double fontSize) |
||
102 | { |
||
103 | return getPreferredLineSpacing(static_cast<int>(fontSize * 10)); |
||
104 | } |
||
105 | |||
106 | void gtWriter::append(const QString& text) |
||
107 | { |
||
12895 | jghali | 108 | if (text.isEmpty()) |
364 | Franz | 109 | return; |
110 | if (text.length() == 0) |
||
111 | return; |
||
18084 | jghali | 112 | if (inNote && !inNoteBody) |
113 | return; |
||
364 | Franz | 114 | if (characterStyle != NULL) |
115 | { |
||
18084 | jghali | 116 | action->write(text, characterStyle, inNote); |
364 | Franz | 117 | } |
118 | else if (paragraphStyle != NULL) |
||
119 | { |
||
18084 | jghali | 120 | action->write(text, paragraphStyle, inNote); |
364 | Franz | 121 | } |
122 | else |
||
123 | { |
||
18084 | jghali | 124 | action->write(text, frameStyle, inNote); |
364 | Franz | 125 | } |
126 | } |
||
127 | |||
12895 | jghali | 128 | void gtWriter::appendUnstyled(const QString& text) |
129 | { |
||
130 | if (text.isEmpty()) |
||
131 | return; |
||
132 | if (text.length() == 0) |
||
133 | return; |
||
18084 | jghali | 134 | if (inNote && !inNoteBody) |
135 | return; |
||
136 | action->writeUnstyled(text, inNote); |
||
12895 | jghali | 137 | } |
138 | |||
375 | Franz | 139 | double gtWriter::getFrameWidth() |
140 | { |
||
141 | return action->getFrameWidth(); |
||
142 | } |
||
143 | |||
144 | QString gtWriter::getFrameName() |
||
145 | { |
||
146 | return action->getFrameName(); |
||
147 | } |
||
148 | |||
411 | Franz | 149 | void gtWriter::append(const QString& text, gtStyle *style) |
364 | Franz | 150 | { |
18084 | jghali | 151 | if (inNote && !inNoteBody) |
152 | return; |
||
364 | Franz | 153 | if (style == NULL) |
154 | { |
||
155 | append(text); |
||
156 | return; |
||
157 | } |
||
158 | |||
159 | currentStyle = style; |
||
18084 | jghali | 160 | action->write(text, style, inNote); |
364 | Franz | 161 | currentStyle = NULL; |
162 | } |
||
163 | |||
411 | Franz | 164 | void gtWriter::append(const QString& text, gtStyle *style, bool updatePStyle) |
165 | { |
||
166 | bool ups = action->getUpdateParagraphStyles(); |
||
167 | action->setUpdateParagraphStyles(updatePStyle); |
||
168 | append(text, style); |
||
169 | action->setUpdateParagraphStyles(ups); |
||
170 | } |
||
171 | |||
364 | Franz | 172 | void gtWriter::setDefaultStyle() |
173 | { |
||
174 | // @todo Get the style of the text frame we are appending to. |
||
175 | defaultStyle = new gtFrameStyle("Default style"); |
||
176 | action->getFrameStyle(defaultStyle); |
||
177 | frameStyle = defaultStyle; |
||
178 | } |
||
179 | |||
411 | Franz | 180 | bool gtWriter::getUpdateParagraphStyles() |
181 | { |
||
182 | return action->getUpdateParagraphStyles(); |
||
183 | } |
||
184 | |||
185 | void gtWriter::setUpdateParagraphStyles(bool newUPS) |
||
186 | { |
||
187 | action->setUpdateParagraphStyles(newUPS); |
||
188 | } |
||
189 | |||
418 | Franz | 190 | bool gtWriter::getOverridePStyleFont() |
191 | { |
||
192 | return action->getOverridePStyleFont(); |
||
193 | } |
||
194 | |||
195 | void gtWriter::setOverridePStyleFont(bool newOPSF) |
||
196 | { |
||
197 | action->setOverridePStyleFont(newOPSF); |
||
198 | } |
||
199 | |||
364 | Franz | 200 | gtWriter::~gtWriter() |
201 | { |
||
202 | if (!errorSet) |
||
203 | action->setProgressInfoDone(); |
||
204 | delete action; |
||
205 | delete defaultStyle; |
||
206 | } |