Rev 455 | Rev 547 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | paul | 1 | /*************************************************************************** |
2 | serializer.cpp - description |
||
3 | ------------------- |
||
4 | begin : Sat May 5 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 "serializer.h" |
||
217 | Franz | 19 | #include "scribusdoc.h" |
456 | fschmid | 20 | #include "pageitem.h" |
3 | paul | 21 | #include <qfile.h> |
22 | #include <qtextstream.h> |
||
23 | #include <qtextcodec.h> |
||
24 | extern bool loadText(QString nam, QString *Buffer); |
||
25 | Serializer::Serializer(QString name) |
||
26 | { |
||
27 | Filename = name; |
||
28 | Objekt = ""; |
||
29 | } |
||
30 | |||
31 | QString Serializer::GetObjekt() |
||
32 | { |
||
33 | return Objekt; |
||
34 | } |
||
35 | |||
36 | void Serializer::PutText(PageItem *Item) |
||
37 | { |
||
167 | Franz | 38 | uint a; |
39 | QString Dat = ""; |
||
3 | paul | 40 | QPtrList<Pti> y = Item->Ptext; |
167 | Franz | 41 | for (a=0; a<y.count(); ++a) |
217 | Franz | 42 | { |
3 | paul | 43 | QString b = y.at(a)->ch; |
44 | if (b == QChar(13)) |
||
45 | b = "\n"; |
||
217 | Franz | 46 | Dat += b; |
47 | } |
||
19 | Franz | 48 | Objekt = Dat; |
3 | paul | 49 | } |
50 | |||
24 | Franz | 51 | void Serializer::GetText(PageItem *Item, int Absatz, QString font, int size, bool Append) |
3 | paul | 52 | { |
53 | struct Pti *hg; |
||
54 | PageItem *nb; |
||
105 | Franz | 55 | PageItem *it = Item; |
456 | fschmid | 56 | ScribusDoc* doku = it->Doc; |
3 | paul | 57 | uint a; |
58 | if (!Append) |
||
167 | Franz | 59 | { |
105 | Franz | 60 | nb = Item; |
61 | while (nb != 0) |
||
167 | Franz | 62 | { |
105 | Franz | 63 | if (nb->BackBox != 0) |
64 | nb = nb->BackBox; |
||
65 | else |
||
66 | break; |
||
167 | Franz | 67 | } |
105 | Franz | 68 | it = nb; |
69 | while (nb != 0) |
||
167 | Franz | 70 | { |
105 | Franz | 71 | nb->Ptext.clear(); |
72 | nb->CPos = 0; |
||
73 | nb = nb->NextBox; |
||
3 | paul | 74 | } |
167 | Franz | 75 | } |
3 | paul | 76 | for (a=0; a<Objekt.length(); ++a) |
167 | Franz | 77 | { |
105 | Franz | 78 | if ((Objekt.at(a) == QChar(0)) || (Objekt.at(a) == QChar(13))) |
79 | continue; |
||
80 | hg = new Pti; |
||
81 | hg->ch = Objekt.at(a); |
||
82 | if ((hg->ch == QChar(10)) || (hg->ch == QChar(5))) |
||
83 | hg->ch = QChar(13); |
||
217 | Franz | 84 | if (doku->Vorlagen[Absatz].Font != "") |
85 | { |
||
86 | hg->cfont = doku->Vorlagen[Absatz].Font; |
||
87 | hg->csize = doku->Vorlagen[Absatz].FontSize; |
||
88 | hg->cstyle = doku->Vorlagen[Absatz].FontEffect; |
||
89 | hg->ccolor = doku->Vorlagen[Absatz].FColor; |
||
90 | hg->cshade = doku->Vorlagen[Absatz].FShade; |
||
91 | hg->cstroke = doku->Vorlagen[Absatz].SColor; |
||
92 | hg->cshade2 = doku->Vorlagen[Absatz].SShade; |
||
93 | } |
||
94 | else |
||
95 | { |
||
96 | hg->cfont = it->IFont; |
||
97 | hg->ccolor = it->TxtFill; |
||
98 | hg->cshade = it->ShTxtFill; |
||
99 | hg->cstroke = it->TxtStroke; |
||
100 | hg->cshade2 = it->ShTxtStroke; |
||
101 | hg->csize = it->ISize; |
||
102 | hg->cstyle = it->TxTStyle; |
||
103 | } |
||
105 | Franz | 104 | hg->cscale = it->TxtScale; |
3 | paul | 105 | hg->cextra = 0; |
106 | hg->cselect = false; |
||
217 | Franz | 107 | hg->cab = Absatz; |
3 | paul | 108 | hg->xp = 0; |
109 | hg->yp = 0; |
||
110 | hg->PRot = 0; |
||
111 | hg->PtransX = 0; |
||
112 | hg->PtransY = 0; |
||
113 | if (Append) |
||
217 | Franz | 114 | it->Ptext.insert(it->CPos, hg); |
3 | paul | 115 | else |
105 | Franz | 116 | it->Ptext.append(hg); |
217 | Franz | 117 | it->CPos += 1; |
118 | } |
||
3 | paul | 119 | } |
120 | |||
19 | Franz | 121 | bool Serializer::Write(QString Cod) |
3 | paul | 122 | { |
19 | Franz | 123 | QTextCodec *codec; |
124 | if (Cod == "") |
||
125 | codec = QTextCodec::codecForLocale(); |
||
126 | else |
||
127 | codec = QTextCodec::codecForName(Cod); |
||
167 | Franz | 128 | QCString dec = codec->fromUnicode( Objekt ); |
3 | paul | 129 | QFile f(Filename); |
130 | bool ret = false; |
||
131 | if (f.open(IO_WriteOnly)) |
||
167 | Franz | 132 | { |
19 | Franz | 133 | f.writeBlock(dec, dec.length()); |
3 | paul | 134 | f.close(); |
135 | ret = true; |
||
167 | Franz | 136 | } |
3 | paul | 137 | return ret; |
138 | } |
||
139 | |||
15 | Franz | 140 | bool Serializer::Read(QString Cod) |
3 | paul | 141 | { |
15 | Franz | 142 | QTextCodec *codec; |
3 | paul | 143 | bool tmp = loadText(Filename, &Objekt); |
15 | Franz | 144 | if (Cod == "") |
145 | codec = QTextCodec::codecForLocale(); |
||
146 | else |
||
147 | codec = QTextCodec::codecForName(Cod); |
||
167 | Franz | 148 | QString dec = codec->toUnicode( Objekt ); |
15 | Franz | 149 | Objekt = dec; |
3 | paul | 150 | return tmp; |
151 | } |