Back to index

scribus-ng  1.3.4.dfsg+svn20071115
stylereader.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007  /***************************************************************************
00008   *   Copyright (C) 2004 by Riku Leino                                      *
00009   *   tsoots@gmail.com                                                      *
00010   *                                                                         *
00011   *   This program is free software; you can redistribute it and/or modify  *
00012   *   it under the terms of the GNU General Public License as published by  *
00013   *   the Free Software Foundation; either version 2 of the License, or     *
00014   *   (at your option) any later version.                                   *
00015   *                                                                         *
00016   *   This program is distributed in the hope that it will be useful,       *
00017   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00019   *   GNU General Public License for more details.                          *
00020   *                                                                         *
00021   *   You should have received a copy of the GNU General Public License     *
00022   *   along with this program; if not, write to the                         *
00023   *   Free Software Foundation, Inc.,                                       *
00024   *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00025   ***************************************************************************/
00026  
00027  #include "stylereader.h"
00028  
00029  #ifdef HAVE_XML
00030  
00031  #include <scribusstructs.h>
00032  #include <gtmeasure.h>
00033  #include <gtparagraphstyle.h>
00034  #include <gtframestyle.h>
00035  #include <gtfont.h>
00036  
00037  StyleReader* StyleReader::sreader = NULL;
00038  
00039  extern xmlSAXHandlerPtr sSAXHandler;
00040  
00041 StyleReader::StyleReader(QString documentName, gtWriter *w,
00042                          bool textOnly, bool prefix, bool combineStyles)
00043 {
00044        sreader      = this;
00045        docname      = documentName;
00046        readProperties = false;
00047        writer       = w;
00048        importTextOnly = textOnly;
00049        usePrefix    = prefix;
00050        packStyles   = combineStyles;
00051        currentStyle = NULL;
00052        parentStyle  = NULL;
00053        inList       = false;
00054        currentList  = "";
00055        defaultStyleCreated = false;
00056 }
00057  
00058  bool StyleReader::startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs) 
00059  {
00060        if (name == "style:default-style")
00061               defaultStyle(attrs);
00062        else if (name == "style:properties")
00063               styleProperties(attrs);
00064        else if (name == "style:style")
00065        {
00066               if (!defaultStyleCreated)
00067               {
00068                      currentStyle = new gtParagraphStyle(*(writer->getDefaultStyle()));
00069                      currentStyle->setName("default-style");
00070                      defaultStyleCreated = true;
00071               }
00072               styleStyle(attrs);
00073        }
00074        else if (name == "style:tab-stop")
00075               tabStop(attrs);
00076        else if (name == "text:list-style")
00077        {
00078               for (int i = 0; i < attrs.count(); ++i)
00079                      if (attrs.localName(i) == "style:name")
00080                             currentList = attrs.value(i);
00081               inList = true;
00082        }
00083        else if (((name == "text:list-level-style-bullet") || 
00084                  (name == "text:list-level-style-number") ||
00085                  (name == "text:list-level-style-image")) && (inList))
00086        {
00087               QString level = "";
00088               for (int i = 0; i < attrs.count(); ++i)
00089               {
00090                      if (attrs.localName(i) == "text:level")
00091                      {
00092                             gtStyle *plist;
00093                             if (attrs.value(i) == "1")
00094                             {
00095                                    plist = listParents[currentList];
00096                             }
00097                             else
00098                             {
00099                                    int level = (attrs.value(i)).toInt();
00100                                    --level;
00101                                    plist = styles[QString(currentList + "_%1").arg(level)]; 
00102                             }
00103                             gtParagraphStyle *pstyle;
00104                             if (plist == NULL)
00105                                    plist = new gtStyle(*(styles["default-style"]));
00106  
00107                             if (plist->target() == "paragraph")
00108                             {
00109                                    pstyle = dynamic_cast<gtParagraphStyle*>(plist);
00110                                    gtParagraphStyle* tmp = new gtParagraphStyle(*pstyle);
00111                                    currentStyle = tmp;
00112                             }
00113                             else
00114                             {
00115                                    gtParagraphStyle* tmp = new gtParagraphStyle(*plist);
00116                                    currentStyle = tmp;
00117                             }
00118                             currentStyle->setName(currentList + "_" + attrs.value(i));
00119                      }
00120               }
00121               readProperties = true;
00122        }
00123        else if ((name == "style:drop-cap") && (readProperties))
00124        {
00125               if (currentStyle->target() == "paragraph")
00126               {
00127                      for (int i = 0; i < attrs.count(); ++i)
00128                      {
00129                             if (attrs.localName(i) == "style:lines")
00130                             {
00131                                    bool ok = false;
00132                                    QString sd = attrs.value(i);
00133                                    int dh = sd.toInt(&ok);
00134                                    if (ok)
00135                                    {
00136                                           gtParagraphStyle* s = dynamic_cast<gtParagraphStyle*>(currentStyle);
00137                                           s->setDropCapHeight(dh);
00138                                           s->setDropCap(true);
00139                                    }
00140                             }
00141                      }
00142               }
00143        }
00144        else if (name == "style:font-decl")
00145        {
00146               QString key = "";
00147               QString family = "";
00148               QString style = "";
00149               for (int i = 0; i < attrs.count(); ++i)
00150               {
00151                      if (attrs.localName(i) == "style:name")
00152                             key = attrs.value(i);
00153                      else if (attrs.localName(i) == "fo:font-family")
00154                      {
00155                             family = attrs.value(i);
00156                             family = family.remove("'");
00157                      }
00158                      else if (attrs.localName(i) == "style:font-style-name")
00159                             style += attrs.value(i) + " ";
00160               }
00161               QString name = family + " " + style;
00162               name = name.simplifyWhiteSpace();
00163               fonts[key] = name;
00164        }
00165        return true;
00166  }
00167  
00168  void StyleReader::defaultStyle(const QXmlAttributes& attrs)
00169  {
00170        currentStyle = NULL;
00171        for (int i = 0; i < attrs.count(); ++i)
00172               if (attrs.localName(i) == "style:family")
00173                      if (attrs.value(i) == "paragraph")
00174                      {
00175                             currentStyle = new gtParagraphStyle(*(writer->getDefaultStyle()));
00176                             currentStyle->setName("default-style");
00177                             readProperties = true;
00178                             defaultStyleCreated = true;
00179                      }
00180  }
00181  
00182  void StyleReader::styleProperties(const QXmlAttributes& attrs)
00183  {
00184        if ((currentStyle == NULL) || (!readProperties))
00185               return;
00186        gtParagraphStyle* pstyle = NULL;
00187        if (currentStyle->target() == "paragraph")
00188               pstyle = dynamic_cast<gtParagraphStyle*>(currentStyle);
00189        else
00190               pstyle = NULL;
00191        QString align = NULL;
00192        QString force = NULL;
00193        bool hasColorTag = false;
00194        for (int i = 0; i < attrs.count(); ++i)
00195        {
00196               if ((attrs.localName(i) == "style:font-name") && (!inList))
00197                      currentStyle->getFont()->setName(getFont(attrs.value(i)));
00198               else if (attrs.localName(i) == "fo:font-size")
00199               {
00200                      double size = 0;
00201                      double psize = 0;
00202                      if (parentStyle != NULL)
00203                             psize = static_cast<double>(parentStyle->getFont()->getSize());
00204                      else if (styles.contains("default-style"))
00205                             psize = static_cast<double>(styles["default-style"]->getFont()->getSize());
00206  
00207                      psize = psize / 10;
00208                      size = getSize(attrs.value(i), psize);
00209                      int nsize = static_cast<int>(size * 10);
00210                      currentStyle->getFont()->setSize(nsize);
00211                      if (pstyle)
00212                             pstyle->setLineSpacing(writer->getPreferredLineSpacing(nsize));
00213               }
00214               else if ((attrs.localName(i) == "fo:line-height") && (parentStyle != NULL))
00215               {
00216                      gtParagraphStyle* ppstyle;
00217                      if (parentStyle->target() == "paragraph")
00218                      {
00219                             ppstyle = dynamic_cast<gtParagraphStyle*>(parentStyle);
00220                             pstyle->setLineSpacing(getSize(attrs.value(i), writer->getPreferredLineSpacing(currentStyle->getFont()->getSize())));
00221                      }
00222               }
00223               else if (attrs.localName(i) == "fo:color")
00224               {
00225                      currentStyle->getFont()->setColor(attrs.value(i));
00226                      hasColorTag = true;
00227               }
00228               else if ((attrs.localName(i) == "style:use-window-font-color") && (attrs.value(i) == "true"))
00229               {
00230                      currentStyle->getFont()->setColor("Black");
00231                      hasColorTag = true;
00232               }
00233               else if ((attrs.localName(i) == "fo:font-weight") && (attrs.value(i) == "bold"))
00234                      currentStyle->getFont()->setWeight(BOLD);
00235               else if ((attrs.localName(i) == "fo:font-style") && (attrs.value(i) == "italic"))
00236                      currentStyle->getFont()->setSlant(ITALIC);
00237               else if ((attrs.localName(i) == "style:text-underline") && (attrs.value(i) != "none"))
00238                      currentStyle->getFont()->toggleEffect(UNDERLINE);
00239               else if ((attrs.localName(i) == "style:text-crossing-out") && (attrs.value(i) != "none"))
00240                      currentStyle->getFont()->toggleEffect(STRIKETHROUGH);
00241               else if ((attrs.localName(i) == "fo:font-variant") && (attrs.value(i) == "small-caps"))
00242                      currentStyle->getFont()->toggleEffect(SMALL_CAPS);
00243               else if ((attrs.localName(i) == "style:text-outline") && (attrs.value(i) == "true"))
00244               {
00245                      currentStyle->getFont()->toggleEffect(OUTLINE);
00246                      currentStyle->getFont()->setStrokeColor("Black");
00247                      currentStyle->getFont()->setColor("White");
00248               }
00249               else if (attrs.localName(i) == "fo:letter-spacing")
00250                      currentStyle->getFont()->setKerning(static_cast<int>(getSize(attrs.value(i), -1.0)));
00251               else if (attrs.localName(i) == "style:text-scale")
00252                      currentStyle->getFont()->setHscale(static_cast<int>(getSize(attrs.value(i), -1.0)));
00253               else if ((attrs.localName(i) == "style:text-position") && 
00254                       (((attrs.value(i)).find("sub") != -1) || 
00255                             (((attrs.value(i)).left(1) == "-") && ((attrs.value(i)).left(1) != "0"))))
00256                      currentStyle->getFont()->toggleEffect(SUBSCRIPT);
00257               else if ((attrs.localName(i) == "style:text-position") && 
00258                       (((attrs.value(i)).find("super") != -1) || 
00259                             (((attrs.value(i)).left(1) != "-") && ((attrs.value(i)).left(1) != "0"))))
00260                      currentStyle->getFont()->toggleEffect(SUPERSCRIPT);
00261               else if ((attrs.localName(i) == "fo:margin-top") && (pstyle != NULL))
00262                      pstyle->setSpaceAbove(getSize(attrs.value(i)));
00263               else if ((attrs.localName(i) == "fo:margin-bottom") && (pstyle != NULL))
00264                      pstyle->setSpaceBelow(getSize(attrs.value(i)));
00265               else if ((attrs.localName(i) == "fo:margin-left") && (pstyle != NULL))
00266               {
00267                      if (inList)
00268                             pstyle->setIndent(pstyle->getIndent() + getSize(attrs.value(i)));
00269                      else
00270                             pstyle->setIndent(getSize(attrs.value(i)));      
00271               }
00272               else if ((attrs.localName(i) == "text:space-before") && (pstyle != NULL))
00273               {
00274                      if (inList)
00275                             pstyle->setIndent(pstyle->getIndent() + getSize(attrs.value(i)));
00276                      else
00277                             pstyle->setIndent(getSize(attrs.value(i)));
00278               }
00279               else if ((attrs.localName(i) == "fo:text-indent") && (pstyle != NULL))
00280                      pstyle->setFirstLineIndent(getSize(attrs.value(i)));
00281               else if ((attrs.localName(i) == "fo:text-align") && (pstyle != NULL))
00282                      align = attrs.value(i);
00283               else if ((attrs.localName(i) == "style:justify-single-word") && (pstyle != NULL))
00284                      force = attrs.value(i);
00285        }
00286        if (align != NULL)
00287        {
00288               if (align == "end")
00289                      pstyle->setAlignment(RIGHT);
00290               else if (align == "center")
00291                      pstyle->setAlignment(CENTER);
00292               else if (align == "justify")
00293               {
00294                      if (force == "false")
00295                             pstyle->setAlignment(BLOCK);
00296                      else
00297                             pstyle->setAlignment(FORCED);
00298               }
00299        }
00300        if (!hasColorTag)
00301               currentStyle->getFont()->setColor("Black");
00302  }
00303  
00304  void StyleReader::styleStyle(const QXmlAttributes& attrs)
00305  {
00306        QString name = "";
00307        QString listName = NULL;
00308        bool isParaStyle = false;
00309        bool create = true;
00310        for (int i = 0; i < attrs.count(); ++i)
00311        {
00312               if (attrs.localName(i) == "style:family")
00313               {
00314                      if (attrs.value(i) == "paragraph")
00315                      {
00316                             isParaStyle = true;
00317                             readProperties = true;
00318                      }
00319                      else if (attrs.value(i) == "text")
00320                      {
00321                             isParaStyle = false;
00322                             readProperties = true;
00323                      }
00324                      else
00325                      {
00326                             readProperties = false;
00327                             return;
00328                      }
00329               }
00330               else if (attrs.localName(i) == "style:name")
00331                      name = attrs.value(i);
00332               else if (attrs.localName(i) == "style:parent-style-name")
00333               {
00334                      if (styles.contains(attrs.value(i)))
00335                             parentStyle = styles[attrs.value(i)];
00336                      else
00337                             parentStyle = NULL;
00338               }
00339               else if (attrs.localName(i) == "style:list-style-name")
00340                      listName = attrs.value(i);
00341        }
00342        if ((parentStyle == NULL) && (styles.contains("default-style")))
00343               parentStyle = styles["default-style"];
00344  
00345        if (create)
00346        {
00347               if (parentStyle == NULL)
00348               {
00349                      parentStyle = new gtStyle("tmp-parent");
00350               }
00351               if (isParaStyle)
00352               {
00353                      gtParagraphStyle *tmpP;
00354                      if (parentStyle->target() == "paragraph")
00355                      {
00356                             tmpP = dynamic_cast<gtParagraphStyle*>(parentStyle);
00357                             gtParagraphStyle* tmp = new gtParagraphStyle(*tmpP);
00358  //                         tmp->setAutoLineSpacing(true);
00359                             currentStyle = tmp;
00360                      }
00361                      else
00362                      {
00363                             gtParagraphStyle* tmp = new gtParagraphStyle(*parentStyle);
00364  //                         tmp->setAutoLineSpacing(true);
00365                             currentStyle = tmp;
00366                      }
00367                      if (listName != NULL)
00368                      {
00369                             listParents[listName] = currentStyle;
00370                      }
00371               }
00372               else
00373                      currentStyle = new gtStyle(*parentStyle);
00374  
00375               currentStyle->setName(name);
00376        }
00377        else
00378               currentStyle = NULL;
00379  }
00380  
00381  void StyleReader::tabStop(const QXmlAttributes& attrs)
00382  {
00383        if (currentStyle->target() == "paragraph")
00384        {
00385               gtParagraphStyle* pstyle = dynamic_cast<gtParagraphStyle*>(currentStyle);
00386               QString pos = NULL;
00387               QString type = NULL;
00388               for (int i = 0; i < attrs.count(); ++i)
00389               {
00390                      if (attrs.localName(i) == "style:position")
00391                             pos = attrs.value(i);
00392                      else if (attrs.localName(i) == "style:type")
00393                             type = attrs.value(i);
00394                             
00395               }
00396               if (pos != NULL)
00397               {
00398                      if (type == NULL)
00399                             type = "left";
00400                      double posd = getSize(pos);
00401                      if (type == "left")
00402                             pstyle->setTabValue(posd, LEFT_T);
00403                      else if (type == "right")
00404                             pstyle->setTabValue(posd, RIGHT_T);
00405                      else if (type == "center")
00406                             pstyle->setTabValue(posd, CENTER_T);
00407                      else
00408                             pstyle->setTabValue(posd, CENTER_T);
00409               }
00410        }
00411  }
00412  
00413  bool StyleReader::endElement(const QString&, const QString&, const QString &name)
00414  {
00415        if ((name == "style:default-style") && (currentStyle != NULL) && (readProperties))
00416        {
00417               setStyle(currentStyle->getName(), currentStyle);
00418               currentStyle = NULL;
00419               parentStyle = NULL;
00420               readProperties = false;
00421        }
00422        else if (((name == "style:style") || 
00423                  (name == "text:list-level-style-bullet") || 
00424                        (name == "text:list-level-style-number") ||
00425                        (name == "text:list-level-style-image")) && (currentStyle != NULL))
00426        {
00427               setStyle(currentStyle->getName(), currentStyle);
00428               currentStyle = NULL;
00429               parentStyle = NULL;
00430               readProperties = false;
00431        }
00432        else if (name == "text:list-style")
00433        {
00434               inList = false;
00435        }
00436 
00437        return true;
00438  }
00439  
00440  void StyleReader::parse(QString fileName)
00441  {
00442 #if defined(_WIN32)
00443        QString fname = QDir::convertSeparators(fileName);
00444        QCString fn = (qWinVersion() & Qt::WV_NT_based) ? fname.utf8() : fname.local8Bit();
00445 #else
00446        QCString fn(fileName.local8Bit());
00447 #endif
00448        xmlSAXParseFile(sSAXHandler, fn.data(), 1);
00449  }
00450  
00451  gtStyle* StyleReader::getStyle(const QString& name)
00452  {
00453        if (styles.contains(name))
00454        {
00455               gtStyle* tmp = styles[name];
00456               QString tname = tmp->getName();
00457               if ((tname.find(docname) == -1) && (usePrefix))
00458                      tmp->setName(docname + "_" + tname);
00459  
00460               return tmp;
00461        }
00462        else
00463               return styles["default-style"];
00464 
00465  }
00466  
00467  void StyleReader::setStyle(const QString& name, gtStyle* style)
00468  {
00469        gtParagraphStyle *s;
00470        QString tname = style->getName();
00471        if ((style->target() == "paragraph") && (packStyles))
00472        {
00473               s = dynamic_cast<gtParagraphStyle*>(style);
00474               QString nameByAttrs = QString("%1-").arg(s->getSpaceAbove());
00475               nameByAttrs += QString("%1-").arg(s->getSpaceBelow());
00476               nameByAttrs += QString("%1-").arg(s->getLineSpacing());
00477               nameByAttrs += QString("%1-").arg(s->getIndent());
00478               nameByAttrs += QString("%1-").arg(s->getFirstLineIndent());
00479               nameByAttrs += QString("%1-").arg(s->getAlignment());
00480               nameByAttrs += QString("%1-").arg(s->hasDropCap());
00481               nameByAttrs += QString("%1-").arg(s->getFont()->getColor());
00482               nameByAttrs += QString("%1-").arg(s->getFont()->getStrokeColor());
00483 // TODO is this important ??
00484 /*            QValueList<double>* tmp = s->getTabValues();
00485               for (uint i = 0; i < tmp->count(); ++i)
00486               {
00487                      double td = (*tmp)[i];
00488                      nameByAttrs += QString("%1-").arg(td);
00489               } */
00490               if (attrsStyles.contains(nameByAttrs))
00491               {
00492                      tname = attrsStyles[nameByAttrs]->getName();
00493                      ++pstyleCounts[nameByAttrs];
00494                      style->setName(tname);
00495               }
00496               else
00497               {
00498                      attrsStyles[nameByAttrs] = style;
00499                      pstyleCounts[nameByAttrs] = 1;
00500                      tname = style->getName();
00501               }
00502        }
00503        else if (!packStyles)
00504        {
00505               attrsStyles[name] = style;
00506               pstyleCounts[name] = 1;
00507               tname = style->getName();
00508        }
00509        if (!styles.contains(name))
00510        {
00511               if ((tname.find(docname) == -1) && (usePrefix))
00512                      style->setName(docname + "_" + tname);
00513               styles[name] = style;
00514        }
00515  }
00516  
00517  QString StyleReader::getFont(const QString& key)
00518  {
00519        if (fonts.contains(key))
00520               return fonts[key];
00521        else
00522               return key;
00523  }
00524  
00525  void StyleReader::setupFrameStyle()
00526  {
00527        QString fstyleName = "";
00528        int count = 0;
00529        CounterMap::Iterator it;
00530        for (it = pstyleCounts.begin(); it != pstyleCounts.end(); ++it)
00531        {
00532               if (it.data() > count)
00533               {
00534                      count = it.data();
00535                      fstyleName = it.key();
00536               }
00537        }
00538        gtFrameStyle* fstyle;
00539        gtParagraphStyle* pstyle = dynamic_cast<gtParagraphStyle*>(attrsStyles[fstyleName]);
00540        fstyle = new gtFrameStyle(*pstyle);
00541  
00542        if (!importTextOnly)
00543               writer->setFrameStyle(fstyle);
00544        delete fstyle;
00545  }
00546  
00547  bool StyleReader::updateStyle(gtStyle* style, gtStyle* parent2Style, const QString& key, const QString& value)
00548  {
00549        gtParagraphStyle* pstyle = NULL;
00550        if (style->target() == "paragraph")
00551               pstyle = dynamic_cast<gtParagraphStyle*>(style);
00552        else
00553               pstyle = NULL;
00554        QString align = NULL;
00555        QString force = NULL;
00556  
00557        if (key == "style:font-name")
00558               style->getFont()->setName(getFont(value));
00559        else if (key == "fo:font-size")
00560        {
00561               double size = 0;
00562               double psize = 0;
00563               if (parent2Style != NULL)
00564                      psize = static_cast<double>(parent2Style->getFont()->getSize());
00565               else if (styles.contains("default-style"))
00566                      psize = static_cast<double>(styles["default-style"]->getFont()->getSize());
00567                      psize = psize / 10;
00568               size = getSize(value, psize);
00569               int nsize = static_cast<int>(size * 10);
00570               style->getFont()->setSize(nsize);
00571               if (pstyle)
00572                      pstyle->setLineSpacing(writer->getPreferredLineSpacing(nsize));
00573        }
00574        else if ((key == "fo:line-height") && (parent2Style != NULL))
00575        {
00576               gtParagraphStyle* ppstyle;
00577               if (parent2Style->target() == "paragraph")
00578               {
00579                      ppstyle = dynamic_cast<gtParagraphStyle*>(parent2Style);
00580                      pstyle->setLineSpacing(getSize(value, writer->getPreferredLineSpacing(style->getFont()->getSize())));
00581               }
00582        }
00583        else if (key == "fo:color")
00584               style->getFont()->setColor(value);
00585        else if ((key == "style:use-window-font-color") && (value == "true"))
00586                      style->getFont()->setColor("Black");
00587        else if ((key == "fo:font-weight") && (value == "bold"))
00588               style->getFont()->setWeight(BOLD);
00589        else if ((key == "fo:font-style") && (value == "italic"))
00590               style->getFont()->setSlant(ITALIC);
00591        else if ((key == "style:text-underline") && (value != "none"))
00592               style->getFont()->toggleEffect(UNDERLINE);
00593        else if ((key == "style:text-crossing-out") && (value != "none"))
00594               style->getFont()->toggleEffect(STRIKETHROUGH);
00595        else if ((key == "fo:font-variant") && (value == "small-caps"))
00596               style->getFont()->toggleEffect(SMALL_CAPS);
00597        else if ((key == "style:text-outline") && (value == "true"))
00598        {
00599               style->getFont()->toggleEffect(OUTLINE);
00600               style->getFont()->setStrokeColor("Black");
00601               style->getFont()->setColor("White");
00602        }
00603        else if (key == "fo:letter-spacing")
00604               style->getFont()->setKerning(static_cast<int>(getSize(value, -1.0)));
00605        else if (key == "style:text-scale")
00606               style->getFont()->setHscale(static_cast<int>(getSize(value, -1.0)));
00607        else if ((key == "style:text-position") && 
00608                (((value).find("sub") != -1) || 
00609                      (((value).left(1) == "-") && ((value).left(1) != "0"))))
00610               style->getFont()->toggleEffect(SUBSCRIPT);
00611        else if ((key == "style:text-position") && 
00612                (((value).find("super") != -1) || 
00613                      (((value).left(1) != "-") && ((value).left(1) != "0"))))
00614               style->getFont()->toggleEffect(SUPERSCRIPT);
00615        else if ((key == "fo:margin-top") && (pstyle != NULL))
00616               pstyle->setSpaceAbove(getSize(value));
00617        else if ((key == "fo:margin-bottom") && (pstyle != NULL))
00618               pstyle->setSpaceBelow(getSize(value));
00619        else if ((key == "fo:margin-left") && (pstyle != NULL))
00620        {
00621               if (inList)
00622                      pstyle->setIndent(pstyle->getIndent() + getSize(value));
00623               else
00624                      pstyle->setIndent(getSize(value)); 
00625        }
00626        else if ((key == "text:space-before") && (pstyle != NULL))
00627        {
00628               if (inList)
00629                      pstyle->setIndent(pstyle->getIndent() + getSize(value));
00630               else
00631                      pstyle->setIndent(getSize(value)); 
00632        }
00633        else if ((key == "fo:text-indent") && (pstyle != NULL))
00634               pstyle->setFirstLineIndent(getSize(value));
00635        else if ((key == "fo:text-align") && (pstyle != NULL))
00636               align = value;
00637        else if ((key == "style:justify-single-word") && (pstyle != NULL))
00638               force = value;
00639  
00640        if (align != NULL)
00641        {
00642               if (align == "end")
00643                      pstyle->setAlignment(RIGHT);
00644               else if (align == "center")
00645                      pstyle->setAlignment(CENTER);
00646               else if (align == "justify")
00647               {
00648                      if (force != "false")
00649                             pstyle->setAlignment(FORCED);
00650                      else
00651                             pstyle->setAlignment(BLOCK);
00652               }
00653        }
00654        
00655        return true;
00656  }
00657  
00658  double StyleReader::getSize(QString s, double parentSize)
00659  {
00660        QString dbl = "0.0";
00661        QString lowerValue = s.lower();
00662        double ret = 0.0;
00663        if (lowerValue.find("pt") != -1)
00664        {
00665               dbl = lowerValue.remove("pt");
00666               ret = gtMeasure::d2d(dbl.toDouble(), SC_PT);
00667        }
00668        else if (lowerValue.find("mm") != -1)
00669        {
00670               dbl = lowerValue.remove("mm");
00671               ret = gtMeasure::d2d(dbl.toDouble(), SC_MM);
00672        }
00673        else if (lowerValue.find("cm") != -1)
00674        {
00675               dbl = lowerValue.remove("cm");
00676               ret = gtMeasure::d2d(dbl.toDouble() * 10, SC_MM);
00677        }
00678        else if (lowerValue.find("in") != -1)
00679        {
00680               dbl = lowerValue.remove("inch");
00681               dbl = lowerValue.remove("in");
00682               ret = gtMeasure::d2d(dbl.toDouble(), SC_IN);
00683        }
00684        else if (lowerValue.find("pi") != -1)
00685        {
00686               dbl = lowerValue.remove("pica");
00687               dbl = lowerValue.remove("pi");
00688               ret = gtMeasure::d2d(dbl.toDouble(), SC_P);
00689        }
00690        else if (lowerValue.find("c") != -1)
00691        {
00692               dbl = lowerValue.remove("cicero");
00693               dbl = lowerValue.remove("c");
00694               ret = gtMeasure::d2d(dbl.toDouble(), SC_C);
00695        }
00696        else if (lowerValue.find("%") != -1)
00697        {
00698               dbl = lowerValue.remove("%");
00699               double factor = dbl.toDouble();
00700               if (parentSize != -1.0)
00701               {
00702                      factor = factor / 100;
00703                      ret = factor * parentSize;
00704               }
00705               else
00706                      ret = factor;
00707        }
00708        return ret;
00709  }
00710  
00711  StyleReader::~StyleReader()
00712  {
00713        sreader = NULL;
00714        StyleMap::Iterator it;
00715        for (it = styles.begin(); it != styles.end(); ++it)
00716        {
00717               if (it.data())
00718               {
00719                      delete it.data();
00720                      it.data() = NULL;
00721               }
00722        }
00723  }
00724  
00725  xmlSAXHandler sSAXHandlerStruct = {
00726        NULL, // internalSubset,
00727        NULL, // isStandalone,
00728        NULL, // hasInternalSubset,
00729        NULL, // hasExternalSubset,
00730        NULL, // resolveEntity,
00731        NULL, // getEntity,
00732        NULL, // entityDecl,
00733        NULL, // notationDecl,
00734        NULL, // attributeDecl,
00735        NULL, // elementDecl,
00736        NULL, // unparsedEntityDecl,
00737        NULL, // setDocumentLocator,
00738        NULL, // startDocument,
00739        NULL, // endDocument,
00740        StyleReader::startElement,
00741        StyleReader::endElement,
00742        NULL, // reference,
00743        NULL, // characters
00744        NULL, // ignorableWhitespace,
00745        NULL, // processingInstruction,
00746        NULL, // comment,
00747        NULL, // warning,
00748        NULL, // error,
00749        NULL, // fatalError,
00750        NULL, // getParameterEntity,
00751        NULL, // cdata,
00752        NULL,
00753        1
00754  #ifdef HAVE_XML26
00755        ,
00756        NULL,
00757        NULL,
00758        NULL,
00759        NULL
00760  #endif
00761  };
00762  
00763  xmlSAXHandlerPtr sSAXHandler = &sSAXHandlerStruct;
00764  
00765  void StyleReader::startElement(void*, const xmlChar * fullname, const xmlChar ** atts)
00766  {
00767        QString* name = new QString((const char*) fullname);
00768        name = new QString(name->lower());
00769        QXmlAttributes* attrs = new QXmlAttributes();
00770        if (atts)
00771        {
00772               for(const xmlChar** cur = atts; cur && *cur; cur += 2)
00773                      attrs->append(QString((char*)*cur), NULL, QString((char*)*cur), QString((char*)*(cur + 1)));
00774        }
00775        sreader->startElement(NULL, NULL, *name, *attrs);
00776  }
00777  
00778  void StyleReader::endElement(void*, const xmlChar * name)
00779  {
00780        QString *nname = new QString((const char*) name);
00781        nname = new QString(nname->lower());
00782        sreader->endElement(NULL, NULL, *nname);
00783  }
00784  
00785  #endif