Subversion Repositories Scribus

Rev

Rev 1194 | Rev 1261 | 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;
1235 fschmid 112
        checkerSettings.ignoreErrors = prefsData->checkerSettings.ignoreErrors;
113
        checkerSettings.autoCheck = prefsData->checkerSettings.autoCheck;
114
        checkerSettings.checkGlyphs = prefsData->checkerSettings.checkGlyphs;
115
        checkerSettings.checkOrphans = prefsData->checkerSettings.checkOrphans;
116
        checkerSettings.checkOverflow = prefsData->checkerSettings.checkOverflow;
117
        checkerSettings.checkPictures = prefsData->checkerSettings.checkPictures;
118
        checkerSettings.checkResolution = prefsData->checkerSettings.checkResolution;
119
        checkerSettings.checkTransparency = prefsData->checkerSettings.checkTransparency;
120
        checkerSettings.minResolution = prefsData->checkerSettings.minResolution;
1065 cbradney 121
        docUnitIndex = prefsData->docUnitIndex;
122
        marginColored = prefsData->marginColored;
823 fschmid 123
        Language = prefsData->Language;
124
        MinWordLen = prefsData->MinWordLen;
125
        HyCount = prefsData->HyCount;
126
        Automatic = prefsData->Automatic;
127
        AutoCheck = prefsData->AutoCheck;
3 paul 128
        GuideLock = false;
129
        SnapGuides = false;
167 Franz 130
        useRaster = false;
131
        EditClip = false;
132
        EditClipMode = 0;
133
        loading = false;
178 Franz 134
        DocName = QObject::tr("Document")+"-";
3 paul 135
        CurrentSel = -1;
136
        DocTitel = "";
137
        DocAutor = "";
138
        DocComments = "";
68 Franz 139
        DocKeyWords = "";
330 Franz 140
        DocPublisher = "";
141
        DocDate = "";
142
        DocType = "";
143
        DocFormat = "";
144
        DocIdent = "";
145
        DocSource = "";
146
        DocLangInfo = "";
147
        DocRelation = "";
148
        DocCover = "";
149
        DocRights = "";
150
        DocContrib = "";
3 paul 151
        PageC = 0;
152
        LastAuto = 0;
153
        FirstAuto = 0;
154
        DraggedElem = 0;
155
        GroupCounter = 1;
1065 cbradney 156
        docParagraphStyles.clear();
157
        struct ParagraphStyle vg;
3 paul 158
        vg.Vname = "Normal Internal";
159
        vg.LineSpa = 15;
1065 cbradney 160
        vg.textAlignment = 0;
3 paul 161
        vg.Indent = 0;
162
        vg.First = 0;
1065 cbradney 163
        vg.gapBefore = 0;
164
        vg.gapAfter = 0;
3 paul 165
        vg.Font = "";
1194 fschmid 166
        vg.FontSize = toolSettings.defSize;
140 Franz 167
        vg.TabValues.clear();
153 Franz 168
        vg.Drop = false;
169
        vg.DropLin = 2;
173 Franz 170
        vg.FontEffect = 0;
1194 fschmid 171
        vg.FColor = toolSettings.dBrush;
172
        vg.FShade = toolSettings.dShade;
173
        vg.SColor = toolSettings.dPen;
174
        vg.SShade = toolSettings.dShade2;
241 Franz 175
        vg.BaseAdj = false;
1065 cbradney 176
        docParagraphStyles.append(vg);
3 paul 177
        vg.Vname = "Center Internal";
1065 cbradney 178
        vg.textAlignment = 1;
179
        docParagraphStyles.append(vg);
3 paul 180
        vg.Vname = "Rechts Internal";
1065 cbradney 181
        vg.textAlignment = 2;
182
        docParagraphStyles.append(vg);
3 paul 183
        vg.Vname = "Block Internal";
1065 cbradney 184
        vg.textAlignment = 3;
185
        docParagraphStyles.append(vg);
3 paul 186
        vg.Vname = "EBlock Internal";
1065 cbradney 187
        vg.textAlignment = 4;
188
        docParagraphStyles.append(vg);
3 paul 189
        Layers.clear();
190
        struct Layer ll;
191
        ll.LNr = 0;
192
        ll.Level = 0;
178 Franz 193
        ll.Name = QObject::tr("Background");
1065 cbradney 194
        ll.isViewable = true;
195
        ll.isPrintable = true;
3 paul 196
        Layers.append(ll);
197
        ActiveLayer = 0;
198
        JavaScripts.clear();
167 Franz 199
        CurrentStyle = 0;
1065 cbradney 200
        currentParaStyle = 0;
3 paul 201
        TotalItems = 0;
202
        TemplateMode = false;
203
        PDF_Optionen.Thumbnails = false;
204
        PDF_Optionen.Articles = false;
205
        PDF_Optionen.Compress = true;
202 Franz 206
        PDF_Optionen.CompressMethod = 0;
207
        PDF_Optionen.Quality = 0;
3 paul 208
        PDF_Optionen.RecalcPic = false;
209
        PDF_Optionen.Bookmarks = false;
210
        PDF_Optionen.PicRes = 300;
203 Franz 211
        PDF_Optionen.Version = 14;
3 paul 212
        PDF_Optionen.Resolution = 300;
213
        PDF_Optionen.Binding = 0;
214
        PDF_Optionen.EmbedList.clear();
476 fschmid 215
        PDF_Optionen.SubsetList.clear();
420 Franz 216
        PDF_Optionen.MirrorH = false;
469 fschmid 217
        PDF_Optionen.MirrorV = false;
454 fschmid 218
        PDF_Optionen.RotateDeg = 0;
3 paul 219
        PDF_Optionen.PresentMode = false;
220
        PDF_Optionen.Datei = "";
221
        PDF_Optionen.PresentVals.clear();
203 Franz 222
        PDF_Optionen.UseRGB = true;
3 paul 223
        PDF_Optionen.UseProfiles = false;
224
        PDF_Optionen.UseProfiles2 = false;
225
        PDF_Optionen.SolidProf = "";
226
        PDF_Optionen.SComp = 3;
227
        PDF_Optionen.ImageProf = "";
228
        PDF_Optionen.PrintProf = "";
229
        PDF_Optionen.Info = "";
230
        PDF_Optionen.Intent = 0;
231
        PDF_Optionen.Intent2 = 0;
232
        PDF_Optionen.BleedTop = 0;
233
        PDF_Optionen.BleedLeft = 0;
234
        PDF_Optionen.BleedRight = 0;
235
        PDF_Optionen.BleedBottom = 0;
236
        PDF_Optionen.EmbeddedI = false;
237
        PDF_Optionen.Encrypt = false;
238
        PDF_Optionen.PassOwner = "";
239
        PDF_Optionen.PassUser = "";
240
        PDF_Optionen.Permissions = -4;
337 Franz 241
        PDF_Optionen.UseLPI = false;
242
        PDF_Optionen.LPISettings.clear();
3 paul 243
        RePos = false;
244
        BookMarks.clear();
245
        OldBM = false;
246
        hasName = false;
63 Franz 247
        DoDrawing = true;
3 paul 248
        RotMode = 0;
123 Franz 249
        SubMode = -1;
3 paul 250
        ASaveTimer = new QTimer(this);
27 Franz 251
        MLineStyles.clear();
456 fschmid 252
        Pages.clear();
253
        MasterPages.clear();
254
        DocPages.clear();
255
        Items.clear();
256
        MasterItems.clear();
257
        DocItems.clear();
823 fschmid 258
        ScratchLeft = prefsData->ScratchLeft;
259
        ScratchRight = prefsData->ScratchRight;
260
        ScratchTop = prefsData->ScratchTop;
261
        ScratchBottom = prefsData->ScratchBottom;
262
        arrowStyles = prefsData->arrowStyles;
1179 tsoots 263
        undoManager = UndoManager::instance();
1235 fschmid 264
        docItemErrors.clear();
265
        masterItemErrors.clear();
3 paul 266
}
267
 
268
ScribusDoc::~ScribusDoc()
269
{
456 fschmid 270
        MasterItems.setAutoDelete(true);
271
        DocItems.setAutoDelete(true);
272
        MasterItems.clear();
273
        DocItems.clear();
274
        MasterPages.setAutoDelete(true);
275
        DocPages.setAutoDelete(true);
276
        MasterPages.clear();
277
        DocPages.clear();
494 fschmid 278
        QMap<QString,QFont>::Iterator it3;
279
        for (it3 = UsedFonts.begin(); it3 != UsedFonts.end(); ++it3)
280
        {
281
                if ((*AllFonts)[it3.key()]->PrivateFont != "")
282
                        (*AllFonts).removeFont(it3.key());
283
        }
3 paul 284
        FT_Done_FreeType( library );
285
}
286
 
456 fschmid 287
/*
288
 * Split out from loadStyles in editFormats.cpp so it's callable from anywhere,
289
 * including plugins.
290
 * - 2004-09-14 Craig Ringer
291
 */
1065 cbradney 292
void ScribusDoc::loadStylesFromFile(QString fileName, QValueList<ParagraphStyle> *tempStyles)
456 fschmid 293
{
1065 cbradney 294
        // This won't create the QValueList<ParagraphStyle> will it?
295
        QValueList<ParagraphStyle> *wrkStyles = NULL;
456 fschmid 296
        /*
297
         * Use the working styles struct if passed, or work directly
298
         * on the document styles otherwise. Note that tempStyles,
299
         * if passed, MUST have the first five styles initialised already
300
         * or this function will segfault.
301
         */
302
        if (tempStyles != NULL)
303
                wrkStyles = tempStyles;
304
         else
1065 cbradney 305
                wrkStyles = &docParagraphStyles;
456 fschmid 306
        if (!fileName.isEmpty())
307
        {
308
                ScriXmlDoc *ss = new ScriXmlDoc();
1065 cbradney 309
                ss->docParagraphStyles.clear();
456 fschmid 310
                for (uint x = 5; x < wrkStyles->count(); ++x)
1065 cbradney 311
                        ss->docParagraphStyles.append((*wrkStyles)[x]);
456 fschmid 312
                uint old = wrkStyles->count()-5;
823 fschmid 313
                if (ss->ReadStyles(fileName, this, prefsValues))
456 fschmid 314
                {
1065 cbradney 315
                        if (ss->docParagraphStyles.count() > old)
456 fschmid 316
                        {
1065 cbradney 317
                                for (uint xx=old; xx<ss->docParagraphStyles.count(); ++xx)
456 fschmid 318
                                {
1065 cbradney 319
                                        struct ParagraphStyle sty;
320
                                        sty.Vname = ss->docParagraphStyles[xx].Vname;
321
                                        sty.LineSpa = ss->docParagraphStyles[xx].LineSpa;
322
                                        sty.textAlignment = ss->docParagraphStyles[xx].textAlignment;
323
                                        sty.Indent = ss->docParagraphStyles[xx].Indent;
324
                                        sty.First = ss->docParagraphStyles[xx].First;
325
                                        sty.gapBefore = ss->docParagraphStyles[xx].gapBefore;
326
                                        sty.gapAfter = ss->docParagraphStyles[xx].gapAfter;
327
                                        sty.Font = ss->docParagraphStyles[xx].Font;
328
                                        sty.FontSize = ss->docParagraphStyles[xx].FontSize;
329
                                        sty.TabValues = ss->docParagraphStyles[xx].TabValues;
330
                                        sty.Drop = ss->docParagraphStyles[xx].Drop;
331
                                        sty.DropLin = ss->docParagraphStyles[xx].DropLin;
332
                                        sty.FontEffect = ss->docParagraphStyles[xx].FontEffect;
333
                                        sty.FColor = ss->docParagraphStyles[xx].FColor;
334
                                        sty.FShade = ss->docParagraphStyles[xx].FShade;
335
                                        sty.SColor = ss->docParagraphStyles[xx].SColor;
336
                                        sty.SShade = ss->docParagraphStyles[xx].SShade;
337
                                        sty.BaseAdj = ss->docParagraphStyles[xx].BaseAdj;
456 fschmid 338
                                        wrkStyles->append(sty);
339
                                }
340
                        }
341
                }
342
                delete ss;
343
        }
344
}
345
 
1179 tsoots 346
void ScribusDoc::lockGuides(bool isLocked)
347
{
1180 tsoots 348
        if (GuideLock == isLocked)
349
                return;
1179 tsoots 350
        GuideLock = isLocked;
351
        if (UndoManager::undoEnabled())
352
        {
353
                QString name;
354
                if (isLocked)
1190 tsoots 355
                        name = Um::LockGuides;
1179 tsoots 356
                else
1190 tsoots 357
                        name = Um::UnlockGuides;
358
                SimpleState *ss = new SimpleState(name, "", Um::ILockGuides);
1179 tsoots 359
                ss->set("GUIDE_LOCK", isLocked);
360
                undoManager->action(this, ss);
361
        }
362
}
363
 
364
void ScribusDoc::restore(UndoState* state, bool isUndo)
365
{
366
        SimpleState *ss = dynamic_cast<SimpleState*>(state);
367
        if (ss)
368
        {
369
                if (ss->contains("GUIDE_LOCK"))
370
                {
371
                        if (isUndo)
372
                                GuideLock = !ss->getBool("GUIDE_LOCK");
373
                        else
374
                                GuideLock = ss->getBool("GUIDE_LOCK"); 
375
                }
376
        }
377
}
378
 
379
void ScribusDoc::setName(const QString& name)
380
{
381
        DocName = name;
382
        QString uname = name;
383
        if (name.find("/") > -1)
384
                uname = name.right(name.length() - name.findRev("/") - 1);
1190 tsoots 385
        if (uname.find(".sl") > -1)
386
                uname = uname.left(uname.findRev(".sl"));
1179 tsoots 387
        setUName(uname); // set the name for the undo object
388
}
389
 
3 paul 390
void ScribusDoc::setModified()
391
{
392
        modified = true;
393
}
394
 
395
void ScribusDoc::setUnModified()
396
{
397
        modified = false;
398
}
399
 
400
bool ScribusDoc::isModified() const
401
{
402
  return modified;
403
}
404
/** Setzt die Seitenattribute */
80 Franz 405
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 406
{
407
        PageB = b;
408
        PageH = h;
409
        PageM.Top = t;
410
        PageM.Left = l;
411
        PageM.Right = r;
412
        PageM.Bottom = bo;
413
        PageSp = sp;
414
        PageSpa = ab;
415
        PageFP = fp;
416
        PageAT = atf;
417
}
418
 
80 Franz 419
void ScribusDoc::resetPage(double t, double l, double r, double bo, bool fp)
3 paul 420
{
421
        PageM.Top = t;
422
        PageM.Left = l;
423
        PageM.Right = r;
424
        PageM.Bottom = bo;
425
        PageFP = fp;
426
}
427
 
220 Franz 428
bool ScribusDoc::AddFont(QString name, QFont fo)
3 paul 429
{
220 Franz 430
        bool ret = false;
431
        bool error;
3 paul 432
        FT_Face      face;
220 Franz 433
        error = FT_New_Face( library, (*AllFonts)[name]->Datei, 0, &face );
434
        if (error)
435
                return ret;
436
        if ((*AllFonts)[name]->ReadMetrics())
167 Franz 437
        {
220 Franz 438
                (*AllFonts)[name]->CharWidth[13] = 0;
249 Franz 439
                (*AllFonts)[name]->CharWidth[28] = 0;
220 Franz 440
                (*AllFonts)[name]->CharWidth[9] = 1;
441
                QString afnm = (*AllFonts)[name]->Datei.left((*AllFonts)[name]->Datei.length()-3);
442
                QFile afm(afnm+"afm");
3 paul 443
                if(!(afm.exists()))
220 Franz 444
                {
445
                        afm.setName(afnm+"Afm");
446
                        if(!(afm.exists()))
447
                                afm.setName(afnm+"AFM");
448
                }
449
                if (afm.exists())
450
                        FT_Attach_File(face, afm.name());
451
                FFonts[name] = face;
452
                UsedFonts[name] = fo;
453
                ret = true;
167 Franz 454
        }
220 Franz 455
        else
456
                FT_Done_Face( face );
457
        return ret;
3 paul 458
}