Subversion Repositories Scribus

Rev

Rev 1235 | Rev 1307 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 paul 1
/***************************************************************************
2
                          scribusdoc.cpp  -  description
3
                             -------------------
4
    begin                : Fre Apr  6 21:47:55 CEST 2001
5
    copyright            : (C) 2001 by Franz Schmid
6
    email                : Franz.Schmid@altmuehlnet.de
7
 ***************************************************************************/
8
 
9
/***************************************************************************
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
 ***************************************************************************/
17
 
18
#include "scribusdoc.h"
410 Franz 19
#include "scribusXml.h"
20
#include "scribus.h"
456 fschmid 21
#include "page.h"
22
#include "pageitem.h"
1179 tsoots 23
#include "undomanager.h"
24
#include "undostate.h"
25
#include <qfile.h>
410 Franz 26
 
1179 tsoots 27
extern QPixmap loadIcon(QString nam);
28
 
1065 cbradney 29
ScribusDoc::ScribusDoc(struct ApplicationPrefs *prefsData)
1179 tsoots 30
: UndoObject(QObject::tr("Document"))
3 paul 31
{
823 fschmid 32
        prefsValues = prefsData;
167 Franz 33
        modified = false;
34
        MasterP = false;
823 fschmid 35
        UsedFonts.clear();
36
        FT_Init_FreeType( &library );
37
        AllFonts = &prefsData->AvailFonts;
1194 fschmid 38
        AddFont(prefsData->toolSettings.defFont, prefsData->AvailFonts[prefsData->toolSettings.defFont]->Font);
39
        toolSettings.defFont = prefsData->toolSettings.defFont;
40
        toolSettings.defSize = prefsData->toolSettings.defSize;
879 fschmid 41
        guidesSettings.marginsShown = prefsData->guidesSettings.marginsShown;
42
        guidesSettings.framesShown = prefsData->guidesSettings.framesShown;
43
        guidesSettings.gridShown = prefsData->guidesSettings.gridShown;
44
        guidesSettings.guidesShown = prefsData->guidesSettings.guidesShown;
45
        guidesSettings.baseShown = prefsData->guidesSettings.baseShown;
46
        guidesSettings.linkShown = prefsData->guidesSettings.linkShown;
47
        guidesSettings.showPic = prefsData->guidesSettings.showPic;
48
        guidesSettings.grabRad = prefsData->guidesSettings.grabRad;
49
        guidesSettings.guideRad = prefsData->guidesSettings.guideRad;
50
        guidesSettings.minorGrid = prefsData->guidesSettings.minorGrid;
51
        guidesSettings.majorGrid = prefsData->guidesSettings.majorGrid;
52
        guidesSettings.minorColor = prefsData->guidesSettings.minorColor;
53
        guidesSettings.majorColor = prefsData->guidesSettings.majorColor;
823 fschmid 54
        papColor = prefsData->DpapColor;
879 fschmid 55
        guidesSettings.margColor = prefsData->guidesSettings.margColor;
56
        guidesSettings.guideColor = prefsData->guidesSettings.guideColor;
57
        guidesSettings.baseColor = prefsData->guidesSettings.baseColor;
1187 fschmid 58
        guidesSettings.before = prefsData->guidesSettings.before;
823 fschmid 59
        PageColors.clear();
60
        PageColors.insert("Black", CMYKColor(0, 0, 0, 255));
61
        PageColors.insert("White", CMYKColor(0, 0, 0, 0));
1194 fschmid 62
        if (prefsData->toolSettings.dPen != "None")
63
                PageColors.insert(prefsData->toolSettings.dPen, prefsData->DColors[prefsData->toolSettings.dPen]);
64
        toolSettings.dPen = prefsData->toolSettings.dPen;
65
        if (prefsData->toolSettings.dPenLine != "None")
66
                PageColors.insert(prefsData->toolSettings.dPenLine, prefsData->DColors[prefsData->toolSettings.dPenLine]);
67
        toolSettings.dPenLine = prefsData->toolSettings.dPenLine;
68
        if (prefsData->toolSettings.dPenText != "None")
69
                PageColors.insert(prefsData->toolSettings.dPenText, prefsData->DColors[prefsData->toolSettings.dPenText]);
70
        toolSettings.dPenText = prefsData->toolSettings.dPenText;
71
        if (prefsData->toolSettings.dStrokeText != "None")
72
                PageColors.insert(prefsData->toolSettings.dStrokeText, prefsData->DColors[prefsData->toolSettings.dStrokeText]);
73
        toolSettings.dStrokeText = prefsData->toolSettings.dStrokeText;
74
        if (prefsData->toolSettings.dBrush != "None")
75
                PageColors.insert(prefsData->toolSettings.dBrush, prefsData->DColors[prefsData->toolSettings.dBrush]);
76
        toolSettings.dBrush = prefsData->toolSettings.dBrush;
77
        if (prefsData->toolSettings.dBrushPict != "None")
78
                PageColors.insert(prefsData->toolSettings.dBrushPict, prefsData->DColors[prefsData->toolSettings.dBrushPict]);
79
        toolSettings.dBrushPict = prefsData->toolSettings.dBrushPict;
823 fschmid 80
        typographicSetttings.valueSuperScript = prefsData->typographicSetttings.valueSuperScript;
81
        typographicSetttings.scalingSuperScript = prefsData->typographicSetttings.scalingSuperScript;
82
        typographicSetttings.valueSubScript = prefsData->typographicSetttings.valueSubScript;
83
        typographicSetttings.scalingSubScript = prefsData->typographicSetttings.scalingSubScript;
84
        typographicSetttings.valueSmallCaps = prefsData->typographicSetttings.valueSmallCaps;
85
        typographicSetttings.autoLineSpacing = prefsData->typographicSetttings.autoLineSpacing;
86
        typographicSetttings.valueBaseGrid = prefsData->typographicSetttings.valueBaseGrid;
87
        typographicSetttings.offsetBaseGrid = prefsData->typographicSetttings.offsetBaseGrid;
1194 fschmid 88
        toolSettings.dShade = prefsData->toolSettings.dShade;
89
        toolSettings.dShade2 = prefsData->toolSettings.dShade2;
90
        toolSettings.shadePict = prefsData->toolSettings.shadePict;
91
        toolSettings.scaleX = prefsData->toolSettings.scaleX;
92
        toolSettings.scaleY = prefsData->toolSettings.scaleY;
93
        toolSettings.scaleType = prefsData->toolSettings.scaleType;
94
        toolSettings.aspectRatio = prefsData->toolSettings.aspectRatio;
95
        toolSettings.dCols = prefsData->toolSettings.dCols;
96
        toolSettings.dGap = prefsData->toolSettings.dGap;
97
        toolSettings.dLineArt = PenStyle(prefsData->toolSettings.dLineArt);
98
        toolSettings.dWidth = prefsData->toolSettings.dWidth;
99
        toolSettings.dShadeLine = prefsData->toolSettings.dShadeLine;
100
        toolSettings.dLstyleLine = PenStyle(prefsData->toolSettings.dLstyleLine);
101
        toolSettings.dWidthLine = prefsData->toolSettings.dWidthLine;
102
        toolSettings.dStartArrow = prefsData->toolSettings.dStartArrow;
103
        toolSettings.dEndArrow = prefsData->toolSettings.dEndArrow;
104
        toolSettings.polyC = prefsData->toolSettings.polyC;
105
        toolSettings.polyF = prefsData->toolSettings.polyF;
106
        toolSettings.polyS = prefsData->toolSettings.polyS;
107
        toolSettings.polyFd = prefsData->toolSettings.polyFd;
108
        toolSettings.polyR = prefsData->toolSettings.polyR;
109
        toolSettings.magMin = prefsData->toolSettings.magMin;
110
        toolSettings.magMax = prefsData->toolSettings.magMax;
111
        toolSettings.magStep = prefsData->toolSettings.magStep;
1261 fschmid 112
        checkerProfiles = prefsData->checkerProfiles;
113
        curCheckProfile = prefsData->curCheckProfile;
1065 cbradney 114
        docUnitIndex = prefsData->docUnitIndex;
115
        marginColored = prefsData->marginColored;
823 fschmid 116
        Language = prefsData->Language;
117
        MinWordLen = prefsData->MinWordLen;
118
        HyCount = prefsData->HyCount;
119
        Automatic = prefsData->Automatic;
120
        AutoCheck = prefsData->AutoCheck;
3 paul 121
        GuideLock = false;
122
        SnapGuides = false;
167 Franz 123
        useRaster = false;
124
        EditClip = false;
125
        EditClipMode = 0;
126
        loading = false;
178 Franz 127
        DocName = QObject::tr("Document")+"-";
3 paul 128
        CurrentSel = -1;
129
        DocTitel = "";
130
        DocAutor = "";
131
        DocComments = "";
68 Franz 132
        DocKeyWords = "";
330 Franz 133
        DocPublisher = "";
134
        DocDate = "";
135
        DocType = "";
136
        DocFormat = "";
137
        DocIdent = "";
138
        DocSource = "";
139
        DocLangInfo = "";
140
        DocRelation = "";
141
        DocCover = "";
142
        DocRights = "";
143
        DocContrib = "";
3 paul 144
        PageC = 0;
145
        LastAuto = 0;
146
        FirstAuto = 0;
147
        DraggedElem = 0;
148
        GroupCounter = 1;
1065 cbradney 149
        docParagraphStyles.clear();
150
        struct ParagraphStyle vg;
3 paul 151
        vg.Vname = "Normal Internal";
152
        vg.LineSpa = 15;
1065 cbradney 153
        vg.textAlignment = 0;
3 paul 154
        vg.Indent = 0;
155
        vg.First = 0;
1065 cbradney 156
        vg.gapBefore = 0;
157
        vg.gapAfter = 0;
3 paul 158
        vg.Font = "";
1194 fschmid 159
        vg.FontSize = toolSettings.defSize;
140 Franz 160
        vg.TabValues.clear();
153 Franz 161
        vg.Drop = false;
162
        vg.DropLin = 2;
173 Franz 163
        vg.FontEffect = 0;
1194 fschmid 164
        vg.FColor = toolSettings.dBrush;
165
        vg.FShade = toolSettings.dShade;
166
        vg.SColor = toolSettings.dPen;
167
        vg.SShade = toolSettings.dShade2;
241 Franz 168
        vg.BaseAdj = false;
1065 cbradney 169
        docParagraphStyles.append(vg);
3 paul 170
        vg.Vname = "Center Internal";
1065 cbradney 171
        vg.textAlignment = 1;
172
        docParagraphStyles.append(vg);
3 paul 173
        vg.Vname = "Rechts Internal";
1065 cbradney 174
        vg.textAlignment = 2;
175
        docParagraphStyles.append(vg);
3 paul 176
        vg.Vname = "Block Internal";
1065 cbradney 177
        vg.textAlignment = 3;
178
        docParagraphStyles.append(vg);
3 paul 179
        vg.Vname = "EBlock Internal";
1065 cbradney 180
        vg.textAlignment = 4;
181
        docParagraphStyles.append(vg);
3 paul 182
        Layers.clear();
183
        struct Layer ll;
184
        ll.LNr = 0;
185
        ll.Level = 0;
178 Franz 186
        ll.Name = QObject::tr("Background");
1065 cbradney 187
        ll.isViewable = true;
188
        ll.isPrintable = true;
3 paul 189
        Layers.append(ll);
190
        ActiveLayer = 0;
191
        JavaScripts.clear();
167 Franz 192
        CurrentStyle = 0;
1065 cbradney 193
        currentParaStyle = 0;
3 paul 194
        TotalItems = 0;
195
        TemplateMode = false;
196
        PDF_Optionen.Thumbnails = false;
197
        PDF_Optionen.Articles = false;
198
        PDF_Optionen.Compress = true;
202 Franz 199
        PDF_Optionen.CompressMethod = 0;
200
        PDF_Optionen.Quality = 0;
3 paul 201
        PDF_Optionen.RecalcPic = false;
202
        PDF_Optionen.Bookmarks = false;
203
        PDF_Optionen.PicRes = 300;
203 Franz 204
        PDF_Optionen.Version = 14;
3 paul 205
        PDF_Optionen.Resolution = 300;
206
        PDF_Optionen.Binding = 0;
207
        PDF_Optionen.EmbedList.clear();
476 fschmid 208
        PDF_Optionen.SubsetList.clear();
420 Franz 209
        PDF_Optionen.MirrorH = false;
469 fschmid 210
        PDF_Optionen.MirrorV = false;
454 fschmid 211
        PDF_Optionen.RotateDeg = 0;
3 paul 212
        PDF_Optionen.PresentMode = false;
213
        PDF_Optionen.Datei = "";
214
        PDF_Optionen.PresentVals.clear();
203 Franz 215
        PDF_Optionen.UseRGB = true;
3 paul 216
        PDF_Optionen.UseProfiles = false;
217
        PDF_Optionen.UseProfiles2 = false;
218
        PDF_Optionen.SolidProf = "";
219
        PDF_Optionen.SComp = 3;
220
        PDF_Optionen.ImageProf = "";
221
        PDF_Optionen.PrintProf = "";
222
        PDF_Optionen.Info = "";
223
        PDF_Optionen.Intent = 0;
224
        PDF_Optionen.Intent2 = 0;
225
        PDF_Optionen.BleedTop = 0;
226
        PDF_Optionen.BleedLeft = 0;
227
        PDF_Optionen.BleedRight = 0;
228
        PDF_Optionen.BleedBottom = 0;
229
        PDF_Optionen.EmbeddedI = false;
230
        PDF_Optionen.Encrypt = false;
231
        PDF_Optionen.PassOwner = "";
232
        PDF_Optionen.PassUser = "";
233
        PDF_Optionen.Permissions = -4;
337 Franz 234
        PDF_Optionen.UseLPI = false;
235
        PDF_Optionen.LPISettings.clear();
3 paul 236
        RePos = false;
237
        BookMarks.clear();
238
        OldBM = false;
239
        hasName = false;
63 Franz 240
        DoDrawing = true;
3 paul 241
        RotMode = 0;
123 Franz 242
        SubMode = -1;
3 paul 243
        ASaveTimer = new QTimer(this);
27 Franz 244
        MLineStyles.clear();
456 fschmid 245
        Pages.clear();
246
        MasterPages.clear();
247
        DocPages.clear();
248
        Items.clear();
249
        MasterItems.clear();
250
        DocItems.clear();
823 fschmid 251
        ScratchLeft = prefsData->ScratchLeft;
252
        ScratchRight = prefsData->ScratchRight;
253
        ScratchTop = prefsData->ScratchTop;
254
        ScratchBottom = prefsData->ScratchBottom;
255
        arrowStyles = prefsData->arrowStyles;
1179 tsoots 256
        undoManager = UndoManager::instance();
1235 fschmid 257
        docItemErrors.clear();
258
        masterItemErrors.clear();
3 paul 259
}
260
 
261
ScribusDoc::~ScribusDoc()
262
{
456 fschmid 263
        MasterItems.setAutoDelete(true);
264
        DocItems.setAutoDelete(true);
265
        MasterItems.clear();
266
        DocItems.clear();
267
        MasterPages.setAutoDelete(true);
268
        DocPages.setAutoDelete(true);
269
        MasterPages.clear();
270
        DocPages.clear();
494 fschmid 271
        QMap<QString,QFont>::Iterator it3;
272
        for (it3 = UsedFonts.begin(); it3 != UsedFonts.end(); ++it3)
273
        {
274
                if ((*AllFonts)[it3.key()]->PrivateFont != "")
275
                        (*AllFonts).removeFont(it3.key());
276
        }
3 paul 277
        FT_Done_FreeType( library );
278
}
279
 
456 fschmid 280
/*
281
 * Split out from loadStyles in editFormats.cpp so it's callable from anywhere,
282
 * including plugins.
283
 * - 2004-09-14 Craig Ringer
284
 */
1065 cbradney 285
void ScribusDoc::loadStylesFromFile(QString fileName, QValueList<ParagraphStyle> *tempStyles)
456 fschmid 286
{
1065 cbradney 287
        // This won't create the QValueList<ParagraphStyle> will it?
288
        QValueList<ParagraphStyle> *wrkStyles = NULL;
456 fschmid 289
        /*
290
         * Use the working styles struct if passed, or work directly
291
         * on the document styles otherwise. Note that tempStyles,
292
         * if passed, MUST have the first five styles initialised already
293
         * or this function will segfault.
294
         */
295
        if (tempStyles != NULL)
296
                wrkStyles = tempStyles;
297
         else
1065 cbradney 298
                wrkStyles = &docParagraphStyles;
456 fschmid 299
        if (!fileName.isEmpty())
300
        {
301
                ScriXmlDoc *ss = new ScriXmlDoc();
1065 cbradney 302
                ss->docParagraphStyles.clear();
456 fschmid 303
                for (uint x = 5; x < wrkStyles->count(); ++x)
1065 cbradney 304
                        ss->docParagraphStyles.append((*wrkStyles)[x]);
456 fschmid 305
                uint old = wrkStyles->count()-5;
823 fschmid 306
                if (ss->ReadStyles(fileName, this, prefsValues))
456 fschmid 307
                {
1065 cbradney 308
                        if (ss->docParagraphStyles.count() > old)
456 fschmid 309
                        {
1065 cbradney 310
                                for (uint xx=old; xx<ss->docParagraphStyles.count(); ++xx)
456 fschmid 311
                                {
1065 cbradney 312
                                        struct ParagraphStyle sty;
313
                                        sty.Vname = ss->docParagraphStyles[xx].Vname;
314
                                        sty.LineSpa = ss->docParagraphStyles[xx].LineSpa;
315
                                        sty.textAlignment = ss->docParagraphStyles[xx].textAlignment;
316
                                        sty.Indent = ss->docParagraphStyles[xx].Indent;
317
                                        sty.First = ss->docParagraphStyles[xx].First;
318
                                        sty.gapBefore = ss->docParagraphStyles[xx].gapBefore;
319
                                        sty.gapAfter = ss->docParagraphStyles[xx].gapAfter;
320
                                        sty.Font = ss->docParagraphStyles[xx].Font;
321
                                        sty.FontSize = ss->docParagraphStyles[xx].FontSize;
322
                                        sty.TabValues = ss->docParagraphStyles[xx].TabValues;
323
                                        sty.Drop = ss->docParagraphStyles[xx].Drop;
324
                                        sty.DropLin = ss->docParagraphStyles[xx].DropLin;
325
                                        sty.FontEffect = ss->docParagraphStyles[xx].FontEffect;
326
                                        sty.FColor = ss->docParagraphStyles[xx].FColor;
327
                                        sty.FShade = ss->docParagraphStyles[xx].FShade;
328
                                        sty.SColor = ss->docParagraphStyles[xx].SColor;
329
                                        sty.SShade = ss->docParagraphStyles[xx].SShade;
330
                                        sty.BaseAdj = ss->docParagraphStyles[xx].BaseAdj;
456 fschmid 331
                                        wrkStyles->append(sty);
332
                                }
333
                        }
334
                }
335
                delete ss;
336
        }
337
}
338
 
1179 tsoots 339
void ScribusDoc::lockGuides(bool isLocked)
340
{
1180 tsoots 341
        if (GuideLock == isLocked)
342
                return;
1179 tsoots 343
        GuideLock = isLocked;
344
        if (UndoManager::undoEnabled())
345
        {
346
                QString name;
347
                if (isLocked)
1190 tsoots 348
                        name = Um::LockGuides;
1179 tsoots 349
                else
1190 tsoots 350
                        name = Um::UnlockGuides;
351
                SimpleState *ss = new SimpleState(name, "", Um::ILockGuides);
1179 tsoots 352
                ss->set("GUIDE_LOCK", isLocked);
353
                undoManager->action(this, ss);
354
        }
355
}
356
 
357
void ScribusDoc::restore(UndoState* state, bool isUndo)
358
{
359
        SimpleState *ss = dynamic_cast<SimpleState*>(state);
360
        if (ss)
361
        {
362
                if (ss->contains("GUIDE_LOCK"))
363
                {
364
                        if (isUndo)
365
                                GuideLock = !ss->getBool("GUIDE_LOCK");
366
                        else
367
                                GuideLock = ss->getBool("GUIDE_LOCK"); 
368
                }
369
        }
370
}
371
 
372
void ScribusDoc::setName(const QString& name)
373
{
374
        DocName = name;
375
        QString uname = name;
376
        if (name.find("/") > -1)
377
                uname = name.right(name.length() - name.findRev("/") - 1);
1190 tsoots 378
        if (uname.find(".sl") > -1)
379
                uname = uname.left(uname.findRev(".sl"));
1179 tsoots 380
        setUName(uname); // set the name for the undo object
381
}
382
 
3 paul 383
void ScribusDoc::setModified()
384
{
385
        modified = true;
386
}
387
 
388
void ScribusDoc::setUnModified()
389
{
390
        modified = false;
391
}
392
 
393
bool ScribusDoc::isModified() const
394
{
395
  return modified;
396
}
397
/** Setzt die Seitenattribute */
80 Franz 398
void ScribusDoc::setPage(double b, double h, double t, double l, double r, double bo, double sp, double ab, bool atf, bool fp)
3 paul 399
{
400
        PageB = b;
401
        PageH = h;
402
        PageM.Top = t;
403
        PageM.Left = l;
404
        PageM.Right = r;
405
        PageM.Bottom = bo;
406
        PageSp = sp;
407
        PageSpa = ab;
408
        PageFP = fp;
409
        PageAT = atf;
410
}
411
 
80 Franz 412
void ScribusDoc::resetPage(double t, double l, double r, double bo, bool fp)
3 paul 413
{
414
        PageM.Top = t;
415
        PageM.Left = l;
416
        PageM.Right = r;
417
        PageM.Bottom = bo;
418
        PageFP = fp;
419
}
420
 
220 Franz 421
bool ScribusDoc::AddFont(QString name, QFont fo)
3 paul 422
{
220 Franz 423
        bool ret = false;
424
        bool error;
3 paul 425
        FT_Face      face;
220 Franz 426
        error = FT_New_Face( library, (*AllFonts)[name]->Datei, 0, &face );
427
        if (error)
428
                return ret;
429
        if ((*AllFonts)[name]->ReadMetrics())
167 Franz 430
        {
220 Franz 431
                (*AllFonts)[name]->CharWidth[13] = 0;
249 Franz 432
                (*AllFonts)[name]->CharWidth[28] = 0;
220 Franz 433
                (*AllFonts)[name]->CharWidth[9] = 1;
434
                QString afnm = (*AllFonts)[name]->Datei.left((*AllFonts)[name]->Datei.length()-3);
435
                QFile afm(afnm+"afm");
3 paul 436
                if(!(afm.exists()))
220 Franz 437
                {
438
                        afm.setName(afnm+"Afm");
439
                        if(!(afm.exists()))
440
                                afm.setName(afnm+"AFM");
441
                }
442
                if (afm.exists())
443
                        FT_Attach_File(face, afm.name());
444
                FFonts[name] = face;
445
                UsedFonts[name] = fo;
446
                ret = true;
167 Franz 447
        }
220 Franz 448
        else
449
                FT_Done_Face( face );
450
        return ret;
3 paul 451
}