[r373]: gsoc2009 / textfilter / scribus / plugins / idmlimplugin / idmlstyles.cpp Maximize Restore History

Download this file

idmlstyles.cpp    227 lines (210 with data), 7.0 kB

  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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
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.
*/
/***************************************************************************
* Copyright (C) 2009 by Jain Basil Aliyas *
* mail@jainbasil.net *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "styles/charstyle.h"
#include "styles/paragraphstyle.h"
#include "styles/linestyle.h"
#include "idmlstyles.h"
#include <QByteArray>
#include <QXmlStreamReader>
#include <QFile>
IDMLStyles::IDMLStyles(QString &stylePath)
{
loadFile(stylePath);
}
IDMLStyles::~IDMLStyles()
{
}
void IDMLStyles::loadFile(QString &fileName)
{
QFile file(fileName);
file.open(QIODevice::ReadOnly || QIODevice::Text);
doc.setContent( fileName );
root=doc.documentElement();
file.close();
}
bool IDMLStyles::processStyleFile()
{
if(root.tagName() != "idPkg:Styles")
{
return false;
}
else
{
node = root.firstChild();
while( !node.isNull() )
{
element = node.toElement();
if(!element.isNull())
{
if( element.tagName()=="RootCharacterStyleGroup" )
getCharacterStyles();
if( element.tagName()=="RootParagraphStyleGroup")
getParagraphStyles();
if( element.tagName()=="TOCStyle")
getTOCStyles();
if( element.tagName()=="RootCellStyleGroup")
getCellStyles();
if( element.tagName()=="RootTableStyleGroup")
getTableStyles();
if( element.tagName()=="RootObjectStyleGroup")
getObjectStyles();
}
node = node.nextSibling();
}
return true;
}
}
void IDMLStyles::getCharacterStyles()
{
QDomNode icharStyle = node.firstChild();
while( !icharStyle.isNull())
{
QDomElement e = icharStyle.toElement();
if(!e.isNull())
{
QString Self = e.attribute("Self","");
cstyle.setName(e.attribute("Name",""));
cstyle.setParent(e.attribute("BasedOn",""));
cstyle.setFontSize(e.attribute("FontSize","").toDouble());
cstyle.setFillShade(e.attribute("FillTint","").toDouble());
cstyle.setStrokeShade(e.attribute("StrokeTint","").toDouble());
cstyle.setScaleH(e.attribute("HorizontalScale","").toDouble());
cstyle.setScaleV(c.vertScale=e.attribute("VerticalScale","").toDouble());
cstyle.setBaselineOffset(e.attribute("BaselineShift","").toDouble().toDouble());
cstyle.setOutlineWidth(e.attribute("StrokeWeight","").toDouble());
cstyle.setUnderlineOffset(e.attribute("UnderlineOffset","").toDouble());
cstyle.setUnderlineWidth(e.attribute("UnderlineWeight","").toDouble());
/*
c.self=e.attribute("Self","");
c.imported=(e.attribute("Imported","")=="true")?true:false;
c.fontStyle=e.attribute("FontStyle","");
c.pointSize=e.attribute("PointSize","").toDouble();
c.kerningMethod=e.attribute("KerningMethod","");
c.Tracking=e.attribute("Tracking","").toDouble();
c.underline=(e.attribute("Underline","")=="true")?true:false;
c.strikeThru=(e.attribute("StrikeThru","")=="true")?true:false;
c.BasedOn=e.attribute("BasedOn","");
c.horizScale=e.attribute("HorizontalScale","").toDouble();
c.language=e.attribute("AppliedLanguage","");
c.Name=e.attribute("Name","");
c.underlineOffset=e.attribute("UnderlineOffset","").toDouble();
c.Name=e.attribute("Name","");
c.KeyboardShortcut=e.attribute("KeyboardShortcut","");
c.underlineOffset=e.attribute("UnderlineOffset","").toDouble();
c.strikethruOffset=e.attribute("StrikethruOffset","");
c.fillColor=e.attribute("FillColor","");
c.fillTint=e.attribute("FillTint","");
c.vertScale=e.attribute("VerticalScale","").toDouble();
c.baselineShift=e.attribute("BaselineShift","").toDouble();*/
// reading the properties, if exist for this style
QDomNode property = icharStyle.firstChild();
while( !property.isNull() )
{
QDomElement e = property.toElement();
if(!e.isNull())
{
if( e.tagName()=="BasedOn")
c.BasedOn=e.text();
if( e.tagName()=="AppliedFont")
c.AppliedFont=e.text();
}
property=property.nextSibling();
}
}
icharStyle = icharStyle.nextSibling();
}
}
void IDMLStyles::getParagraphStyles()
{
QDomNode pstyle = node.firstChild();
while( !pstyle.isNull() )
{
QDomElement e = pstyle.toElement();
if(!e.isNull())
{
IDMLPStyle parStyle;
parStyle.self = e.attribute("Self","");
parStyle.Name = e.attribute("Name","");
parStyle.imported = (e.attribute("Imported","")=="true")?true:false;
parStyle.NextStyle = e.attribute("NextStyle","");
}
pstyle=pstyle.nextSibling();
}
}
void IDMLStyles::getTOCStyles()
{
QDomNode tocStyle = node.firstChild();
while( !tocStyle.isNull() )
{
QDomElement e = tocStyle.toElement();
if( !e.isNull() )
{
/* Do ajor of you toc style code here
*/
}
tocStyle=tocStyle.nextSibling();
}
}
void IDMLStyles::getCellStyles()
{
QDomNode cellStyle = node.firstChild();
while( !cellStyle.isNull() )
{
QDomElement e = cellStyle.toElement();
if( !e.isNull() )
{
/* major coding section here */
}
cellStyle=cellStyle.nextSibling();
}
}
void IDMLStyles::getTableStyles()
{
QDomNode tableStyle = node.firstChild();
while( !tableStyle.isNull() )
{
QDomElement e = tableStyle.toElement();
if( !e.isNull())
{
/* do code here
*/
}
tableStyle=tableStyle.nextSibling();
}
}
void IDMLStyles::getObjectStyles()
{
QDomNode objStyle = node.firstChild();
while( !objStyle.isNull() )
{
QDomElement e = objStyle.toElement();
if( !e.isNull() )
{
/* implement object style here */
}
objStyle=objStyle.nextSibling();
}
}