Subversion Repositories Scribus

Rev

Rev 1190 | Rev 1235 | 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;
1065 cbradney 112
        docUnitIndex = prefsData->docUnitIndex;
113
        marginColored = prefsData->marginColored;
823 fschmid 114
        Language = prefsData->Language;
115
        MinWordLen = prefsData->MinWordLen;
116
        HyCount = prefsData->HyCount;
117
        Automatic = prefsData->Automatic;
118
        AutoCheck = prefsData->AutoCheck;
3 paul 119
        GuideLock = false;
120
        SnapGuides = false;
167 Franz 121
        useRaster = false;
122
        EditClip = false;
123
        EditClipMode = 0;
124
        loading = false;
178 Franz 125
        DocName = QObject::tr("Document")+"-";
3 paul 126
        CurrentSel = -1;
127
        DocTitel = "";
128
        DocAutor = "";
129
        DocComments = "";
68 Franz 130
        DocKeyWords = "";
330 Franz 131
        DocPublisher = "";
132
        DocDate = "";
133
        DocType = "";
134
        DocFormat = "";
135
        DocIdent = "";
136
        DocSource = "";
137
        DocLangInfo = "";
138
        DocRelation = "";
139
        DocCover = "";
140
        DocRights = "";
141
        DocContrib = "";
3 paul 142
        PageC = 0;
143
        LastAuto = 0;
144
        FirstAuto = 0;
145
        DraggedElem = 0;
146
        GroupCounter = 1;
1065 cbradney 147
        docParagraphStyles.clear();
148
        struct ParagraphStyle vg;
3 paul 149
        vg.Vname = "Normal Internal";
150
        vg.LineSpa = 15;
1065 cbradney 151
        vg.textAlignment = 0;
3 paul 152
        vg.Indent = 0;
153
        vg.First = 0;
1065 cbradney 154
        vg.gapBefore = 0;
155
        vg.gapAfter = 0;
3 paul 156
        vg.Font = "";
1194 fschmid 157
        vg.FontSize = toolSettings.defSize;
140 Franz 158
        vg.TabValues.clear();
153 Franz 159
        vg.Drop = false;
160
        vg.DropLin = 2;
173 Franz 161
        vg.FontEffect = 0;
1194 fschmid 162
        vg.FColor = toolSettings.dBrush;
163
        vg.FShade = toolSettings.dShade;
164
        vg.SColor = toolSettings.dPen;
165
        vg.SShade = toolSettings.dShade2;
241 Franz 166
        vg.BaseAdj = false;
1065 cbradney 167
        docParagraphStyles.append(vg);
3 paul 168
        vg.Vname = "Center Internal";
1065 cbradney 169
        vg.textAlignment = 1;
170
        docParagraphStyles.append(vg);
3 paul 171
        vg.Vname = "Rechts Internal";
1065 cbradney 172
        vg.textAlignment = 2;
173
        docParagraphStyles.append(vg);
3 paul 174
        vg.Vname = "Block Internal";
1065 cbradney 175
        vg.textAlignment = 3;
176
        docParagraphStyles.append(vg);
3 paul 177
        vg.Vname = "EBlock Internal";
1065 cbradney 178
        vg.textAlignment = 4;
179
        docParagraphStyles.append(vg);
3 paul 180
        Layers.clear();
181
        struct Layer ll;
182
        ll.LNr = 0;
183
        ll.Level = 0;
178 Franz 184
        ll.Name = QObject::tr("Background");
1065 cbradney 185
        ll.isViewable = true;
186
        ll.isPrintable = true;
3 paul 187
        Layers.append(ll);
188
        ActiveLayer = 0;
189
        JavaScripts.clear();
190
        UnDoValid = false;
191
        UnData.UnCode = -1;
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();
3 paul 257
}
258
 
259
ScribusDoc::~ScribusDoc()
260
{
456 fschmid 261
        MasterItems.setAutoDelete(true);
262
        DocItems.setAutoDelete(true);
263
        MasterItems.clear();
264
        DocItems.clear();
265
        MasterPages.setAutoDelete(true);
266
        DocPages.setAutoDelete(true);
267
        MasterPages.clear();
268
        DocPages.clear();
494 fschmid 269
        QMap<QString,QFont>::Iterator it3;
270
        for (it3 = UsedFonts.begin(); it3 != UsedFonts.end(); ++it3)
271
        {
272
                if ((*AllFonts)[it3.key()]->PrivateFont != "")
273
                        (*AllFonts).removeFont(it3.key());
274
        }
3 paul 275
        FT_Done_FreeType( library );
276
}
277
 
456 fschmid 278
/*
279
 * Split out from loadStyles in editFormats.cpp so it's callable from anywhere,
280
 * including plugins.
281
 * - 2004-09-14 Craig Ringer
282
 */
1065 cbradney 283
void ScribusDoc::loadStylesFromFile(QString fileName, QValueList<ParagraphStyle> *tempStyles)
456 fschmid 284
{
1065 cbradney 285
        // This won't create the QValueList<ParagraphStyle> will it?
286
        QValueList<ParagraphStyle> *wrkStyles = NULL;
456 fschmid 287
        /*
288
         * Use the working styles struct if passed, or work directly
289
         * on the document styles otherwise. Note that tempStyles,
290
         * if passed, MUST have the first five styles initialised already
291
         * or this function will segfault.
292
         */
293
        if (tempStyles != NULL)
294
                wrkStyles = tempStyles;
295
         else
1065 cbradney 296
                wrkStyles = &docParagraphStyles;
456 fschmid 297
        if (!fileName.isEmpty())
298
        {
299
                ScriXmlDoc *ss = new ScriXmlDoc();
1065 cbradney 300
                ss->docParagraphStyles.clear();
456 fschmid 301
                for (uint x = 5; x < wrkStyles->count(); ++x)
1065 cbradney 302
                        ss->docParagraphStyles.append((*wrkStyles)[x]);
456 fschmid 303
                uint old = wrkStyles->count()-5;
823 fschmid 304
                if (ss->ReadStyles(fileName, this, prefsValues))
456 fschmid 305
                {
1065 cbradney 306
                        if (ss->docParagraphStyles.count() > old)
456 fschmid 307
                        {
1065 cbradney 308
                                for (uint xx=old; xx<ss->docParagraphStyles.count(); ++xx)
456 fschmid 309
                                {
1065 cbradney 310
                                        struct ParagraphStyle sty;
311
                                        sty.Vname = ss->docParagraphStyles[xx].Vname;
312
                                        sty.LineSpa = ss->docParagraphStyles[xx].LineSpa;
313
                                        sty.textAlignment = ss->docParagraphStyles[xx].textAlignment;
314
                                        sty.Indent = ss->docParagraphStyles[xx].Indent;
315
                                        sty.First = ss->docParagraphStyles[xx].First;
316
                                        sty.gapBefore = ss->docParagraphStyles[xx].gapBefore;
317
                                        sty.gapAfter = ss->docParagraphStyles[xx].gapAfter;
318
                                        sty.Font = ss->docParagraphStyles[xx].Font;
319
                                        sty.FontSize = ss->docParagraphStyles[xx].FontSize;
320
                                        sty.TabValues = ss->docParagraphStyles[xx].TabValues;
321
                                        sty.Drop = ss->docParagraphStyles[xx].Drop;
322
                                        sty.DropLin = ss->docParagraphStyles[xx].DropLin;
323
                                        sty.FontEffect = ss->docParagraphStyles[xx].FontEffect;
324
                                        sty.FColor = ss->docParagraphStyles[xx].FColor;
325
                                        sty.FShade = ss->docParagraphStyles[xx].FShade;
326
                                        sty.SColor = ss->docParagraphStyles[xx].SColor;
327
                                        sty.SShade = ss->docParagraphStyles[xx].SShade;
328
                                        sty.BaseAdj = ss->docParagraphStyles[xx].BaseAdj;
456 fschmid 329
                                        wrkStyles->append(sty);
330
                                }
331
                        }
332
                }
333
                delete ss;
334
        }
335
}
336
 
1179 tsoots 337
void ScribusDoc::lockGuides(bool isLocked)
338
{
1180 tsoots 339
        if (GuideLock == isLocked)
340
                return;
1179 tsoots 341
        GuideLock = isLocked;
342
        if (UndoManager::undoEnabled())
343
        {
344
                QString name;
345
                if (isLocked)
1190 tsoots 346
                        name = Um::LockGuides;
1179 tsoots 347
                else
1190 tsoots 348
                        name = Um::UnlockGuides;
349
                SimpleState *ss = new SimpleState(name, "", Um::ILockGuides);
1179 tsoots 350
                ss->set("GUIDE_LOCK", isLocked);
351
                undoManager->action(this, ss);
352
        }
353
}
354
 
355
void ScribusDoc::restore(UndoState* state, bool isUndo)
356
{
357
        SimpleState *ss = dynamic_cast<SimpleState*>(state);
358
        if (ss)
359
        {
360
                if (ss->contains("GUIDE_LOCK"))
361
                {
362
                        if (isUndo)
363
                                GuideLock = !ss->getBool("GUIDE_LOCK");
364
                        else
365
                                GuideLock = ss->getBool("GUIDE_LOCK"); 
366
                }
367
        }
368
}
369
 
370
void ScribusDoc::setName(const QString& name)
371
{
372
        DocName = name;
373
        QString uname = name;
374
        if (name.find("/") > -1)
375
                uname = name.right(name.length() - name.findRev("/") - 1);
1190 tsoots 376
        if (uname.find(".sl") > -1)
377
                uname = uname.left(uname.findRev(".sl"));
1179 tsoots 378
        setUName(uname); // set the name for the undo object
379
}
380
 
3 paul 381
void ScribusDoc::setModified()
382
{
383
        modified = true;
384
}
385
 
386
void ScribusDoc::setUnModified()
387
{
388
        modified = false;
389
}
390
 
391
bool ScribusDoc::isModified() const
392
{
393
  return modified;
394
}
395
/** Setzt die Seitenattribute */
80 Franz 396
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 397
{
398
        PageB = b;
399
        PageH = h;
400
        PageM.Top = t;
401
        PageM.Left = l;
402
        PageM.Right = r;
403
        PageM.Bottom = bo;
404
        PageSp = sp;
405
        PageSpa = ab;
406
        PageFP = fp;
407
        PageAT = atf;
408
}
409
 
80 Franz 410
void ScribusDoc::resetPage(double t, double l, double r, double bo, bool fp)
3 paul 411
{
412
        PageM.Top = t;
413
        PageM.Left = l;
414
        PageM.Right = r;
415
        PageM.Bottom = bo;
416
        PageFP = fp;
417
}
418
 
220 Franz 419
bool ScribusDoc::AddFont(QString name, QFont fo)
3 paul 420
{
220 Franz 421
        bool ret = false;
422
        bool error;
3 paul 423
        FT_Face      face;
220 Franz 424
        error = FT_New_Face( library, (*AllFonts)[name]->Datei, 0, &face );
425
        if (error)
426
                return ret;
427
        if ((*AllFonts)[name]->ReadMetrics())
167 Franz 428
        {
220 Franz 429
                (*AllFonts)[name]->CharWidth[13] = 0;
249 Franz 430
                (*AllFonts)[name]->CharWidth[28] = 0;
220 Franz 431
                (*AllFonts)[name]->CharWidth[9] = 1;
432
                QString afnm = (*AllFonts)[name]->Datei.left((*AllFonts)[name]->Datei.length()-3);
433
                QFile afm(afnm+"afm");
3 paul 434
                if(!(afm.exists()))
220 Franz 435
                {
436
                        afm.setName(afnm+"Afm");
437
                        if(!(afm.exists()))
438
                                afm.setName(afnm+"AFM");
439
                }
440
                if (afm.exists())
441
                        FT_Attach_File(face, afm.name());
442
                FFonts[name] = face;
443
                UsedFonts[name] = fo;
444
                ret = true;
167 Franz 445
        }
220 Franz 446
        else
447
                FT_Done_Face( face );
448
        return ret;
3 paul 449
}