File: serializer.cpp

package info (click to toggle)
scribus 1.3.3.13.dfsg~svn20081228-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 54,668 kB
  • ctags: 14,434
  • sloc: cpp: 165,840; ansic: 8,920; python: 3,149; xml: 419; makefile: 114; perl: 94; sh: 69
file content (193 lines) | stat: -rw-r--r-- 5,083 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
                          serializer.cpp  -  description
                             -------------------
    begin                : Sat May 5 2001
    copyright            : (C) 2001 by Franz Schmid
    email                : Franz.Schmid@altmuehlnet.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "serializer.h"
#include "scribusdoc.h"
#include "pageitem.h"
#include <qfile.h>
#include <qtextstream.h>
#include <qtextcodec.h>
#include "util.h"

Serializer::Serializer(QString name)
{
	Filename = name;
	Objekt = "";
}

QString Serializer::GetObjekt()
{
	return Objekt;
}

void Serializer::PutText(PageItem *Item)
{
	uint a;
	QString Dat = "";
	QPtrList<ScText> y = Item->itemText;
	for (a=0; a<y.count(); ++a)
	{
		QString b = y.at(a)->ch;
		if (b == QChar(13))
			b = "\n";
		Dat += b;
	}
	Objekt = Dat;
}

void Serializer::GetText(PageItem *Item, int Absatz, QString font, int size, bool Append)
{
	ScText *hg;
	PageItem *nextItem;
	PageItem *it = Item;
	ScribusDoc* doku = it->document();
	uint a;
	if (!Append)
	{
		nextItem = Item;
		while (nextItem != 0)
		{
			if (nextItem->BackBox != 0)
				nextItem = nextItem->BackBox;
			else
				break;
		}
		it = nextItem;
		while (nextItem != 0)
		{
			for (ScText *it = nextItem->itemText.first(); it != 0; it = nextItem->itemText.next())
			{
				if ((it->ch == QChar(25)) && (it->cembedded != 0))
				{
					doku->FrameItems.remove(it->cembedded);
					delete it->cembedded;
				}
			}
			nextItem->itemText.clear();
			nextItem->CPos = 0;
			nextItem = nextItem->NextBox;
		}
		doku->updateFrameItems();
	}
	
	const ParagraphStyle& pstyle(doku->docParagraphStyles[Absatz]);
	uint len = Objekt.length();
	for (a=0; a < len; ++a)
	{
		QChar ch(Objekt.at(a));
		uint unicd = ch.unicode();
		if (unicd == 0 || unicd == 13)
			continue;
		if (unicd == 10 || unicd == 5)
			ch = QChar(13);
		hg = new ScText;
		hg->ch = ch;
		if (!pstyle.Font.isEmpty())
		{
			hg->cfont = (*doku->AllFonts)[pstyle.Font];
			hg->csize = pstyle.FontSize;
			hg->cstyle = pstyle.FontEffect;
			hg->ccolor = pstyle.FColor;
			hg->cshade = pstyle.FShade;
			hg->cstroke = pstyle.SColor;
			hg->cshade2 = pstyle.SShade;
			hg->cshadowx = pstyle.txtShadowX;
			hg->cshadowy = pstyle.txtShadowY;
			hg->coutline = pstyle.txtOutline;
			hg->cunderpos = pstyle.txtUnderPos;
			hg->cunderwidth = pstyle.txtUnderWidth;
			hg->cstrikepos = pstyle.txtStrikePos;
			hg->cstrikewidth = pstyle.txtStrikeWidth;
			hg->cscale = pstyle.scaleH;
			hg->cscalev = pstyle.scaleV;
			hg->cbase = pstyle.baseOff;
			hg->cextra = pstyle.kernVal;
		}
		else
		{
			hg->cfont = (*doku->AllFonts)[font];
			hg->ccolor = it->TxtFill;
			hg->cshade = it->ShTxtFill;
			hg->cstroke = it->TxtStroke;
			hg->cshade2 = it->ShTxtStroke;
			hg->csize = size;
			hg->cstyle = it->TxTStyle;
			hg->cshadowx = it->TxtShadowX;
			hg->cshadowy = it->TxtShadowY;
			hg->coutline = it->TxtOutline;
			hg->cunderpos = it->TxtUnderPos;
			hg->cunderwidth = it->TxtUnderWidth;
			hg->cstrikepos = it->TxtStrikePos;
			hg->cstrikewidth = it->TxtStrikeWidth;
			hg->cscale = it->TxtScale;
			hg->cscalev = it->TxtScaleV;
			hg->cbase = it->TxtBase;
			hg->cextra = 0;
		}
		hg->cselect = false;
		hg->cab = Absatz;
		hg->xp = 0;
		hg->yp = 0;
		hg->PRot = 0;
		hg->PtransX = 0;
		hg->PtransY = 0;
		hg->cembedded = 0;
		if (Append)
			it->itemText.insert(it->CPos, hg);
		else
			it->itemText.append(hg);
		it->CPos += 1;
	}
}

bool Serializer::Write(QString Cod)
{
	QTextCodec *codec;
	if (Cod.isEmpty())
		codec = QTextCodec::codecForLocale();
	else
		codec = QTextCodec::codecForName(Cod);
	QCString dec = codec->fromUnicode( Objekt );
	QFile f(Filename);
	bool ret = false;
	if (f.open(IO_WriteOnly))
	{
		f.writeBlock(dec, dec.length());
		f.close();
		ret = true;
	}
	return ret;
}

bool Serializer::Read(QString Cod)
{
	QCString file;
	QTextCodec *codec;
	bool tmp = loadRawText(Filename, file);
	if (Cod.isEmpty())
		codec = QTextCodec::codecForLocale();
	else
		codec = QTextCodec::codecForName(Cod);
	Objekt = codec->toUnicode( file.data() );
	return tmp;
}