filters

textFrame.cc

00001 /*
00002 ** A program to convert the XML rendered by KWord into LATEX.
00003 **
00004 ** Copyright (C) 2000, 2001, 2002 Robert JACOLIN
00005 **
00006 ** This library is free software; you can redistribute it and/or
00007 ** modify it under the terms of the GNU Library General Public
00008 ** License as published by the Free Software Foundation; either
00009 ** version 2 of the License, or (at your option) any later version.
00010 **
00011 ** This library is distributed in the hope that it will be useful,
00012 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 ** Library General Public License for more details.
00015 **
00016 ** To receive a copy of the GNU Library General Public License, write to the
00017 ** Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 **
00020 */
00021 
00022 #include <stdlib.h>     /* for atoi function */
00023 #include <kdebug.h>     /* for kdDebug() stream */
00024 #include "textFrame.h"
00025 
00026 /*******************************************/
00027 /* Constructor                             */
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     //_footnotes         = 0;
00041 
00042     setType(ST_TEXT);
00043 }
00044 
00045 /*******************************************/
00046 /* searchFootnote                          */
00047 /*******************************************/
00048 /*Para* TextFrame::searchFootnote(const QString name)
00049 {
00050     for(Para* current = _footnotes.first(); current!= 0; current = _footnotes.next())
00051     {
00052         QString* string = current->getName();
00053         kdDebug(30522) << *string << endl;
00054         if(*string == name)
00055             return current;
00056         //iter.next();
00057     }
00058     return 0;
00059 }*/
00060 
00061 /*******************************************/
00062 /* analyse                                 */
00063 /*******************************************/
00064 void TextFrame::analyse(const QDomNode balise)
00065 {
00066     /* MARKUP TYPE : FRAMESET INFO = TEXTE, ENTETE CONNUE */
00067 
00068     /* Parameters Analyse */
00069     Element::analyse(balise);
00070 
00071     kdDebug(30522) << "FRAME ANALYSE (TextFrame)" << endl;
00072 
00073     /* Chlidren markups Analyse */
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             // 1. Create a paragraph :
00081             Para *prg = new Para(this);
00082             // 2. Add the informations :
00083             prg->analyse(getChild(balise, index));
00084             if(prg->getInfo() == EP_FOOTNOTE)
00085             {
00086                 // 3. add this parag. in the footnote list
00087                 //if(_footnotes == 0)
00088                 //  _footnotes = new ListPara;
00089                 //_footnotes.append(prg);
00090             }
00091             else
00092             {
00093                 // 3. add this parag. in the text list
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 /* analyseParamFrame                       */
00105 /*******************************************/
00106 void TextFrame::analyseParamFrame(const QDomNode balise)
00107 {
00108     /*<FRAME left="28" top="42" right="566" bottom="798" runaround="1" />*/
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     setLeftWidth(getAttr(balise, "bleftpt").toDouble());
00163     setLeftWidth(getAttr(balise, "brightpt").toDouble());
00164     setLeftWidth(getAttr(balise, "bktoppt").toDouble());
00165     setLeftWidth(getAttr(balise, "bkbottompt").toDouble());
00166 */
00167 }
00168 
00169 /*******************************************/
00170 /* generate                                */
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         //indent();
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         /* List management */
00203         if(isBeginEnum(lastPara, currentPara))
00204         {
00205             currentPara->openList(out);
00206             _lastTypeEnum = currentPara->getCounterType();
00207         }
00208         /* paragraph generation */
00209         currentPara->generate(out);
00210 
00211         lastPara = currentPara;
00212         currentPara = _parags.next();
00213 
00214         /* list management */
00215         if(isCloseEnum(lastPara, currentPara))
00216         {
00217             lastPara->closeList(out, currentPara);
00218             _lastTypeEnum = TL_NONE;
00219         }
00220         /* layout management (left, center, justify, right) */
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 /* next is the paragraph which will be generated, just after */
00259 bool TextFrame::isBeginEnum(Para* previous, Para* next)
00260 {
00261     /* If it's a list : */
00262     /* - go in a new list */
00263     /* - change depth (a list in a list) */
00264     /* - or two lists nearby (but with the same depth) */
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 /* next is the paragraph which will be generated in the next loop */
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 }
KDE Home | KDE Accessibility Home | Description of Access Keys