00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdlib.h>
00023 #include <kdebug.h>
00024 #include "textFrame.h"
00025
00026
00027
00028
00029 TextFrame::TextFrame()
00030 {
00031 _left = 0;
00032 _right = 0;
00033 _top = 0;
00034 _bottom = 0;
00035 _runaround = TA_NONE;
00036 _runaroundGap = 0;
00037 _autoCreate = TC_EXTEND;
00038 _newFrameBehaviour = TF_RECONNECT;
00039 _sheetSide = TS_ANYSIDE;
00040
00041
00042 setType(ST_TEXT);
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 void TextFrame::analyse(const QDomNode balise)
00065 {
00066
00067
00068
00069 Element::analyse(balise);
00070
00071 kdDebug(30522) << "FRAME ANALYSE (TextFrame)" << endl;
00072
00073
00074 analyseParamFrame(getChild(balise, "FRAME"));
00075
00076 for(int index = 0; index < getNbChild(balise); index++)
00077 {
00078 if(getChildName(balise, index).compare("PARAGRAPH")== 0)
00079 {
00080
00081 Para *prg = new Para(this);
00082
00083 prg->analyse(getChild(balise, index));
00084 if(prg->getInfo() == EP_FOOTNOTE)
00085 {
00086
00087
00088
00089
00090 }
00091 else
00092 {
00093
00094 _parags.append(prg);
00095 }
00096 kdDebug(30522) << "PARA ADDED" << endl;
00097 }
00098
00099 }
00100 kdDebug(30522) << "END OF A FRAME ANALYSE" << endl;
00101 }
00102
00103
00104
00105
00106 void TextFrame::analyseParamFrame(const QDomNode balise)
00107 {
00108
00109 setLeft(getAttr(balise, "left").toDouble());
00110 setTop(getAttr(balise, "top").toDouble());
00111 setRight(getAttr(balise, "right").toDouble());
00112 setBottom(getAttr(balise, "bottom").toDouble());
00113 setRunAround(getAttr(balise, "runaround").toInt());
00114 setAroundGap(getAttr(balise, "runaroundGap").toInt());
00115 setAutoCreate(getAttr(balise, "autoCreateNewFrame").toInt());
00116 setNewFrame(getAttr(balise, "newFrameBehaviour").toInt());
00117 setSheetSide(getAttr(balise, "sheetSide").toInt());
00118 if(getAttr(balise, "lWidth").toInt() > 0)
00119 {
00120 setLeftWidth(getAttr(balise, "lWidth").toInt());
00121 useLeftBorder();
00122 }
00123 if(getAttr(balise, "rWidth").toInt() > 0)
00124 {
00125 setRightWidth(getAttr(balise, "rWidth").toInt());
00126 useRightBorder();
00127 }
00128 if(getAttr(balise, "tWidth").toInt() > 0)
00129 {
00130 setTopWidth(getAttr(balise, "tWidth").toInt());
00131 useTopBorder();
00132 }
00133 if(getAttr(balise, "bWidth").toInt() > 0)
00134 {
00135 setBottomWidth(getAttr(balise, "bWidth").toInt());
00136 useBottomBorder();
00137 }
00138 setLeftRed(getAttr(balise, "lRed").toInt());
00139 setLeftGreen(getAttr(balise, "lGreen").toInt());
00140 setLeftBlue(getAttr(balise, "lBlue").toInt());
00141
00142 setRightRed(getAttr(balise, "rRed").toInt());
00143 setRightGreen(getAttr(balise, "rGreen").toInt());
00144 setRightBlue(getAttr(balise, "rBlue").toInt());
00145
00146 setTopRed(getAttr(balise, "tRed").toInt());
00147 setTopGreen(getAttr(balise, "tGreen").toInt());
00148 setTopBlue(getAttr(balise, "tBlue").toInt());
00149
00150 setBottomRed(getAttr(balise, "bRed").toInt());
00151 setBottomGreen(getAttr(balise, "bGreen").toInt());
00152 setBottomBlue(getAttr(balise, "bBlue").toInt());
00153
00154 setLeftStyle(getAttr(balise, "lStyle").toInt());
00155 setRightStyle(getAttr(balise, "rStyle").toInt());
00156 setTopStyle(getAttr(balise, "tStyle").toInt());
00157 setBottomStyle(getAttr(balise, "bStyle").toInt());
00158 setBkRed(getAttr(balise, "bkred").toInt());
00159 setBkGreen(getAttr(balise, "bkgreen").toInt());
00160 setBkBlue(getAttr(balise, "bkblue").toInt());
00161
00162
00163
00164
00165
00166
00167 }
00168
00169
00170
00171
00172 void TextFrame::generate(QTextStream &out)
00173 {
00174 Para * lastPara = 0;
00175
00176 kdDebug(30522) << "TEXT GENERATION" << endl;
00177 kdDebug(30522) << "NB PARA " << _parags.count() << endl;
00178
00179 if(getSection() == SS_TABLE || getSection() == SS_HEADERS ||
00180 getSection() == SS_FOOTERS)
00181 {
00182 Config::instance()->writeIndent(out);
00183 out << "\\begin{minipage}{";
00184 out << (getRight() - getLeft()) << "pt}" << endl;
00185 }
00186 _lastEnv = ENV_NONE;
00187 _lastTypeEnum = TL_NONE;
00188
00189 Para* currentPara = _parags.first();
00190 while( currentPara != 0)
00191 {
00192
00193 if((!currentPara->isChapter() && _lastTypeEnum == TL_NONE &&
00194 _lastEnv != getNextEnv(_parags, _parags.at()) &&
00195 currentPara->notEmpty()) ||
00196 _lastEnv != getNextEnv(_parags, _parags.at()) )
00197 {
00198 currentPara->generateBeginEnv(out);
00199 _lastEnv = currentPara->getEnv();
00200 }
00201
00202
00203 if(isBeginEnum(lastPara, currentPara))
00204 {
00205 currentPara->openList(out);
00206 _lastTypeEnum = currentPara->getCounterType();
00207 }
00208
00209 currentPara->generate(out);
00210
00211 lastPara = currentPara;
00212 currentPara = _parags.next();
00213
00214
00215 if(isCloseEnum(lastPara, currentPara))
00216 {
00217 lastPara->closeList(out, currentPara);
00218 _lastTypeEnum = TL_NONE;
00219 }
00220
00221 if((!lastPara->isChapter() && _lastEnv != getNextEnv(_parags, _parags.at()) &&
00222 lastPara->notEmpty()) ||
00223 _lastEnv != getNextEnv(_parags, _parags.at()))
00224 {
00225 lastPara->generateEndEnv(out);
00226 out << endl;
00227 }
00228 if(getSection() != SS_HEADERS && getSection() != SS_FOOTERS)
00229 out << endl;
00230 }
00231
00232 if(getSection() == SS_TABLE || getSection() == SS_HEADERS ||
00233 getSection() == SS_FOOTERS)
00234 {
00235 Config::instance()->desindent();
00236 Config::instance()->writeIndent(out);
00237 out << "\\end{minipage}" << endl;
00238 }
00239 }
00240
00241 EEnv TextFrame::getNextEnv(QPtrList<Para> liste, const int pos)
00242 {
00243 if ( pos < 0 )
00244 return ENV_NONE;
00245 Para* index = 0;
00246
00247 for(index = liste.at(pos); index != 0 && index->isChapter(); index = liste.next())
00248 {}
00249
00250 if(index != 0)
00251 {
00252 return index->getEnv();
00253 }
00254 else
00255 return ENV_NONE;
00256 }
00257
00258
00259 bool TextFrame::isBeginEnum(Para* previous, Para* next)
00260 {
00261
00262
00263
00264
00265 kdDebug(30522) << "---------------------------------" << endl;
00266 kdDebug(30522) << getSection() << " = " << SS_HEADERS << endl;
00267 if(next->isList() && getSection() != SS_FOOTNOTES &&
00268 getSection() != SS_HEADERS && getSection() != SS_FOOTERS)
00269 {
00270 if(previous == 0 || !previous->isList() ||
00271 (previous->isList() && (
00272 (previous->getCounterDepth() < next->getCounterDepth()) ||
00273 (previous->getCounterType() != next->getCounterType() &&
00274 previous->getCounterDepth() == next->getCounterDepth()))
00275 ))
00276 return true;
00277 }
00278 return false;
00279 }
00280
00281
00282 bool TextFrame::isCloseEnum(Para* previous, Para* next)
00283 {
00284 if(previous->isList() && getSection() != SS_FOOTNOTES &&
00285 getSection() != SS_HEADERS && getSection() != SS_FOOTERS)
00286 {
00287 if(next == 0 || !next->isList() ||
00288 (next->isList() && next->getCounterDepth() < previous->getCounterDepth()) ||
00289 (next->isList() && next->getCounterType() != previous->getCounterType() &&
00290 next->getCounterDepth() == previous->getCounterDepth()) ||
00291 previous->getFrameType() == SS_TABLE)
00292 return true;
00293 }
00294 return false;
00295 }