Rev 2282 | Rev 2362 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
364 | Franz | 1 | /*************************************************************************** |
2 | * Copyright (C) 2004 by Riku Leino * |
||
1184 | tsoots | 3 | * tsoots@gmail.com * |
364 | Franz | 4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * |
||
6 | * it under the terms of the GNU General Public License as published by * |
||
7 | * the Free Software Foundation; either version 2 of the License, or * |
||
8 | * (at your option) any later version. * |
||
9 | * * |
||
10 | * This program is distributed in the hope that it will be useful, * |
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
13 | * GNU General Public License for more details. * |
||
14 | * * |
||
15 | * You should have received a copy of the GNU General Public License * |
||
16 | * along with this program; if not, write to the * |
||
17 | * Free Software Foundation, Inc., * |
||
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
19 | ***************************************************************************/ |
||
20 | |||
713 | cbradney | 21 | #include "missing.h" |
364 | Franz | 22 | #include "gtaction.h" |
759 | cbradney | 23 | #include "mpalette.h" |
766 | cbradney | 24 | #include "scribus.h" |
415 | Franz | 25 | #include <qcursor.h> |
833 | tsoots | 26 | #include <qstringlist.h> |
27 | #include "color.h" |
||
364 | Franz | 28 | |
29 | extern ScribusApp* ScApp; |
||
30 | |||
31 | gtAction::gtAction(bool append) |
||
32 | { |
||
456 | fschmid | 33 | textFrame = ScApp->view->SelItem.at(0); |
364 | Franz | 34 | it = textFrame; |
35 | lastParagraphStyle = -1; |
||
411 | Franz | 36 | inPara = false; |
418 | Franz | 37 | isFirstWrite = true; |
364 | Franz | 38 | lastCharWasLineChange = false; |
375 | Franz | 39 | currentFrameStyle = ""; |
418 | Franz | 40 | doAppend = append; |
411 | Franz | 41 | updateParagraphStyles = false; |
418 | Franz | 42 | overridePStyleFont = true; |
364 | Franz | 43 | } |
44 | |||
1702 | cbradney | 45 | gtAction::gtAction(bool append, PageItem* pageitem) |
46 | { |
||
47 | textFrame = pageitem; |
||
48 | it = textFrame; |
||
49 | lastParagraphStyle = -1; |
||
50 | inPara = false; |
||
51 | isFirstWrite = true; |
||
52 | lastCharWasLineChange = false; |
||
53 | currentFrameStyle = ""; |
||
54 | doAppend = append; |
||
55 | updateParagraphStyles = false; |
||
56 | overridePStyleFont = true; |
||
57 | } |
||
58 | |||
364 | Franz | 59 | void gtAction::setProgressInfo() |
60 | { |
||
61 | ScApp->FMess->setText(QObject::tr("Importing text")); |
||
62 | ScApp->FProg->reset(); |
||
63 | ScApp->FProg->setTotalSteps(0); |
||
64 | } |
||
65 | |||
66 | void gtAction::setProgressInfoDone() |
||
67 | { |
||
68 | ScApp->FMess->setText(""); |
||
69 | ScApp->FProg->reset(); |
||
70 | } |
||
71 | |||
72 | void gtAction::setInfo(QString infoText) |
||
73 | { |
||
74 | ScApp->FMess->setText(infoText); |
||
75 | } |
||
76 | |||
77 | void gtAction::clearFrame() |
||
78 | { |
||
1065 | cbradney | 79 | textFrame->itemText.clear(); |
364 | Franz | 80 | textFrame->CPos = 0; |
81 | } |
||
82 | |||
411 | Franz | 83 | void gtAction::write(const QString& text, gtStyle *style) |
364 | Franz | 84 | { |
418 | Franz | 85 | if (isFirstWrite) |
86 | { |
||
87 | if (!doAppend) |
||
88 | { |
||
89 | if (it->NextBox != 0) |
||
90 | { |
||
1957 | cbradney | 91 | PageItem *nextItem = it->NextBox; |
92 | while (nextItem != 0) |
||
418 | Franz | 93 | { |
1957 | cbradney | 94 | nextItem->itemText.clear(); |
95 | nextItem->CPos = 0; |
||
96 | nextItem = nextItem->NextBox; |
||
418 | Franz | 97 | } |
98 | } |
||
1065 | cbradney | 99 | it->itemText.clear(); |
418 | Franz | 100 | it->CPos = 0; |
101 | } |
||
102 | } |
||
411 | Franz | 103 | int paragraphStyle = -1; |
364 | Franz | 104 | if (style->target() == "paragraph") |
105 | { |
||
106 | gtParagraphStyle* pstyle = dynamic_cast<gtParagraphStyle*>(style); |
||
107 | paragraphStyle = applyParagraphStyle(pstyle); |
||
418 | Franz | 108 | if (isFirstWrite) |
109 | inPara = true; |
||
364 | Franz | 110 | } |
111 | else if (style->target() == "frame") |
||
112 | { |
||
113 | gtFrameStyle* fstyle = dynamic_cast<gtFrameStyle*>(style); |
||
114 | applyFrameStyle(fstyle); |
||
115 | } |
||
411 | Franz | 116 | |
117 | if ((inPara) && (!lastCharWasLineChange) && (text.left(1) != "\n") && (lastParagraphStyle != -1)) |
||
118 | paragraphStyle = lastParagraphStyle; |
||
119 | |||
120 | |||
121 | if (paragraphStyle == -1) |
||
1065 | cbradney | 122 | paragraphStyle = ScApp->doc->currentParaStyle; |
411 | Franz | 123 | |
364 | Franz | 124 | gtFont* font = style->getFont(); |
375 | Franz | 125 | QString fontName = validateFont(font); |
418 | Franz | 126 | gtFont* font2 = new gtFont(*font); |
1065 | cbradney | 127 | font2->setName(ScApp->doc->docParagraphStyles[paragraphStyle].Font); |
418 | Franz | 128 | QString fontName2 = validateFont(font2); |
364 | Franz | 129 | for (uint a = 0; a < text.length(); ++a) |
130 | { |
||
131 | if ((text.at(a) == QChar(0)) || (text.at(a) == QChar(13))) |
||
132 | continue; |
||
1065 | cbradney | 133 | struct ScText *hg = new ScText; |
364 | Franz | 134 | hg->ch = text.at(a); |
135 | if ((hg->ch == QChar(10)) || (hg->ch == QChar(5))) |
||
136 | hg->ch = QChar(13); |
||
418 | Franz | 137 | if ((inPara) && (!overridePStyleFont)) |
138 | { |
||
1065 | cbradney | 139 | if (ScApp->doc->docParagraphStyles[paragraphStyle].Font == "") |
1789 | fschmid | 140 | hg->cfont = (*ScApp->doc->AllFonts)[fontName2]; |
418 | Franz | 141 | else |
1789 | fschmid | 142 | hg->cfont = (*ScApp->doc->AllFonts)[ScApp->doc->docParagraphStyles[paragraphStyle].Font]; |
1065 | cbradney | 143 | hg->csize = ScApp->doc->docParagraphStyles[paragraphStyle].FontSize; |
144 | hg->ccolor = ScApp->doc->docParagraphStyles[paragraphStyle].FColor; |
||
145 | hg->cshade = ScApp->doc->docParagraphStyles[paragraphStyle].FShade; |
||
146 | hg->cstroke = ScApp->doc->docParagraphStyles[paragraphStyle].SColor; |
||
147 | hg->cshade2 = ScApp->doc->docParagraphStyles[paragraphStyle].SShade; |
||
148 | hg->cstyle = ScApp->doc->docParagraphStyles[paragraphStyle].FontEffect; |
||
418 | Franz | 149 | } |
150 | else |
||
151 | { |
||
1789 | fschmid | 152 | hg->cfont = (*ScApp->doc->AllFonts)[fontName]; |
418 | Franz | 153 | hg->csize = font->getSize(); |
833 | tsoots | 154 | hg->ccolor = parseColor(font->getColor()); |
418 | Franz | 155 | hg->cshade = font->getShade(); |
833 | tsoots | 156 | hg->cstroke = parseColor(font->getStrokeColor()); |
418 | Franz | 157 | hg->cshade2 = font->getStrokeShade(); |
158 | hg->cstyle = font->getEffectsValue(); |
||
159 | } |
||
2254 | fschmid | 160 | hg->cscale = font->getHscale(); |
2242 | fschmid | 161 | hg->cscalev = 1000; |
2234 | fschmid | 162 | hg->cbase = 0; |
2247 | fschmid | 163 | hg->cshadowx = 50; |
164 | hg->cshadowy = -50; |
||
2257 | fschmid | 165 | hg->coutline = 10; |
2262 | fschmid | 166 | hg->cunderpos = -1; |
167 | hg->cunderwidth = -1; |
||
2272 | fschmid | 168 | hg->cstrikepos = -1; |
169 | hg->cstrikewidth = -1; |
||
364 | Franz | 170 | hg->cextra = font->getKerning(); |
171 | hg->cselect = false; |
||
411 | Franz | 172 | hg->cab = paragraphStyle; |
364 | Franz | 173 | hg->xp = 0; |
174 | hg->yp = 0; |
||
175 | hg->PtransX = 0; |
||
176 | hg->PtransY = 0; |
||
1065 | cbradney | 177 | it->itemText.append(hg); |
364 | Franz | 178 | } |
411 | Franz | 179 | lastCharWasLineChange = text.right(1) == "\n"; |
180 | inPara = style->target() == "paragraph"; |
||
181 | lastParagraphStyle = paragraphStyle; |
||
418 | Franz | 182 | if (isFirstWrite) |
183 | isFirstWrite = false; |
||
364 | Franz | 184 | } |
185 | |||
186 | int gtAction::findParagraphStyle(gtParagraphStyle* pstyle) |
||
187 | { |
||
411 | Franz | 188 | return findParagraphStyle(pstyle->getName()); |
189 | } |
||
190 | |||
191 | int gtAction::findParagraphStyle(const QString& name) |
||
192 | { |
||
364 | Franz | 193 | int pstyleIndex = -1; |
1065 | cbradney | 194 | for (uint i = 0; i < ScApp->doc->docParagraphStyles.size(); ++i) |
364 | Franz | 195 | { |
1065 | cbradney | 196 | if (ScApp->doc->docParagraphStyles[i].Vname == name) |
411 | Franz | 197 | { |
364 | Franz | 198 | pstyleIndex = i; |
199 | break; |
||
200 | } |
||
201 | } |
||
202 | return pstyleIndex; |
||
203 | } |
||
204 | |||
205 | int gtAction::applyParagraphStyle(gtParagraphStyle* pstyle) |
||
206 | { |
||
207 | int pstyleIndex = findParagraphStyle(pstyle); |
||
208 | if (pstyleIndex == -1) |
||
209 | { |
||
210 | createParagraphStyle(pstyle); |
||
1065 | cbradney | 211 | pstyleIndex = ScApp->doc->docParagraphStyles.size() - 1; |
364 | Franz | 212 | } |
411 | Franz | 213 | else if (updateParagraphStyles) |
214 | { |
||
215 | updateParagraphStyle(pstyleIndex, pstyle); |
||
216 | } |
||
364 | Franz | 217 | return pstyleIndex; |
218 | } |
||
219 | |||
220 | void gtAction::applyFrameStyle(gtFrameStyle* fstyle) |
||
221 | { |
||
375 | Franz | 222 | textFrame->Cols = fstyle->getColumns(); |
223 | textFrame->ColGap = fstyle->getColumnsGap(); |
||
1394 | cbradney | 224 | textFrame->setFillColor(parseColor(fstyle->getBgColor())); |
225 | textFrame->setFillShade(fstyle->getBgShade()); |
||
2282 | fschmid | 226 | textFrame->TabValues = QValueList<PageItem::TabRecord>(*(fstyle->getTabValues())); |
375 | Franz | 227 | |
411 | Franz | 228 | // gtParagraphStyle* pstyle = new gtParagraphStyle(*fstyle); |
229 | // int pstyleIndex = findParagraphStyle(pstyle); |
||
230 | // if (pstyleIndex == -1) |
||
231 | // pstyleIndex = 0; |
||
1065 | cbradney | 232 | // textFrame->Doc->currentParaStyle = pstyleIndex; |
375 | Franz | 233 | |
411 | Franz | 234 | double linesp; |
235 | if (fstyle->getAutoLineSpacing()) |
||
236 | linesp = getLineSpacing(fstyle->getFont()->getSize()); |
||
237 | else |
||
238 | linesp = fstyle->getLineSpacing(); |
||
239 | textFrame->LineSp = linesp; |
||
2309 | fschmid | 240 | textFrame->LineSpMode = 0; |
375 | Franz | 241 | gtFont* font = fstyle->getFont(); |
242 | QString fontName = validateFont(font); |
||
243 | textFrame->IFont = fontName; |
||
244 | textFrame->ISize = font->getSize(); |
||
833 | tsoots | 245 | textFrame->TxtFill = parseColor(font->getColor()); |
375 | Franz | 246 | textFrame->ShTxtFill = font->getShade(); |
833 | tsoots | 247 | textFrame->TxtStroke = parseColor(font->getStrokeColor()); |
375 | Franz | 248 | textFrame->ShTxtStroke = font->getStrokeShade(); |
2254 | fschmid | 249 | textFrame->TxtScale = font->getHscale(); |
250 | textFrame->TxtScaleV = 1000; |
||
2234 | fschmid | 251 | textFrame->TxtBase = 0; |
2247 | fschmid | 252 | textFrame->TxtShadowX = 50; |
253 | textFrame->TxtShadowY = -50; |
||
2257 | fschmid | 254 | textFrame->TxtOutline = 10; |
2262 | fschmid | 255 | textFrame->TxtUnderPos = -1; |
256 | textFrame->TxtUnderWidth = -1; |
||
2272 | fschmid | 257 | textFrame->TxtStrikePos = -1; |
258 | textFrame->TxtStrikeWidth = -1; |
||
411 | Franz | 259 | textFrame->ExtraV = font->getKerning(); |
364 | Franz | 260 | } |
261 | |||
262 | void gtAction::getFrameFont(gtFont *font) |
||
263 | { |
||
264 | font->setName(textFrame->IFont); |
||
265 | font->setSize(textFrame->ISize); |
||
266 | font->setColor(textFrame->TxtFill); |
||
267 | font->setShade(textFrame->ShTxtFill); |
||
268 | font->setStrokeColor(textFrame->TxtStroke); |
||
269 | font->setStrokeShade(textFrame->ShTxtStroke); |
||
270 | font->setHscale(textFrame->TxtScale); |
||
271 | font->setKerning(0); |
||
272 | } |
||
273 | |||
274 | void gtAction::getFrameStyle(gtFrameStyle *fstyle) |
||
275 | { |
||
276 | fstyle->setColumns(textFrame->Cols); |
||
277 | fstyle->setColumnsGap(textFrame->ColGap); |
||
1394 | cbradney | 278 | fstyle->setBgColor(textFrame->fillColor()); |
279 | fstyle->setBgShade(textFrame->fillShade()); |
||
364 | Franz | 280 | |
1065 | cbradney | 281 | struct ParagraphStyle vg = textFrame->Doc->docParagraphStyles[textFrame->Doc->currentParaStyle]; |
364 | Franz | 282 | fstyle->setName(vg.Vname); |
283 | fstyle->setLineSpacing(vg.LineSpa); |
||
1065 | cbradney | 284 | fstyle->setAlignment(vg.textAlignment); |
364 | Franz | 285 | fstyle->setIndent(vg.Indent); |
286 | fstyle->setFirstLineIndent(vg.First); |
||
1065 | cbradney | 287 | fstyle->setSpaceAbove(vg.gapBefore); |
288 | fstyle->setSpaceBelow(vg.gapAfter); |
||
364 | Franz | 289 | fstyle->setDropCap(vg.Drop); |
290 | fstyle->setDropCapHeight(vg.DropLin); |
||
291 | fstyle->setAdjToBaseline(vg.BaseAdj); |
||
292 | |||
293 | gtFont font; |
||
294 | getFrameFont(&font); |
||
295 | fstyle->setFont(font); |
||
387 | Franz | 296 | fstyle->setName("Default frame style"); |
364 | Franz | 297 | } |
298 | |||
299 | void gtAction::createParagraphStyle(gtParagraphStyle* pstyle) |
||
300 | { |
||
1065 | cbradney | 301 | if (textFrame->Doc->docParagraphStyles.size() > 5) |
364 | Franz | 302 | { |
1065 | cbradney | 303 | for (uint i = 5; i < textFrame->Doc->docParagraphStyles.size(); ++i) |
364 | Franz | 304 | { |
1065 | cbradney | 305 | if (textFrame->Doc->docParagraphStyles[i].Vname == pstyle->getName()) |
364 | Franz | 306 | return; |
307 | } |
||
411 | Franz | 308 | } |
364 | Franz | 309 | gtFont* font = pstyle->getFont(); |
1065 | cbradney | 310 | struct ParagraphStyle vg; |
364 | Franz | 311 | vg.Vname = pstyle->getName(); |
411 | Franz | 312 | double linesp; |
313 | if (pstyle->getAutoLineSpacing()) |
||
314 | linesp = getLineSpacing(pstyle->getFont()->getSize()); |
||
315 | else |
||
316 | linesp = pstyle->getLineSpacing(); |
||
2309 | fschmid | 317 | vg.LineSpaMode = 0; |
411 | Franz | 318 | vg.LineSpa = linesp; |
1065 | cbradney | 319 | vg.textAlignment = pstyle->getAlignment(); |
364 | Franz | 320 | vg.Indent = pstyle->getIndent(); |
321 | vg.First = pstyle->getFirstLineIndent(); |
||
1065 | cbradney | 322 | vg.gapBefore = pstyle->getSpaceAbove(); |
323 | vg.gapAfter = pstyle->getSpaceBelow(); |
||
403 | Franz | 324 | vg.Font = validateFont(font); |
364 | Franz | 325 | vg.FontSize = font->getSize(); |
326 | vg.TabValues.clear(); |
||
2282 | fschmid | 327 | QValueList<PageItem::TabRecord> *tabs = pstyle->getTabValues(); |
375 | Franz | 328 | for (uint i = 0; i < tabs->size(); ++i) |
329 | { |
||
2282 | fschmid | 330 | struct PageItem::TabRecord tmp = (*tabs)[i]; |
375 | Franz | 331 | vg.TabValues.append(tmp); |
332 | } |
||
364 | Franz | 333 | vg.Drop = pstyle->hasDropCap(); |
334 | vg.DropLin = pstyle->getDropCapHeight(); |
||
335 | vg.FontEffect = font->getEffectsValue(); |
||
833 | tsoots | 336 | vg.FColor = parseColor(font->getColor()); |
364 | Franz | 337 | vg.FShade = font->getShade(); |
833 | tsoots | 338 | vg.SColor = parseColor(font->getStrokeColor()); |
364 | Franz | 339 | vg.SShade = font->getStrokeShade(); |
340 | vg.BaseAdj = pstyle->isAdjToBaseline(); |
||
2273 | fschmid | 341 | vg.txtShadowX = 50; |
342 | vg.txtShadowY = -50; |
||
343 | vg.txtOutline = 10; |
||
344 | vg.txtUnderPos = ScApp->doc->typographicSetttings.valueUnderlinePos; |
||
345 | vg.txtUnderWidth = ScApp->doc->typographicSetttings.valueUnderlineWidth; |
||
346 | vg.txtStrikePos = ScApp->doc->typographicSetttings.valueStrikeThruPos; |
||
347 | vg.txtStrikeWidth = ScApp->doc->typographicSetttings.valueStrikeThruPos; |
||
1065 | cbradney | 348 | textFrame->Doc->docParagraphStyles.append(vg); |
1545 | cbradney | 349 | ScApp->propertiesPalette->Spal->updateFormatList(); |
364 | Franz | 350 | } |
351 | |||
411 | Franz | 352 | void gtAction::removeParagraphStyle(const QString& name) |
353 | { |
||
354 | int index = findParagraphStyle(name); |
||
355 | if (index != -1) |
||
356 | removeParagraphStyle(index); |
||
357 | } |
||
358 | |||
359 | void gtAction::removeParagraphStyle(int index) |
||
360 | { |
||
1065 | cbradney | 361 | QValueList<ParagraphStyle>::iterator it = ScApp->doc->docParagraphStyles.at(index); |
362 | ScApp->doc->docParagraphStyles.remove(it); |
||
411 | Franz | 363 | } |
364 | |||
1185 | tsoots | 365 | void gtAction::updateParagraphStyle(const QString&, gtParagraphStyle* pstyle) |
411 | Franz | 366 | { |
367 | int pstyleIndex = findParagraphStyle(pstyle->getName()); |
||
368 | if (pstyleIndex != -1) |
||
369 | updateParagraphStyle(pstyleIndex, pstyle); |
||
370 | } |
||
371 | |||
372 | void gtAction::updateParagraphStyle(int pstyleIndex, gtParagraphStyle* pstyle) |
||
373 | { |
||
374 | gtFont* font = pstyle->getFont(); |
||
1065 | cbradney | 375 | struct ParagraphStyle vg; |
411 | Franz | 376 | vg.Vname = pstyle->getName(); |
377 | double linesp; |
||
378 | if (pstyle->getAutoLineSpacing()) |
||
379 | linesp = getLineSpacing(pstyle->getFont()->getSize()); |
||
380 | else |
||
381 | linesp = pstyle->getLineSpacing(); |
||
2309 | fschmid | 382 | vg.LineSpaMode = 0; |
411 | Franz | 383 | vg.LineSpa = linesp; |
1065 | cbradney | 384 | vg.textAlignment = pstyle->getAlignment(); |
411 | Franz | 385 | vg.Indent = pstyle->getIndent(); |
386 | vg.First = pstyle->getFirstLineIndent(); |
||
1065 | cbradney | 387 | vg.gapBefore = pstyle->getSpaceAbove(); |
388 | vg.gapAfter = pstyle->getSpaceBelow(); |
||
411 | Franz | 389 | vg.Font = validateFont(font); |
390 | vg.FontSize = font->getSize(); |
||
391 | vg.TabValues.clear(); |
||
2282 | fschmid | 392 | QValueList<PageItem::TabRecord> *tabs = pstyle->getTabValues(); |
411 | Franz | 393 | for (uint i = 0; i < tabs->size(); ++i) |
394 | { |
||
2282 | fschmid | 395 | struct PageItem::TabRecord tmp = (*tabs)[i]; |
411 | Franz | 396 | vg.TabValues.append(tmp); |
397 | } |
||
398 | vg.Drop = pstyle->hasDropCap(); |
||
399 | vg.DropLin = pstyle->getDropCapHeight(); |
||
400 | vg.FontEffect = font->getEffectsValue(); |
||
833 | tsoots | 401 | vg.FColor = parseColor(font->getColor()); |
411 | Franz | 402 | vg.FShade = font->getShade(); |
833 | tsoots | 403 | vg.SColor = parseColor(font->getStrokeColor()); |
411 | Franz | 404 | vg.SShade = font->getStrokeShade(); |
405 | vg.BaseAdj = pstyle->isAdjToBaseline(); |
||
2273 | fschmid | 406 | vg.txtShadowX = 50; |
407 | vg.txtShadowY = -50; |
||
408 | vg.txtOutline = 10; |
||
409 | vg.txtUnderPos = ScApp->doc->typographicSetttings.valueUnderlinePos; |
||
410 | vg.txtUnderWidth = ScApp->doc->typographicSetttings.valueUnderlineWidth; |
||
411 | vg.txtStrikePos = ScApp->doc->typographicSetttings.valueStrikeThruPos; |
||
412 | vg.txtStrikeWidth = ScApp->doc->typographicSetttings.valueStrikeThruPos; |
||
1065 | cbradney | 413 | ScApp->doc->docParagraphStyles[pstyleIndex] = vg; |
411 | Franz | 414 | } |
415 | |||
375 | Franz | 416 | QString gtAction::validateFont(gtFont* font) |
364 | Franz | 417 | { |
411 | Franz | 418 | // Dirty hack for family Times New Roman |
419 | if (font->getFamily() == "Times New") |
||
420 | { |
||
421 | font->setFamily("Times New Roman"); |
||
422 | if (font->getWeight() == "Roman") |
||
423 | font->setWeight("Regular"); |
||
424 | } |
||
425 | |||
375 | Franz | 426 | QString useFont = font->getName(); |
427 | if ((useFont == NULL) || (useFont == "")) |
||
428 | useFont = textFrame->IFont; |
||
429 | else if (ScApp->Prefs.AvailFonts[font->getName()] == 0) |
||
364 | Franz | 430 | { |
387 | Franz | 431 | bool found = false; |
411 | Franz | 432 | useFont == NULL; |
387 | Franz | 433 | QString tmpName = findFontName(font); |
434 | if (tmpName != NULL) |
||
375 | Franz | 435 | { |
387 | Franz | 436 | useFont = tmpName; |
437 | found = true; |
||
375 | Franz | 438 | } |
387 | Franz | 439 | if (!found) |
440 | { |
||
441 | if (font->getSlant() == gtFont::fontSlants[ITALIC]) |
||
442 | { |
||
443 | gtFont* tmp = new gtFont(*font); |
||
444 | tmp->setSlant(OBLIQUE); |
||
445 | tmpName = findFontName(tmp); |
||
446 | if (tmpName != NULL) |
||
447 | { |
||
448 | useFont = tmpName; |
||
449 | found = true; |
||
450 | } |
||
451 | delete tmp; |
||
452 | } |
||
453 | else if (font->getSlant() == gtFont::fontSlants[OBLIQUE]) |
||
454 | { |
||
455 | gtFont* tmp = new gtFont(*font); |
||
456 | tmp->setSlant(ITALIC); |
||
457 | tmpName = findFontName(tmp); |
||
458 | if (tmpName != NULL) |
||
459 | { |
||
460 | useFont = tmpName; |
||
461 | found = true; |
||
462 | } |
||
463 | delete tmp; |
||
464 | } |
||
465 | if (!found) |
||
466 | { |
||
467 | if (!ScApp->Prefs.GFontSub.contains(font->getName())) |
||
468 | { |
||
1143 | fschmid | 469 | MissingFont *dia = new MissingFont(0, useFont, &ScApp->Prefs, ScApp->doc); |
387 | Franz | 470 | dia->exec(); |
713 | cbradney | 471 | useFont = dia->getReplacementFont(); |
387 | Franz | 472 | ScApp->Prefs.GFontSub[font->getName()] = useFont; |
473 | delete dia; |
||
474 | } |
||
475 | else |
||
476 | useFont = ScApp->Prefs.GFontSub[font->getName()]; |
||
477 | } |
||
478 | } |
||
364 | Franz | 479 | } |
411 | Franz | 480 | |
375 | Franz | 481 | if(!ScApp->doc->UsedFonts.contains(useFont)) |
482 | ScApp->doc->AddFont(useFont, ScApp->Prefs.AvailFonts[useFont]->Font); |
||
483 | return useFont; |
||
364 | Franz | 484 | } |
485 | |||
387 | Franz | 486 | QString gtAction::findFontName(gtFont* font) |
487 | { |
||
488 | QString ret = NULL; |
||
489 | for (uint i = 0; i < static_cast<uint>(gtFont::NAMECOUNT); ++i) |
||
490 | { |
||
491 | QString nname = font->getName(i); |
||
492 | if (ScApp->Prefs.AvailFonts[nname] != 0) |
||
493 | { |
||
494 | ret = nname; |
||
495 | break; |
||
496 | } |
||
497 | } |
||
498 | return ret; |
||
499 | } |
||
500 | |||
411 | Franz | 501 | double gtAction::getLineSpacing(int fontSize) |
502 | { |
||
823 | fschmid | 503 | return ((fontSize / 10.0) * static_cast<double>(ScApp->doc->typographicSetttings.autoLineSpacing) / 100) + (fontSize / 10.0); |
411 | Franz | 504 | } |
505 | |||
375 | Franz | 506 | double gtAction::getFrameWidth() |
507 | { |
||
508 | return textFrame->Width; |
||
509 | } |
||
510 | |||
511 | QString gtAction::getFrameName() |
||
512 | { |
||
1361 | tsoots | 513 | return QString(textFrame->itemName()); |
375 | Franz | 514 | } |
515 | |||
411 | Franz | 516 | bool gtAction::getUpdateParagraphStyles() |
517 | { |
||
518 | return updateParagraphStyles; |
||
519 | } |
||
520 | |||
521 | void gtAction::setUpdateParagraphStyles(bool newUPS) |
||
522 | { |
||
523 | updateParagraphStyles = newUPS; |
||
524 | } |
||
525 | |||
418 | Franz | 526 | bool gtAction::getOverridePStyleFont() |
527 | { |
||
528 | return overridePStyleFont; |
||
529 | } |
||
530 | void gtAction::setOverridePStyleFont(bool newOPSF) |
||
531 | { |
||
532 | overridePStyleFont = newOPSF; |
||
533 | } |
||
534 | |||
833 | tsoots | 535 | QString gtAction::parseColor(const QString &s) |
536 | { |
||
537 | QString ret = "None"; |
||
538 | if (s == "None") |
||
539 | return ret; // don't want None to become Black or any color |
||
540 | bool found = false; |
||
1065 | cbradney | 541 | ColorList::Iterator it; |
833 | tsoots | 542 | for (it = ScApp->doc->PageColors.begin(); it != ScApp->doc->PageColors.end(); ++it) |
543 | { |
||
544 | if (it.key() == s) |
||
545 | { |
||
546 | ret = it.key(); |
||
547 | found = true; |
||
548 | } |
||
549 | } |
||
550 | if (!found) |
||
551 | { |
||
552 | QColor c; |
||
553 | if( s.startsWith( "rgb(" ) ) |
||
554 | { |
||
555 | QString parse = s.stripWhiteSpace(); |
||
556 | QStringList colors = QStringList::split( ',', parse ); |
||
557 | QString r = colors[0].right( ( colors[0].length() - 4 ) ); |
||
558 | QString g = colors[1]; |
||
559 | QString b = colors[2].left( ( colors[2].length() - 1 ) ); |
||
560 | if( r.contains( "%" ) ) |
||
561 | { |
||
562 | r = r.left( r.length() - 1 ); |
||
563 | r = QString::number( static_cast<int>( ( static_cast<double>( 255 * r.toDouble() ) / 100.0 ) ) ); |
||
564 | } |
||
565 | if( g.contains( "%" ) ) |
||
566 | { |
||
567 | g = g.left( g.length() - 1 ); |
||
568 | g = QString::number( static_cast<int>( ( static_cast<double>( 255 * g.toDouble() ) / 100.0 ) ) ); |
||
569 | } |
||
570 | if( b.contains( "%" ) ) |
||
571 | { |
||
572 | b = b.left( b.length() - 1 ); |
||
573 | b = QString::number( static_cast<int>( ( static_cast<double>( 255 * b.toDouble() ) / 100.0 ) ) ); |
||
574 | } |
||
575 | c = QColor(r.toInt(), g.toInt(), b.toInt()); |
||
576 | } |
||
577 | else |
||
578 | { |
||
579 | QString rgbColor = s.stripWhiteSpace(); |
||
580 | if( rgbColor.startsWith( "#" ) ) |
||
581 | c.setNamedColor( rgbColor ); |
||
582 | else |
||
583 | c = parseColorN( rgbColor ); |
||
584 | } |
||
585 | found = false; |
||
586 | for (it = ScApp->doc->PageColors.begin(); it != ScApp->doc->PageColors.end(); ++it) |
||
587 | { |
||
588 | if (c == ScApp->doc->PageColors[it.key()].getRGBColor()) |
||
589 | { |
||
590 | ret = it.key(); |
||
591 | found = true; |
||
592 | } |
||
593 | } |
||
594 | if (!found) |
||
595 | { |
||
596 | CMYKColor tmp; |
||
597 | tmp.fromQColor(c); |
||
598 | ScApp->doc->PageColors.insert("FromGetText"+c.name(), tmp); |
||
1545 | cbradney | 599 | ScApp->propertiesPalette->Cpal->SetColors(ScApp->doc->PageColors); |
833 | tsoots | 600 | ret = "FromGetText"+c.name(); |
601 | } |
||
602 | } |
||
603 | return ret; |
||
604 | } |
||
605 | |||
606 | QColor gtAction::parseColorN(const QString &rgbColor) |
||
607 | { |
||
608 | int r, g, b; |
||
609 | keywordToRGB( rgbColor, r, g, b ); |
||
610 | return QColor( r, g, b ); |
||
611 | } |
||
612 | |||
364 | Franz | 613 | void gtAction::finalize() |
614 | { |
||
1065 | cbradney | 615 | if (ScApp->doc->docHyphenator->AutoCheck) |
616 | ScApp->doc->docHyphenator->slotHyphenate(textFrame); |
||
456 | fschmid | 617 | ScApp->view->DrawNew(); |
364 | Franz | 618 | ScApp->slotDocCh(); |
619 | } |
||
620 | |||
621 | gtAction::~gtAction() |
||
622 | { |
||
623 | finalize(); |
||
624 | } |