Back to index

scribus-ng  1.3.4.dfsg+svn20071115
stencilreader.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 #include "stencilreader.h"
00008 #include <qtextstream.h>
00009 #include <qregexp.h>
00010 #include "sccolor.h"
00011 #include "scribus.h"
00012 #include "splash.h"
00013 #include "util.h"
00014 #include "prefsmanager.h"
00015 #include "scpainter.h"
00016 #include "commonstrings.h"
00017 #include "pageitem.h"
00018 #include "scribusdoc.h"
00019 
00020 
00021 StencilReader::StencilReader()
00022 {
00023 }
00024 
00025 QString StencilReader::createShape(QString datain)
00026 {
00027        QString tmp = "";
00028        double GrW = 50.0;
00029        double GrH = 50.0;
00030        double Dx = 0.0;
00031        double Dy = 0.0;
00032        QDomDocument docu("scridoc");
00033        docu.setContent(datain);
00034        QDomElement elem=docu.documentElement();
00035        if (elem.tagName() != "shape")
00036               return tmp;
00037        QDomNodeList list = elem.elementsByTagName("name");
00038        if (list.count() == 0)
00039               return tmp;
00040        QString name = list.item(0).toElement().text();
00041        QDomDocument data("scribus");
00042        QString st="<SCRIBUSELEMUTF8></SCRIBUSELEMUTF8>";
00043        data.setContent(st);
00044        QDomElement group = data.documentElement();
00045        QDomNodeList list2 = elem.elementsByTagName("svg:svg");
00046        if (list2.count() == 0)
00047               return tmp;
00048        QDomElement svg = list2.item(0).toElement();
00049        Conversion = 1.0;
00050 
00051        group.setAttribute("XP", 0.0);
00052        group.setAttribute("YP", 0.0);
00053        group.setAttribute("Version", QString(VERSION));
00054        PageColors.insert("Black", ScColor(0, 0, 0, 255));
00055        QDomElement co = data.createElement("COLOR");
00056        co.setAttribute("NAME","Black");
00057        co.setAttribute("CMYK", "#000000FF");
00058        co.setAttribute("Spot","0");
00059        co.setAttribute("Register","0");
00060        group.appendChild(co);
00061        PageColors.insert("White", ScColor(0, 0, 0, 0));
00062        QDomElement co2 = data.createElement("COLOR");
00063        co2.setAttribute("NAME","White");
00064        co2.setAttribute("CMYK", "#00000000");
00065        co2.setAttribute("Spot","0");
00066        co2.setAttribute("Register","0");
00067        group.appendChild(co2);
00068        QDomNode DOC = svg.firstChild();
00069        double minXCoor = 0.0;
00070        double minYCoor = 0.0;
00071        double maxXCoor = 0.0;
00072        double maxYCoor = 0.0;
00073        int groupElemCounter = 0;
00074        Conversion = 1.0;
00075        bool firstCheck = true;
00076        parseGroupProperties(data, group, DOC, groupElemCounter, minXCoor, minYCoor, maxXCoor, maxYCoor, firstCheck);
00077        GrW = maxXCoor - minXCoor;
00078        GrH = maxYCoor - minYCoor;
00079        Conversion = 100.0 / QMAX(GrW, GrH);
00080        GrW *= Conversion;
00081        GrH *= Conversion;
00082        Dx = minXCoor * Conversion;
00083        Dy = minYCoor* Conversion;
00084        QDomElement obGroup;
00085        if (groupElemCounter != 1)
00086        {
00087               group.setAttribute("COUNT", groupElemCounter+1);
00088               obGroup = data.createElement("ITEM");
00089               writeDefaults(obGroup);
00090               obGroup.setAttribute("PWIDTH", 0);
00091               obGroup.setAttribute("PCOLOR", "None");
00092               obGroup.setAttribute("PCOLOR2", "None");
00093               obGroup.setAttribute("PLINEART", Qt::SolidLine);
00094               obGroup.setAttribute("PLINEEND", Qt::FlatCap);
00095               obGroup.setAttribute("PLINEJOIN", Qt::MiterJoin);
00096               obGroup.setAttribute("ANNAME", name.simplifyWhiteSpace().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ));
00097               obGroup.setAttribute("GROUPS", 1);
00098               obGroup.setAttribute("NUMGROUP", 1);
00099               obGroup.setAttribute("isGroupControl", 1);
00100               obGroup.setAttribute("PTYPE", PageItem::Polygon);
00101               group.appendChild(obGroup);
00102        }
00103        else
00104               group.setAttribute("COUNT", groupElemCounter);
00105        int groupElemCounter2 = 0;
00106        DOC = svg.firstChild();
00107        parseGroup(data, group, DOC, groupElemCounter, groupElemCounter2, Dx, Dy);
00108        if (groupElemCounter > 1)
00109        {
00110               obGroup.setAttribute("groupsLastItem", groupElemCounter2);
00111               static double rect[] = {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
00112                                                                              1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
00113                                                                              0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0};
00114               FPointArray PoLine;
00115               PoLine.resize(0);
00116               for (int a = 0; a < 29; a += 4)
00117               {
00118                      double xa = GrW * rect[a];
00119                      double ya = GrH * rect[a+1];
00120                      double xb = GrW * rect[a+2];
00121                      double yb = GrH * rect[a+3];
00122                      PoLine.addPoint(0+xa, 0+ya);
00123                      PoLine.addPoint(0+xb, 0+yb);
00124               }
00125               obGroup.setAttribute("XPOS", 0);
00126               obGroup.setAttribute("YPOS",0);
00127               obGroup.setAttribute("WIDTH",GrW);
00128               obGroup.setAttribute("HEIGHT",GrH);
00129               obGroup.setAttribute("NUMPO", PoLine.size());
00130               QString polp = "";
00131               double xf, yf;
00132               QString tmpSt, tmpSt2;
00133               for (uint nxx=0; nxx<PoLine.size(); ++nxx)
00134               {
00135                      PoLine.point(nxx, &xf, &yf);
00136                      polp += tmpSt.setNum(xf) + " " + tmpSt2.setNum(yf) + " ";
00137               }
00138               obGroup.setAttribute("POCOOR", polp);
00139        }
00140        group.setAttribute("W", GrW);
00141        group.setAttribute("H", GrH);
00142        return data.toString();
00143 }
00144 
00145 void StencilReader::parseGroup(QDomDocument &data, QDomElement &group, QDomNode &DOC, int groupElemCounter, int &groupElemCounter2, double Dx, double Dy)
00146 {
00147        QString tmp = "";
00148        QString FillCol = "White";
00149        QString StrokeCol = "Black";
00150        QString defFillCol = "White";
00151        QString defStrokeCol = "Black";
00152        QColor stroke = Qt::black;
00153        QColor fill = Qt::white;
00154        Qt::PenStyle Dash = Qt::SolidLine;
00155        Qt::PenCapStyle LineEnd = Qt::FlatCap;
00156        Qt::PenJoinStyle LineJoin = Qt::MiterJoin;
00157        int fillStyle = 1;
00158        double strokewidth = 0.1;
00159        bool poly = false;
00160        while(!DOC.isNull())
00161        {
00162               double x1, y1, x2, y2;
00163               StrokeCol = defStrokeCol;
00164               FillCol = defFillCol;
00165               stroke = Qt::black;
00166               fill = Qt::white;
00167               fillStyle = 1;
00168               strokewidth = 1.0;
00169               Dash = Qt::SolidLine;
00170               LineEnd = Qt::FlatCap;
00171               LineJoin = Qt::MiterJoin;
00172               FPointArray PoLine;
00173               PoLine.resize(0);
00174               QDomElement pg=DOC.toElement();
00175               QString STag = pg.tagName();
00176               QString style = pg.attribute( "style", "" ).simplifyWhiteSpace();
00177               if (style.isEmpty())
00178                      style = pg.attribute( "svg:style", "" ).simplifyWhiteSpace();
00179               if (!style.isEmpty())
00180               {
00181                      FillCol = "None";
00182                      strokewidth = 0.1;
00183                      QStringList substyles = QStringList::split( ';', style );
00184                      for( QStringList::Iterator it = substyles.begin(); it != substyles.end(); ++it )
00185                      {
00186                             QStringList substyle = QStringList::split( ':', (*it) );
00187                             QString command      = substyle[0].stripWhiteSpace();
00188                             QString params       = substyle[1].stripWhiteSpace();
00189                             if (command == "fill")
00190                             {
00191                                    if ((params == "foreground") || (params == "fg") || (params == "inverse"))
00192                                           FillCol = defStrokeCol;
00193                                    else if ((params == "background") || (params == "bg"))
00194                                           FillCol = defFillCol;
00195                                    else if  (params == "default")
00196                                           FillCol = "None";
00197                                    else if (params == "none")
00198                                           FillCol = "None";
00199                                    else
00200                                    {
00201                                           fill.setNamedColor( params );
00202                                           if (fill == Qt::white)
00203                                                  FillCol = "White";
00204                                           else if (fill == Qt::black)
00205                                                  FillCol = "Black";
00206                                           else
00207                                                  FillCol = "FromDia"+fill.name();
00208                                    }
00209                             }
00210                             else if (command == "stroke")
00211                             {
00212                                    if ((params == "foreground") || (params == "fg"))
00213                                           StrokeCol = defStrokeCol;
00214                                    else if ((params == "background") || (params == "bg") || (params == "inverse"))
00215                                           StrokeCol = defFillCol;
00216                                    else if  (params == "default")
00217                                           StrokeCol = defStrokeCol;
00218                                    else if (params == "none")
00219                                           StrokeCol = "None";
00220                                    else
00221                                    {
00222                                           stroke.setNamedColor( params );
00223                                           if (stroke == Qt::white)
00224                                                  StrokeCol = "White";
00225                                           else if (stroke == Qt::black)
00226                                                  StrokeCol = "Black";
00227                                           else
00228                                                  StrokeCol = "FromDia"+stroke.name();
00229                                    }
00230                             }
00231                             else if (command == "stroke-width")
00232                                    strokewidth = params.toDouble();
00233                             else if( command == "stroke-linejoin" )
00234                             {
00235                                    if( params == "miter" )
00236                                           LineJoin = Qt::MiterJoin;
00237                                    else if( params == "round" )
00238                                           LineJoin = Qt::RoundJoin;
00239                                    else if( params == "bevel" )
00240                                           LineJoin = Qt::BevelJoin;
00241                             }
00242                             else if( command == "stroke-linecap" )
00243                             {
00244                                    if( params == "butt" )
00245                                           LineEnd = Qt::FlatCap;
00246                                    else if( params == "round" )
00247                                           LineEnd = Qt::RoundCap;
00248                                    else if( params == "square" )
00249                                           LineEnd = Qt::SquareCap;
00250                             }
00251                      }
00252               }
00253               if (STag == "svg:line")
00254               {
00255                      x1 = pg.attribute("x1").toDouble() * Conversion;
00256                      y1 = pg.attribute("y1").toDouble() * Conversion;
00257                      x2 = pg.attribute("x2").toDouble() * Conversion;
00258                      y2 = pg.attribute("y2").toDouble() * Conversion;
00259                      PoLine.addPoint(x1, y1);
00260                      PoLine.addPoint(x1, y1);
00261                      PoLine.addPoint(x2, y2);
00262                      PoLine.addPoint(x2, y2);
00263               }
00264               else if (STag == "svg:rect")
00265               {
00266                      x1 = pg.attribute("x").toDouble() * Conversion;
00267                      y1 = pg.attribute("y").toDouble() * Conversion;
00268                      x2 = pg.attribute("width").toDouble() * Conversion;
00269                      y2 = pg.attribute("height").toDouble() * Conversion;
00270                      static double rect[] = {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
00271                                                                1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
00272                                                                0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0};
00273                      for (int a = 0; a < 29; a += 4)
00274                      {
00275                             double xa = x2 * rect[a];
00276                             double ya = y2 * rect[a+1];
00277                             double xb = x2 * rect[a+2];
00278                             double yb = y2 * rect[a+3];
00279                             PoLine.addPoint(x1+xa, y1+ya);
00280                             PoLine.addPoint(x1+xb, y1+yb);
00281                      }
00282               }
00283               else if ((STag == "svg:polygon") || (STag == "svg:polyline"))
00284               {
00285                      bool bFirst = true;
00286                      double x = 0.0;
00287                      double y = 0.0;
00288                      QString points = pg.attribute( "points" ).simplifyWhiteSpace().replace(',', " ");
00289                      QStringList pointList = QStringList::split( ' ', points );
00290                      FirstM = true;
00291                      for( QStringList::Iterator it = pointList.begin(); it != pointList.end(); it++ )
00292                      {
00293                             if( bFirst )
00294                             {
00295                                    x = (*(it++)).toDouble();
00296                                    y = (*it).toDouble();
00297                                    svgMoveTo(x * Conversion, y * Conversion);
00298                                    bFirst = false;
00299                                    WasM = true;
00300                             }
00301                             else
00302                             {
00303                                    x = (*(it++)).toDouble();
00304                                    y = (*it).toDouble();
00305                                    svgLineTo(&PoLine, x * Conversion, y * Conversion);
00306                             }
00307                      }
00308                      if (STag == "svg:polygon")
00309                             svgClosePath(&PoLine);
00310                      if (PoLine.size() < 4)
00311                      {
00312                             DOC = DOC.nextSibling();
00313                             continue;
00314                      }
00315               }
00316               else if (STag == "svg:circle")
00317               {
00318                      x1 = pg.attribute("r").toDouble() * Conversion;
00319                      y1 = pg.attribute("r").toDouble() * Conversion;
00320                      x2 = pg.attribute("cx").toDouble() * Conversion - x1;
00321                      y2 = pg.attribute("cy").toDouble() * Conversion - y1;
00322                      x1 *= 2.0;
00323                      y1 *= 2.0;
00324                      static double rect[] = {1.0, 0.5, 1.0, 0.77615235,0.5, 1.0, 0.77615235, 1.0,
00325                                                                0.5, 1.0, 0.22385765, 1.0, 0.0, 0.5, 0.0, 0.77615235,
00326                                                                0.0, 0.5, 0.0, 0.22385765, 0.5, 0.0, 0.22385765, 0.0,
00327                                                                0.5, 0.0, 0.77615235, 0.0, 1.0, 0.5, 1.0, 0.22385765};
00328                      for (int a = 0; a < 29; a += 4)
00329                      {
00330                             double xa = x1 * rect[a];
00331                             double ya = y1 * rect[a+1];
00332                             double xb = x1 * rect[a+2];
00333                             double yb = y1 * rect[a+3];
00334                             PoLine.addPoint(x2+xa, y2+ya);
00335                             PoLine.addPoint(x2+xb, y2+yb);
00336                      }
00337               }
00338               else if (STag == "svg:ellipse")
00339               {
00340                      x1 = pg.attribute("rx").toDouble() * Conversion;
00341                      y1 = pg.attribute("ry").toDouble() * Conversion;
00342                      x2 = pg.attribute("cx").toDouble() * Conversion - x1;
00343                      y2 = pg.attribute("cy").toDouble() * Conversion - y1;
00344                      x1 *= 2.0;
00345                      y1 *= 2.0;
00346                      static double rect[] = {1.0, 0.5, 1.0, 0.77615235,0.5, 1.0, 0.77615235, 1.0,
00347                                                                0.5, 1.0, 0.22385765, 1.0, 0.0, 0.5, 0.0, 0.77615235,
00348                                                                0.0, 0.5, 0.0, 0.22385765, 0.5, 0.0, 0.22385765, 0.0,
00349                                                                0.5, 0.0, 0.77615235, 0.0, 1.0, 0.5, 1.0, 0.22385765};
00350                      for (int a = 0; a < 29; a += 4)
00351                      {
00352                             double xa = x1 * rect[a];
00353                             double ya = y1 * rect[a+1];
00354                             double xb = x1 * rect[a+2];
00355                             double yb = y1 * rect[a+3];
00356                             PoLine.addPoint(x2+xa, y2+ya);
00357                             PoLine.addPoint(x2+xb, y2+yb);
00358                      }
00359               }
00360               else if (STag == "svg:path")
00361               {
00362                      poly = parseSVG( pg.attribute( "d" ), &PoLine );
00363                      if (PoLine.size() < 4)
00364                      {
00365                             DOC = DOC.nextSibling();
00366                             continue;
00367                      }
00368               }
00369               else if (STag == "svg:g")
00370               {
00371                      QDomNode child = DOC.firstChild();
00372                      parseGroup(data, group, child, groupElemCounter, groupElemCounter2, Dx, Dy);
00373               }
00374               if (PoLine.size() < 4)
00375               {
00376                      DOC = DOC.nextSibling();
00377                      continue;
00378               }
00379               QDomElement ob = data.createElement("ITEM");
00380               ob.setAttribute("PWIDTH", strokewidth);
00381               ob.setAttribute("PCOLOR2", StrokeCol);
00382               writeDefaults(ob);
00383               ob.setAttribute("PLINEART", Dash);
00384               ob.setAttribute("PLINEEND", LineEnd);
00385               ob.setAttribute("PLINEJOIN", LineJoin);
00386               if (groupElemCounter != 1)
00387               {
00388                      ob.setAttribute("GROUPS", 1);
00389                      ob.setAttribute("NUMGROUP", 1);
00390               }
00391               else
00392               {
00393                      ob.setAttribute("GROUPS", "");
00394                      ob.setAttribute("NUMGROUP", 0);
00395               }
00396               if ((STag == "svg:rect") || (STag == "svg:polygon") || (STag == "svg:circle") || (STag == "svg:ellipse"))
00397               {
00398                      ob.setAttribute("PTYPE", PageItem::Polygon);
00399                      ob.setAttribute("PCOLOR", FillCol);
00400               }
00401               else if ((STag == "svg:line") || (STag == "svg:polyline"))
00402               {
00403                      ob.setAttribute("PTYPE", PageItem::PolyLine);
00404                      ob.setAttribute("PCOLOR", "None");
00405               }
00406               else if (STag == "svg:path")
00407               {
00408                      if (poly)
00409                      {
00410                             ob.setAttribute("PTYPE", PageItem::PolyLine);
00411                             ob.setAttribute("PCOLOR", "None");
00412                      }
00413                      else
00414                      {
00415                             ob.setAttribute("PTYPE", PageItem::Polygon);
00416                             ob.setAttribute("PCOLOR", FillCol);
00417                      }
00418               }
00419               FPoint tp2(getMinClipF(&PoLine));
00420               PoLine.translate(-tp2.x(), -tp2.y());
00421               FPoint wh = getMaxClipF(&PoLine);
00422               ob.setAttribute("XPOS", tp2.x() - Dx);
00423               ob.setAttribute("YPOS",tp2.y() - Dy);
00424               ob.setAttribute("WIDTH",wh.x());
00425               ob.setAttribute("HEIGHT",wh.y());
00426               ob.setAttribute("NUMPO", PoLine.size());
00427               QString polp = "";
00428               double xf, yf;
00429               QString tmpSt, tmpSt2;
00430               for (uint nxx=0; nxx<PoLine.size(); ++nxx)
00431               {
00432                      PoLine.point(nxx, &xf, &yf);
00433                      polp += tmpSt.setNum(xf) + " " + tmpSt2.setNum(yf) + " ";
00434               }
00435               ob.setAttribute("POCOOR", polp);
00436               group.appendChild(ob);
00437               groupElemCounter2++;
00438               DOC = DOC.nextSibling();
00439        }
00440 }
00441 
00442 void StencilReader::parseGroupProperties(QDomDocument &data, QDomElement &group, QDomNode &DOC, int &groupElemCounter, double &minXCoor, double &minYCoor, double &maxXCoor, double &maxYCoor, bool &firstCheck)
00443 {
00444        QColor fill, stroke;
00445        QString FillCol, StrokeCol;
00446        while(!DOC.isNull())
00447        {
00448               double x1, y1, x2, y2;
00449               FPointArray PoLine;
00450               PoLine.resize(0);
00451               QDomElement pg = DOC.toElement();
00452               QString STag = pg.tagName();
00453               QString style = pg.attribute( "style", "" ).simplifyWhiteSpace();
00454               if (style.isEmpty())
00455                      style = pg.attribute( "svg:style", "" ).simplifyWhiteSpace();
00456               QStringList substyles = QStringList::split( ';', style );
00457               for( QStringList::Iterator it = substyles.begin(); it != substyles.end(); ++it )
00458               {
00459                      QStringList substyle = QStringList::split( ':', (*it) );
00460                      QString command = substyle[0].stripWhiteSpace();
00461                      QString params = substyle[1].stripWhiteSpace();
00462                      if (command == "fill")
00463                      {
00464                             if (!((params == "foreground") || (params == "background") || (params == "fg") || (params == "bg") || (params == "none") || (params == "default") || (params == "inverse")))
00465                             {
00466                                    fill.setNamedColor( params );
00467                                    FillCol = "FromDia"+fill.name();
00468                             }
00469                      }
00470                      else if (command == "stroke")
00471                      {
00472                             if (!((params == "foreground") || (params == "background") || (params == "fg") || (params == "bg") || (params == "none") || (params == "default")) || (params == "inverse"))
00473                             {
00474                                    fill.setNamedColor( params );
00475                                    FillCol = "FromDia"+fill.name();
00476                             }
00477                      }
00478                      ColorList::Iterator itc;
00479                      bool found = false;
00480                      int r, g, b;
00481                      QColor tmpR;
00482                      if ((fill == Qt::white) || (fill == Qt::black))
00483                             continue;
00484                      for (itc = PageColors.begin(); itc != PageColors.end(); ++itc)
00485                      {
00486                             if (itc.data().getColorModel() == colorModelRGB)
00487                             {
00488                                    itc.data().getRGB(&r, &g, &b);
00489                                    tmpR.setRgb(r, g, b);
00490                                    if (fill == tmpR)
00491                                    {
00492                                           FillCol = itc.key();
00493                                           found = true;
00494                                           break;
00495                                    }
00496                             }
00497                      }
00498                      if (!found)
00499                      {
00500                             ScColor tmp;
00501                             tmp.fromQColor(fill);
00502                             tmp.setSpotColor(false);
00503                             tmp.setRegistrationColor(false);
00504                             PageColors.insert(FillCol, tmp);
00505                             QDomElement co = data.createElement("COLOR");
00506                             co.setAttribute("NAME",FillCol);
00507                             co.setAttribute("RGB",fill.name());
00508                             co.setAttribute("Spot","0");
00509                             co.setAttribute("Register","0");
00510                             group.appendChild(co);
00511                      }
00512               }
00513               if (STag == "svg:line")
00514               {
00515                      x1 = pg.attribute("x1").toDouble() * Conversion;
00516                      y1 = pg.attribute("y1").toDouble() * Conversion;
00517                      x2 = pg.attribute("x2").toDouble() * Conversion;
00518                      y2 = pg.attribute("y2").toDouble() * Conversion;
00519                      PoLine.addPoint(x1, y1);
00520                      PoLine.addPoint(x1, y1);
00521                      PoLine.addPoint(x2, y2);
00522                      PoLine.addPoint(x2, y2);
00523               }
00524               else if (STag == "svg:rect")
00525               {
00526                      x1 = pg.attribute("x").toDouble() * Conversion;
00527                      y1 = pg.attribute("y").toDouble() * Conversion;
00528                      x2 = pg.attribute("width").toDouble() * Conversion;
00529                      y2 = pg.attribute("height").toDouble() * Conversion;
00530                      static double rect[] = {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
00531                                                                1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
00532                                                                0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0};
00533                      for (int a = 0; a < 29; a += 4)
00534                      {
00535                             double xa = x2 * rect[a];
00536                             double ya = y2 * rect[a+1];
00537                             double xb = x2 * rect[a+2];
00538                             double yb = y2 * rect[a+3];
00539                             PoLine.addPoint(x1+xa, y1+ya);
00540                             PoLine.addPoint(x1+xb, y1+yb);
00541                      }
00542               }
00543               else if ((STag == "svg:polygon") || (STag == "svg:polyline"))
00544               {
00545                      bool bFirst = true;
00546                      double x = 0.0;
00547                      double y = 0.0;
00548                      QString points = pg.attribute( "points" ).simplifyWhiteSpace().replace(',', " ");
00549                      QStringList pointList = QStringList::split( ' ', points );
00550                      FirstM = true;
00551                      for( QStringList::Iterator it1 = pointList.begin(); it1 != pointList.end(); it1++ )
00552                      {
00553                             if( bFirst )
00554                             {
00555                                    x = (*(it1++)).toDouble();
00556                                    y = (*it1).toDouble();
00557                                    svgMoveTo(x * Conversion, y * Conversion);
00558                                    bFirst = false;
00559                                    WasM = true;
00560                             }
00561                             else
00562                             {
00563                                    x = (*(it1++)).toDouble();
00564                                    y = (*it1).toDouble();
00565                                    svgLineTo(&PoLine, x * Conversion, y * Conversion);
00566                             }
00567                      }
00568                      if (STag == "svg:polygon")
00569                             svgClosePath(&PoLine);
00570                      if (PoLine.size() < 4)
00571                      {
00572                             DOC = DOC.nextSibling();
00573                             continue;
00574                      }
00575               }
00576               else if (STag == "svg:circle")
00577               {
00578                      x1 = pg.attribute("r").toDouble() * Conversion;
00579                      y1 = pg.attribute("r").toDouble() * Conversion;
00580                      x2 = pg.attribute("cx").toDouble() * Conversion - x1;
00581                      y2 = pg.attribute("cy").toDouble() * Conversion - y1;
00582                      x1 *= 2.0;
00583                      y1 *= 2.0;
00584                      static double rect[] = {1.0, 0.5, 1.0, 0.77615235,0.5, 1.0, 0.77615235, 1.0,
00585                                                                0.5, 1.0, 0.22385765, 1.0, 0.0, 0.5, 0.0, 0.77615235,
00586                                                                0.0, 0.5, 0.0, 0.22385765, 0.5, 0.0, 0.22385765, 0.0,
00587                                                                0.5, 0.0, 0.77615235, 0.0, 1.0, 0.5, 1.0, 0.22385765};
00588                      for (int a = 0; a < 29; a += 4)
00589                      {
00590                             double xa = x1 * rect[a];
00591                             double ya = y1 * rect[a+1];
00592                             double xb = x1 * rect[a+2];
00593                             double yb = y1 * rect[a+3];
00594                             PoLine.addPoint(x2+xa, y2+ya);
00595                             PoLine.addPoint(x2+xb, y2+yb);
00596                      }
00597               }
00598               else if (STag == "svg:ellipse")
00599               {
00600                      x1 = pg.attribute("rx").toDouble() * Conversion;
00601                      y1 = pg.attribute("ry").toDouble() * Conversion;
00602                      x2 = pg.attribute("cx").toDouble() * Conversion - x1;
00603                      y2 = pg.attribute("cy").toDouble() * Conversion - y1;
00604                      x1 *= 2.0;
00605                      y1 *= 2.0;
00606                      static double rect[] = {1.0, 0.5, 1.0, 0.77615235,0.5, 1.0, 0.77615235, 1.0,
00607                                                                0.5, 1.0, 0.22385765, 1.0, 0.0, 0.5, 0.0, 0.77615235,
00608                                                                0.0, 0.5, 0.0, 0.22385765, 0.5, 0.0, 0.22385765, 0.0,
00609                                                                0.5, 0.0, 0.77615235, 0.0, 1.0, 0.5, 1.0, 0.22385765};
00610                      for (int a = 0; a < 29; a += 4)
00611                      {
00612                             double xa = x1 * rect[a];
00613                             double ya = y1 * rect[a+1];
00614                             double xb = x1 * rect[a+2];
00615                             double yb = y1 * rect[a+3];
00616                             PoLine.addPoint(x2+xa, y2+ya);
00617                             PoLine.addPoint(x2+xb, y2+yb);
00618                      }
00619               }
00620               else if (STag == "svg:path")
00621               {
00622                      parseSVG( pg.attribute( "d" ), &PoLine );
00623                      if (PoLine.size() < 4)
00624                      {
00625                             DOC = DOC.nextSibling();
00626                             continue;
00627                      }
00628               }
00629               else if (STag == "svg:g")
00630               {
00631                      QDomNode child = DOC.firstChild();
00632                      parseGroupProperties(data, group, child, groupElemCounter, minXCoor, minYCoor, maxXCoor, maxYCoor, firstCheck);
00633               }
00634               if (PoLine.size() < 4)
00635               {
00636                      DOC = DOC.nextSibling();
00637                      continue;
00638               }
00639               groupElemCounter++;
00640               FPoint tp2(getMinClipF(&PoLine));
00641               PoLine.translate(-tp2.x(), -tp2.y());
00642               FPoint wh(getMaxClipF(&PoLine));
00643               if (firstCheck)
00644               {
00645                      minXCoor = tp2.x();
00646                      minYCoor = tp2.y();
00647                      maxXCoor = tp2.x() + wh.x();
00648                      maxYCoor = tp2.y() + wh.y();
00649                      firstCheck = false;
00650               }
00651               else
00652               {
00653                      minXCoor = QMIN(minXCoor, tp2.x());
00654                      minYCoor = QMIN(minYCoor, tp2.y());
00655                      maxXCoor = QMAX(maxXCoor, tp2.x() + wh.x());
00656                      maxYCoor = QMAX(maxYCoor, tp2.y() + wh.y());
00657               }
00658               DOC = DOC.nextSibling();
00659        }
00660 }
00661 
00662 double StencilReader::parseUnit(const QString &unit)
00663 {
00664        bool noUnit = false;
00665        QString unitval=unit;
00666        if( unit.right( 2 ) == "pt" )
00667               unitval.replace( "pt", "" );
00668        else if( unit.right( 2 ) == "cm" )
00669               unitval.replace( "cm", "" );
00670        else if( unit.right( 2 ) == "mm" )
00671               unitval.replace( "mm" , "" );
00672        else if( unit.right( 2 ) == "in" )
00673               unitval.replace( "in", "" );
00674        else if( unit.right( 2 ) == "px" )
00675               unitval.replace( "px", "" );
00676        if (unitval == unit)
00677               noUnit = true;
00678        double value = unitval.toDouble();
00679        if( unit.right( 2 ) == "pt" )
00680               value = value;
00681        else if( unit.right( 2 ) == "cm" )
00682        {
00683               value = ( value / 2.54 ) * 72;
00684               Conversion = 72.0 / 2.54;
00685        }
00686        else if( unit.right( 2 ) == "mm" )
00687        {
00688               value = ( value / 25.4 ) * 72;
00689               Conversion = 72.0 / 25.4;
00690        }
00691        else if( unit.right( 2 ) == "in" )
00692        {
00693               value = value * 72;
00694               Conversion = 72.0;
00695        }
00696        else if( unit.right( 2 ) == "px" )
00697        {
00698               value = value * 0.8;
00699               Conversion = 0.8;
00700        }
00701        else if(noUnit)
00702               value = value;
00703        return value;
00704 }
00705 
00706 const char * StencilReader::getCoord( const char *ptr, double &number )
00707 {
00708        int integer, exponent;
00709        double decimal, frac;
00710        int sign, expsign;
00711 
00712        exponent = 0;
00713        integer = 0;
00714        frac = 1.0;
00715        decimal = 0;
00716        sign = 1;
00717        expsign = 1;
00718 
00719        // read the sign
00720        if(*ptr == '+')
00721               ptr++;
00722        else if(*ptr == '-')
00723        {
00724               ptr++;
00725               sign = -1;
00726        }
00727 
00728        // read the integer part
00729        while(*ptr != '\0' && *ptr >= '0' && *ptr <= '9')
00730               integer = (integer * 10) + *(ptr++) - '0';
00731        if(*ptr == '.') // read the decimals
00732        {
00733               ptr++;
00734               while(*ptr != '\0' && *ptr >= '0' && *ptr <= '9')
00735                      decimal += (*(ptr++) - '0') * (frac *= 0.1);
00736        }
00737 
00738        if(*ptr == 'e' || *ptr == 'E') // read the exponent part
00739        {
00740               ptr++;
00741 
00742               // read the sign of the exponent
00743               if(*ptr == '+')
00744                      ptr++;
00745               else if(*ptr == '-')
00746               {
00747                      ptr++;
00748                      expsign = -1;
00749               }
00750 
00751               exponent = 0;
00752               while(*ptr != '\0' && *ptr >= '0' && *ptr <= '9')
00753               {
00754                      exponent *= 10;
00755                      exponent += *ptr - '0';
00756                      ptr++;
00757               }
00758        }
00759        number = integer + decimal;
00760        number *= sign * pow( static_cast<double>(10), static_cast<double>( expsign * exponent ) );
00761        // skip the following space
00762        if(*ptr == ' ')
00763               ptr++;
00764 
00765        return ptr;
00766 }
00767 
00768 bool StencilReader::parseSVG( const QString &s, FPointArray *ite )
00769 {
00770        QString d = s;
00771        d = d.replace( QRegExp( "," ), " ");
00772        bool ret = false;
00773        if( !d.isEmpty() )
00774        {
00775               d = d.simplifyWhiteSpace();
00776               const char *ptr = d.latin1();
00777               const char *end = d.latin1() + d.length() + 1;
00778               double contrlx, contrly, curx, cury, subpathx, subpathy, tox, toy, x1, y1, x2, y2, xc, yc;
00779               double px1, py1, px2, py2, px3, py3;
00780               bool relative;
00781               FirstM = true;
00782               char command = *(ptr++), lastCommand = ' ';
00783               subpathx = subpathy = curx = cury = contrlx = contrly = 0.0;
00784               while( ptr < end )
00785               {
00786                      if( *ptr == ' ' )
00787                             ptr++;
00788                      relative = false;
00789                      switch( command )
00790                      {
00791                      case 'm':
00792                             relative = true;
00793                      case 'M':
00794                             {
00795                                    ptr = getCoord( ptr, tox );
00796                                    ptr = getCoord( ptr, toy );
00797                                    tox *= Conversion;
00798                                    toy *= Conversion;
00799                                    WasM = true;
00800                                    subpathx = curx = relative ? curx + tox : tox;
00801                                    subpathy = cury = relative ? cury + toy : toy;
00802                                    svgMoveTo(curx, cury );
00803                                    break;
00804                             }
00805                      case 'l':
00806                             relative = true;
00807                      case 'L':
00808                             {
00809                                    ptr = getCoord( ptr, tox );
00810                                    ptr = getCoord( ptr, toy );
00811                                    tox *= Conversion;
00812                                    toy *= Conversion;
00813                                    curx = relative ? curx + tox : tox;
00814                                    cury = relative ? cury + toy : toy;
00815                                    svgLineTo(ite, curx, cury );
00816                                    break;
00817                             }
00818                      case 'h':
00819                             {
00820                                    ptr = getCoord( ptr, tox );
00821                                    tox *= Conversion;
00822                                    curx = curx + tox;
00823                                    svgLineTo(ite, curx, cury );
00824                                    break;
00825                             }
00826                      case 'H':
00827                             {
00828                                    ptr = getCoord( ptr, tox );
00829                                    tox *= Conversion;
00830                                    curx = tox;
00831                                    svgLineTo(ite, curx, cury );
00832                                    break;
00833                             }
00834                      case 'v':
00835                             {
00836                                    ptr = getCoord( ptr, toy );
00837                                    toy *= Conversion;
00838                                    cury = cury + toy;
00839                                    svgLineTo(ite, curx, cury );
00840                                    break;
00841                             }
00842                      case 'V':
00843                             {
00844                                    ptr = getCoord( ptr, toy );
00845                                    toy *= Conversion;
00846                                    cury = toy;
00847                                    svgLineTo(ite,  curx, cury );
00848                                    break;
00849                             }
00850                      case 'z':
00851                      case 'Z':
00852                             {
00853                                    curx = subpathx;
00854                                    cury = subpathy;
00855                                    svgClosePath(ite);
00856                                    break;
00857                             }
00858                      case 'c':
00859                             relative = true;
00860                      case 'C':
00861                             {
00862                                    ptr = getCoord( ptr, x1 );
00863                                    ptr = getCoord( ptr, y1 );
00864                                    ptr = getCoord( ptr, x2 );
00865                                    ptr = getCoord( ptr, y2 );
00866                                    ptr = getCoord( ptr, tox );
00867                                    ptr = getCoord( ptr, toy );
00868                                    tox *= Conversion;
00869                                    toy *= Conversion;
00870                                    x1 *= Conversion;
00871                                    y1 *= Conversion;
00872                                    x2 *= Conversion;
00873                                    y2 *= Conversion;
00874                                    px1 = relative ? curx + x1 : x1;
00875                                    py1 = relative ? cury + y1 : y1;
00876                                    px2 = relative ? curx + x2 : x2;
00877                                    py2 = relative ? cury + y2 : y2;
00878                                    px3 = relative ? curx + tox : tox;
00879                                    py3 = relative ? cury + toy : toy;
00880                                    svgCurveToCubic(ite, px1, py1, px2, py2, px3, py3 );
00881                                    contrlx = relative ? curx + x2 : x2;
00882                                    contrly = relative ? cury + y2 : y2;
00883                                    curx = relative ? curx + tox : tox;
00884                                    cury = relative ? cury + toy : toy;
00885                                    break;
00886                             }
00887                      case 's':
00888                             relative = true;
00889                      case 'S':
00890                             {
00891                                    ptr = getCoord( ptr, x2 );
00892                                    ptr = getCoord( ptr, y2 );
00893                                    ptr = getCoord( ptr, tox );
00894                                    ptr = getCoord( ptr, toy );
00895                                    tox *= Conversion;
00896                                    toy *= Conversion;
00897                                    x2 *= Conversion;
00898                                    y2 *= Conversion;
00899                                    px1 = 2 * curx - contrlx;
00900                                    py1 = 2 * cury - contrly;
00901                                    px2 = relative ? curx + x2 : x2;
00902                                    py2 = relative ? cury + y2 : y2;
00903                                    px3 = relative ? curx + tox : tox;
00904                                    py3 = relative ? cury + toy : toy;
00905                                    svgCurveToCubic(ite, px1, py1, px2, py2, px3, py3 );
00906                                    contrlx = relative ? curx + x2 : x2;
00907                                    contrly = relative ? cury + y2 : y2;
00908                                    curx = relative ? curx + tox : tox;
00909                                    cury = relative ? cury + toy : toy;
00910                                    break;
00911                             }
00912                      case 'q':
00913                             relative = true;
00914                      case 'Q':
00915                             {
00916                                    ptr = getCoord( ptr, x1 );
00917                                    ptr = getCoord( ptr, y1 );
00918                                    ptr = getCoord( ptr, tox );
00919                                    ptr = getCoord( ptr, toy );
00920                                    tox *= Conversion;
00921                                    toy *= Conversion;
00922                                    x1 *= Conversion;
00923                                    y1 *= Conversion;
00924                                    px1 = relative ? (curx + 2 * (x1 + curx)) * (1.0 / 3.0) : (curx + 2 * x1) * (1.0 / 3.0);
00925                                    py1 = relative ? (cury + 2 * (y1 + cury)) * (1.0 / 3.0) : (cury + 2 * y1) * (1.0 / 3.0);
00926                                    px2 = relative ? ((curx + tox) + 2 * (x1 + curx)) * (1.0 / 3.0) : (tox + 2 * x1) * (1.0 / 3.0);
00927                                    py2 = relative ? ((cury + toy) + 2 * (y1 + cury)) * (1.0 / 3.0) : (toy + 2 * y1) * (1.0 / 3.0);
00928                                    px3 = relative ? curx + tox : tox;
00929                                    py3 = relative ? cury + toy : toy;
00930                                    svgCurveToCubic(ite, px1, py1, px2, py2, px3, py3 );
00931                                    contrlx = relative ? curx + x1 : (tox + 2 * x1) * (1.0 / 3.0);
00932                                    contrly = relative ? cury + y1 : (toy + 2 * y1) * (1.0 / 3.0);
00933                                    curx = relative ? curx + tox : tox;
00934                                    cury = relative ? cury + toy : toy;
00935                                    break;
00936                             }
00937                      case 't':
00938                             relative = true;
00939                      case 'T':
00940                             {
00941                                    ptr = getCoord(ptr, tox);
00942                                    ptr = getCoord(ptr, toy);
00943                                    tox *= Conversion;
00944                                    toy *= Conversion;
00945                                    xc = 2 * curx - contrlx;
00946                                    yc = 2 * cury - contrly;
00947                                    px1 = relative ? (curx + 2 * xc) * (1.0 / 3.0) : (curx + 2 * xc) * (1.0 / 3.0);
00948                                    py1 = relative ? (cury + 2 * yc) * (1.0 / 3.0) : (cury + 2 * yc) * (1.0 / 3.0);
00949                                    px2 = relative ? ((curx + tox) + 2 * xc) * (1.0 / 3.0) : (tox + 2 * xc) * (1.0 / 3.0);
00950                                    py2 = relative ? ((cury + toy) + 2 * yc) * (1.0 / 3.0) : (toy + 2 * yc) * (1.0 / 3.0);
00951                                    px3 = relative ? curx + tox : tox;
00952                                    py3 = relative ? cury + toy : toy;
00953                                    svgCurveToCubic(ite, px1, py1, px2, py2, px3, py3 );
00954                                    contrlx = xc;
00955                                    contrly = yc;
00956                                    curx = relative ? curx + tox : tox;
00957                                    cury = relative ? cury + toy : toy;
00958                                    break;
00959                             }
00960                      }
00961                      lastCommand = command;
00962                      if(*ptr == '+' || *ptr == '-' || (*ptr >= '0' && *ptr <= '9'))
00963                      {
00964                             // there are still coords in this command
00965                             if(command == 'M')
00966                                    command = 'L';
00967                             else if(command == 'm')
00968                                    command = 'l';
00969                      }
00970                      else
00971                             command = *(ptr++);
00972 
00973                      if( lastCommand != 'C' && lastCommand != 'c' &&
00974                              lastCommand != 'S' && lastCommand != 's' &&
00975                              lastCommand != 'Q' && lastCommand != 'q' &&
00976                              lastCommand != 'T' && lastCommand != 't')
00977                      {
00978                             contrlx = curx;
00979                             contrly = cury;
00980                      }
00981               }
00982               if ((lastCommand != 'z') && (lastCommand != 'Z'))
00983                      ret = true;
00984               if (ite->size() > 2)
00985               {
00986                      if ((ite->point(0).x() == ite->point(ite->size()-2).x()) && (ite->point(0).y() == ite->point(ite->size()-2).y()))
00987                             ret = false;
00988               }
00989        }
00990        return ret;
00991 }
00992 
00993 void StencilReader::svgMoveTo(double x1, double y1)
00994 {
00995        CurrX = x1;
00996        CurrY = y1;
00997        StartX = x1;
00998        StartY = y1;
00999        PathLen = 0;
01000 }
01001 
01002 void StencilReader::svgLineTo(FPointArray *i, double x1, double y1)
01003 {
01004        if ((!FirstM) && (WasM))
01005        {
01006               i->setMarker();
01007               PathLen += 4;
01008        }
01009        FirstM = false;
01010        WasM = false;
01011        if (i->size() > 3)
01012        {
01013               FPoint b1 = i->point(i->size()-4);
01014               FPoint b2 = i->point(i->size()-3);
01015               FPoint b3 = i->point(i->size()-2);
01016               FPoint b4 = i->point(i->size()-1);
01017               FPoint n1 = FPoint(CurrX, CurrY);
01018               FPoint n2 = FPoint(x1, y1);
01019               if ((b1 == n1) && (b2 == n1) && (b3 == n2) && (b4 == n2))
01020                      return;
01021        }
01022        i->addPoint(FPoint(CurrX, CurrY));
01023        i->addPoint(FPoint(CurrX, CurrY));
01024        i->addPoint(FPoint(x1, y1));
01025        i->addPoint(FPoint(x1, y1));
01026        CurrX = x1;
01027        CurrY = y1;
01028        PathLen += 4;
01029 }
01030 
01031 void StencilReader::svgCurveToCubic(FPointArray *i, double x1, double y1, double x2, double y2, double x3, double y3)
01032 {
01033        if ((!FirstM) && (WasM))
01034        {
01035               i->setMarker();
01036               PathLen += 4;
01037        }
01038        FirstM = false;
01039        WasM = false;
01040        if (PathLen > 3)
01041        {
01042               FPoint b1 = i->point(i->size()-4);
01043               FPoint b2 = i->point(i->size()-3);
01044               FPoint b3 = i->point(i->size()-2);
01045               FPoint b4 = i->point(i->size()-1);
01046               FPoint n1 = FPoint(CurrX, CurrY);
01047               FPoint n2 = FPoint(x1, y1);
01048               FPoint n3 = FPoint(x3, y3);
01049               FPoint n4 = FPoint(x2, y2);
01050               if ((b1 == n1) && (b2 == n2) && (b3 == n3) && (b4 == n4))
01051                      return;
01052        }
01053        i->addPoint(FPoint(CurrX, CurrY));
01054        i->addPoint(FPoint(x1, y1));
01055        i->addPoint(FPoint(x3, y3));
01056        i->addPoint(FPoint(x2, y2));
01057        CurrX = x3;
01058        CurrY = y3;
01059        PathLen += 4;
01060 }
01061 
01062 void StencilReader::svgClosePath(FPointArray *i)
01063 {
01064        if (PathLen > 2)
01065        {
01066               if ((PathLen == 4) || (i->point(i->size()-2).x() != StartX) || (i->point(i->size()-2).y() != StartY))
01067               {
01068                      i->addPoint(i->point(i->size()-2));
01069                      i->addPoint(i->point(i->size()-3));
01070                      i->addPoint(FPoint(StartX, StartY));
01071                      i->addPoint(FPoint(StartX, StartY));
01072               }
01073        }
01074 }
01075 
01076 QPixmap StencilReader::createPreview(QString data)
01077 {
01078        double pmmax;
01079        double GrW = 50.0;
01080        double GrH = 50.0;
01081        QPixmap tmp = QPixmap(0, 0);
01082        QColor stroke = Qt::black;
01083        QColor fill = Qt::white;
01084        Qt::PenStyle Dash = Qt::SolidLine;
01085        Qt::PenCapStyle LineEnd = Qt::FlatCap;
01086        Qt::PenJoinStyle LineJoin = Qt::MiterJoin;
01087        int fillStyle = 1;
01088        ScPainter *pS = NULL;
01089        double strokewidth = 1.0;
01090        QDomDocument docu("scridoc");
01091        docu.setContent(data);
01092        QDomElement elem=docu.documentElement();
01093        if (elem.tagName() != "KivioShapeStencil")
01094               return tmp;
01095        QDomNodeList list = elem.elementsByTagName("Dimensions");
01096        if (list.count() == 0)
01097               return tmp;
01098        QDomElement dims = list.item(0).toElement();
01099        GrW = dims.attribute("w","50").toDouble()+10;
01100        GrH = dims.attribute("h","50").toDouble()+10;
01101        pmmax = 60 / QMAX(GrW, GrH);
01102        tmp = QPixmap(static_cast<int>(GrW), static_cast<int>(GrH));
01103        pS = new ScPainter(&tmp, tmp.width(), tmp.height());
01104        pS->translate(5, 5);
01105        QDomNode DOC=elem.firstChild();
01106        while(!DOC.isNull())
01107        {
01108               QDomElement pg=DOC.toElement();
01109               if(pg.tagName()=="KivioShape")
01110               {
01111                      stroke = Qt::black;
01112                      fill = Qt::white;
01113                      fillStyle = 1;
01114                      strokewidth = 1.0;
01115                      Dash = Qt::SolidLine;
01116                      LineEnd = Qt::FlatCap;
01117                      LineJoin = Qt::MiterJoin;
01118                      FPointArray PoLine;
01119                      PoLine.resize(0);
01120                      double x = 0.0;
01121                      double y = 0.0;
01122                      double x1 = 0.0;
01123                      double y1 = 0.0;
01124                      double currx = 0.0;
01125                      double curry = 0.0;
01126                      double startx = 0.0;
01127                      double starty = 0.0;
01128                      QString typ = pg.attribute("type");
01129                      QDomNode point = DOC.firstChild();
01130                      bool first = true;
01131                      int count = 0;
01132                      while(!point.isNull())
01133                      {
01134                             QDomElement pt = point.toElement();
01135                             if(pt.tagName()=="KivioFillStyle")
01136                             {
01137                                    QString colnam = pt.attribute("color","#000000");
01138                                    fill.setNamedColor("#"+colnam.right(6));
01139                                    fillStyle = pt.attribute("colorStyle","1").toInt();
01140                             }
01141                             if(pt.tagName()=="KivioLineStyle")
01142                             {
01143                                    QString colnam = pt.attribute("color","#FFFFFF");
01144                                    stroke.setNamedColor("#"+colnam.right(6));
01145                                    strokewidth = pt.attribute("width", "1").toDouble();
01146                                    LineJoin = Qt::PenJoinStyle(pt.attribute("joinStyle", "0").toInt());
01147                                    Dash = Qt::PenStyle(pt.attribute("pattern").toInt());
01148                                    LineEnd = Qt::PenCapStyle(pt.attribute("capStyle", "0").toInt());
01149                             }
01150                             if(pt.tagName()=="KivioPoint")
01151                             {
01152                                    x = pt.attribute("x").toDouble();
01153                                    y = pt.attribute("y").toDouble();
01154                                    if (first)
01155                                    {
01156                                           currx = x;
01157                                           curry = y;
01158                                           startx = x;
01159                                           starty = y;
01160                                           first = false;
01161                                           if (pt.attribute("type") == "bezier")
01162                                                  count = 0;
01163                                           else
01164                                                  count = -1;
01165                                    }
01166                                    else
01167                                    {
01168                                           if (pt.attribute("type") != "bezier")
01169                                           {
01170                                                  PoLine.addPoint(currx, curry);
01171                                                  PoLine.addPoint(currx, curry);
01172                                                  PoLine.addPoint(x, y);
01173                                                  PoLine.addPoint(x, y);
01174                                                  currx = x;
01175                                                  curry = y;
01176                                           }
01177                                           else
01178                                           {
01179                                                  if (count == -1)
01180                                                  {
01181                                                         if (FPoint(currx, curry) != FPoint(x, y))
01182                                                         {
01183                                                                PoLine.addPoint(currx, curry);
01184                                                                PoLine.addPoint(currx, curry);
01185                                                                PoLine.addPoint(x, y);
01186                                                                PoLine.addPoint(x, y);
01187                                                         }
01188                                                         currx = x;
01189                                                         curry = y;
01190                                                         count++;
01191                                                  }
01192                                                  else if (count == 0)
01193                                                  {
01194                                                         PoLine.addPoint(currx, curry);
01195                                                         PoLine.addPoint(x, y);
01196                                                         count++;
01197                                                  }
01198                                                  else if (count == 1)
01199                                                  {
01200                                                         currx = x;
01201                                                         curry = y;
01202                                                         count++;
01203                                                  }
01204                                                  else if (count == 2)
01205                                                  {
01206                                                         PoLine.addPoint(x, y);
01207                                                         PoLine.addPoint(currx, curry);
01208                                                         currx = x;
01209                                                         curry = y;
01210                                                         count = -1;
01211                                                  }
01212                                           }
01213                                    }
01214                             }
01215                             if(pt.tagName()=="Line")
01216                             {
01217                                    if (!first)
01218                                           PoLine.setMarker();
01219                                    x = pt.attribute("x1").toDouble();
01220                                    y = pt.attribute("y1").toDouble();
01221                                    x1 = pt.attribute("x2").toDouble();
01222                                    y1 = pt.attribute("y2").toDouble();
01223                                    PoLine.addPoint(x, y);
01224                                    PoLine.addPoint(x, y);
01225                                    PoLine.addPoint(x1, y1);
01226                                    PoLine.addPoint(x1, y1);
01227                                    first = false;
01228                             }
01229                             point = point.nextSibling();
01230                      }
01231                      if ((typ == "Polygon") || (typ == "ClosedPath"))
01232                      {
01233                             pS->setBrush(fill);
01234                             pS->setFillMode(fillStyle);
01235                             pS->setLineWidth(strokewidth);
01236                             pS->setPen(stroke);
01237                             pS->setupPolygon(&PoLine);
01238                             pS->drawPolygon();
01239                             pS->drawPolyLine();
01240                      }
01241                      else if ((typ == "Bezier") || (typ == "OpenPath") || (typ == "LineArray") || (typ == "Polyline"))
01242                      {
01243                             pS->setPen(stroke, strokewidth, Dash, LineEnd, LineJoin);
01244                             pS->setupPolygon(&PoLine, false);
01245                             pS->drawPolyLine();
01246                      }
01247                      if (typ == "Rectangle")
01248                      {
01249                             pS->setBrush(fill);
01250                             pS->setFillMode(fillStyle);
01251                             pS->setPen(stroke, strokewidth, Dash, LineEnd, LineJoin);
01252                             x = pg.attribute("x").toDouble();
01253                             y = pg.attribute("y").toDouble();
01254                             x1 = pg.attribute("w").toDouble();
01255                             y1 = pg.attribute("h").toDouble();
01256                             static double rect[] = {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
01257                                                                       1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
01258                                                                       0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0};
01259                             PoLine.resize(0);
01260                             for (int a = 0; a < 29; a += 4)
01261                             {
01262                                    double xa = x1 * rect[a];
01263                                    double ya = y1 * rect[a+1];
01264                                    double xb = x1 * rect[a+2];
01265                                    double yb = y1 * rect[a+3];
01266                                    PoLine.addPoint(x+xa, y+ya);
01267                                    PoLine.addPoint(x+xb, y+yb);
01268                             }
01269                             pS->setupPolygon(&PoLine);
01270                             pS->drawPolygon();
01271                             pS->drawPolyLine();
01272                      }
01273                      if (typ == "Ellipse")
01274                      {
01275                             pS->setBrush(fill);
01276                             pS->setFillMode(fillStyle);
01277                             pS->setPen(stroke, strokewidth, Dash, LineEnd, LineJoin);
01278                             x = pg.attribute("x").toDouble();
01279                             y = pg.attribute("y").toDouble();
01280                             x1 = pg.attribute("w").toDouble();
01281                             y1 = pg.attribute("h").toDouble();
01282                             static double rect[] = {1.0, 0.5, 1.0, 0.77615235,0.5, 1.0, 0.77615235, 1.0,
01283                                                                       0.5, 1.0, 0.22385765, 1.0, 0.0, 0.5, 0.0, 0.77615235,
01284                                                                       0.0, 0.5, 0.0, 0.22385765, 0.5, 0.0, 0.22385765, 0.0,
01285                                                                       0.5, 0.0, 0.77615235, 0.0, 1.0, 0.5, 1.0, 0.22385765};
01286                             PoLine.resize(0);
01287                             for (int a = 0; a < 29; a += 4)
01288                             {
01289                                    double xa = x1 * rect[a];
01290                                    double ya = y1 * rect[a+1];
01291                                    double xb = x1 * rect[a+2];
01292                                    double yb = y1 * rect[a+3];
01293                                    PoLine.addPoint(x+xa, y+ya);
01294                                    PoLine.addPoint(x+xb, y+yb);
01295                             }
01296                             pS->setupPolygon(&PoLine);
01297                             pS->drawPolygon();
01298                             pS->drawPolyLine();
01299                      }
01300               }
01301               DOC = DOC.nextSibling();
01302        }
01303        if (pS)
01304        {
01305               pS->end();
01306               delete pS;
01307        }
01308        QImage tmpi1 = tmp.convertToImage();
01309        QImage tmpi = tmpi1.smoothScale(static_cast<int>(tmp.width()*pmmax), static_cast<int>(tmp.height()*pmmax));
01310        tmp.convertFromImage(tmpi);
01311        return tmp;
01312 }
01313 
01314 void StencilReader::writeDefaults(QDomElement &ob)
01315 {
01316        PrefsManager* prefsManager = PrefsManager::instance();
01317        ob.setAttribute("OwnPage", 0);
01318        ob.setAttribute("RADRECT", 0);
01319        ob.setAttribute("FRTYPE",  3);
01320        ob.setAttribute("CLIPEDIT", 1);
01321        ob.setAttribute("TXTFILL", prefsManager->appPrefs.toolSettings.dPenText);
01322        ob.setAttribute("TXTSTROKE", prefsManager->appPrefs.toolSettings.dStrokeText);
01323        ob.setAttribute("TXTSTRSH", 100);
01324        ob.setAttribute("TXTFILLSH", 100);
01325        ob.setAttribute("TXTSCALE", 100);
01326        ob.setAttribute("TXTSCALEV", 100);
01327        ob.setAttribute("TXTBASE", 0);
01328        ob.setAttribute("TXTSHX", 0);
01329        ob.setAttribute("TXTSHY", 0);
01330        ob.setAttribute("TXTOUT", 0);
01331        ob.setAttribute("TXTULP", 0);
01332        ob.setAttribute("TXTULW", 0);
01333        ob.setAttribute("TXTSTP", 0);
01334        ob.setAttribute("TXTSTW", 0);
01335        ob.setAttribute("TXTSTYLE", 0);
01336        ob.setAttribute("COLUMNS", 1);
01337        ob.setAttribute("COLGAP", 0);
01338        ob.setAttribute("NAMEDLST", "");
01339        ob.setAttribute("SHADE", 100);
01340        ob.setAttribute("SHADE2", 100);
01341        ob.setAttribute("GRTYP", 0);
01342        ob.setAttribute("ROT", 0);
01343        ob.setAttribute("LINESP", 12);
01344        ob.setAttribute("LINESPMode", 0);
01345        ob.setAttribute("TXTKERN", 0);
01346        ob.setAttribute("LOCALSCX", 100);
01347        ob.setAttribute("LOCALSCY", 100);
01348        ob.setAttribute("LOCALX", 0);
01349        ob.setAttribute("LOCALY", 0);
01350        ob.setAttribute("PICART",  1);
01351        ob.setAttribute("PLTSHOW", 0);
01352        ob.setAttribute("BASEOF", 0);
01353        ob.setAttribute("FLIPPEDH", 0);
01354        ob.setAttribute("FLIPPEDV", 0);
01355        ob.setAttribute("IFONT", prefsManager->appPrefs.toolSettings.defFont);
01356        ob.setAttribute("ISIZE", prefsManager->appPrefs.toolSettings.defSize / 10.0);
01357        ob.setAttribute("SCALETYPE", 1);
01358        ob.setAttribute("RATIO", 0);
01359        ob.setAttribute("PRINTABLE", 1);
01360        ob.setAttribute("ALIGN", "0");
01361        ob.setAttribute("BOOKMARK", "0");
01362        ob.setAttribute("fillRule", "1");
01363        ob.setAttribute("TEXTFLOW",  0);
01364        ob.setAttribute("TEXTFLOW2",  0);
01365        ob.setAttribute("TEXTFLOW3",  0);
01366        ob.setAttribute("AUTOTEXT",  0);
01367        ob.setAttribute("EXTRA", 1);
01368        ob.setAttribute("TEXTRA", 1);
01369        ob.setAttribute("BEXTRA", 1);
01370        ob.setAttribute("REXTRA", 1);
01371        ob.setAttribute("PFILE","");
01372        ob.setAttribute("PFILE2","");
01373        ob.setAttribute("PFILE3","");
01374        ob.setAttribute("PRFILE", "");
01375        ob.setAttribute("EPROF", "");
01376        ob.setAttribute("IRENDER", 1);
01377        ob.setAttribute("EMBEDDED", 1);
01378        ob.setAttribute("LOCK",  0);
01379        ob.setAttribute("LOCKR",  0);
01380        ob.setAttribute("REVERS",  0);
01381        ob.setAttribute("TransValue", 0);
01382        ob.setAttribute("TransValueS", 0);
01383        ob.setAttribute("isTableItem", 0);
01384        ob.setAttribute("TopLine", 0);
01385        ob.setAttribute("LeftLine", 0);
01386        ob.setAttribute("RightLine", 0);
01387        ob.setAttribute("BottomLine", 0);
01388        ob.setAttribute("LANGUAGE", prefsManager->appPrefs.Language);
01389        ob.setAttribute("startArrowIndex", 0);
01390        ob.setAttribute("endArrowIndex", 0);
01391        ob.setAttribute("NUMDASH", 0);
01392        ob.setAttribute("DASHS", "");
01393        ob.setAttribute("DASHOFF", 0);
01394        ob.setAttribute("NUMTEXT", 0);
01395        ob.setAttribute("TEXTCOOR", "");
01396        ob.setAttribute("BACKITEM", -1);
01397        ob.setAttribute("BACKPAGE", -1);
01398        ob.setAttribute("NEXTITEM", -1);
01399        ob.setAttribute("NEXTPAGE", -1);
01400        ob.setAttribute("NUMCO", 0);
01401        ob.setAttribute("COCOOR", "");
01402 }
01403 
01404 QString StencilReader::createObjects(QString datain)
01405 {
01406        double GrW = 50.0;
01407        double GrH = 50.0;
01408        QString tmp = "";
01409        QColor stroke = Qt::black;
01410        QColor fill = Qt::white;
01411        Qt::PenStyle Dash = Qt::SolidLine;
01412        Qt::PenCapStyle LineEnd = Qt::FlatCap;
01413        Qt::PenJoinStyle LineJoin = Qt::MiterJoin;
01414        int fillStyle = 1;
01415        double strokewidth = 1.0;
01416        QString FillCol = "White";
01417        QString StrokeCol = "Black";
01418        QDomDocument docu("scridoc");
01419        docu.setContent(datain);
01420        QDomElement elem=docu.documentElement();
01421        if (elem.tagName() != "KivioShapeStencil")
01422               return "";
01423        QDomNodeList list = elem.elementsByTagName("Dimensions");
01424        if (list.count() == 0)
01425               return tmp;
01426        QString name = "KivioGroup";
01427        QDomNodeList descList = elem.elementsByTagName("Title");
01428        if (descList.count() != 0)
01429        {
01430               QDomElement namElem = descList.item(0).toElement();
01431               name = namElem.attribute("data", "");
01432        }
01433        QDomDocument data("scribus");
01434        QString st="<SCRIBUSELEMUTF8></SCRIBUSELEMUTF8>";
01435        data.setContent(st);
01436        QDomElement group = data.documentElement();
01437        QDomNodeList listItems = elem.elementsByTagName("KivioShape");
01438        QDomElement dims = list.item(0).toElement();
01439        GrW = dims.attribute("w","50").toDouble();
01440        GrH = dims.attribute("h","50").toDouble();
01441        group.setAttribute("W", GrW);
01442        group.setAttribute("H", GrH);
01443        group.setAttribute("XP", 0.0);
01444        group.setAttribute("YP", 0.0);
01445        group.setAttribute("Version", QString(VERSION));
01446 
01447        PageColors.insert("Black", ScColor(0, 0, 0, 255));
01448        QDomElement co = data.createElement("COLOR");
01449        co.setAttribute("NAME","Black");
01450        co.setAttribute("CMYK", "#000000FF");
01451        co.setAttribute("Spot","0");
01452        co.setAttribute("Register","0");
01453        group.appendChild(co);
01454        PageColors.insert("White", ScColor(0, 0, 0, 0));
01455        QDomElement co2 = data.createElement("COLOR");
01456        co2.setAttribute("NAME","White");
01457        co2.setAttribute("CMYK", "#00000000");
01458        co2.setAttribute("Spot","0");
01459        co2.setAttribute("Register","0");
01460        group.appendChild(co2);
01461        QDomNodeList listStrokes = elem.elementsByTagName("KivioLineStyle");
01462        for (uint st = 0; st < listStrokes.count(); st++)
01463        {
01464               QDomElement str = listStrokes.item(st).toElement();
01465               QString colnam = str.attribute("color","#ffffff");
01466               stroke.setNamedColor("#"+colnam.right(6));
01467               if ((stroke == Qt::white) || (stroke == Qt::black))
01468                      continue;
01469               ColorList::Iterator it;
01470               bool found = false;
01471               int r, g, b;
01472               QColor tmpR;
01473               for (it = PageColors.begin(); it != PageColors.end(); ++it)
01474               {
01475                      if (it.data().getColorModel() == colorModelRGB)
01476                      {
01477                             it.data().getRGB(&r, &g, &b);
01478                             tmpR.setRgb(r, g, b);
01479                             if (stroke == tmpR)
01480                             {
01481                                    StrokeCol = it.key();
01482                                    found = true;
01483                                    break;
01484                             }
01485                      }
01486               }
01487               if (!found)
01488               {
01489                      ScColor tmp;
01490                      tmp.fromQColor(stroke);
01491                      tmp.setSpotColor(false);
01492                      tmp.setRegistrationColor(false);
01493                      PageColors.insert("FromKivio"+stroke.name(), tmp);
01494                      StrokeCol = "FromKivio"+stroke.name();
01495                      QDomElement co = data.createElement("COLOR");
01496                      co.setAttribute("NAME",StrokeCol);
01497                      co.setAttribute("RGB",stroke.name());
01498                      co.setAttribute("Spot","0");
01499                      co.setAttribute("Register","0");
01500                      group.appendChild(co);
01501               }
01502        }
01503        QDomNodeList listFills = elem.elementsByTagName("KivioFillStyle");
01504        for (uint st = 0; st < listFills.count(); st++)
01505        {
01506               QDomElement fil = listFills.item(st).toElement();
01507               QString colnam = fil.attribute("color","#ffffff");
01508               fill.setNamedColor("#"+colnam.right(6));
01509               ColorList::Iterator it;
01510               bool found = false;
01511               int r, g, b;
01512               QColor tmpR;
01513               if ((fill == Qt::white) || (fill == Qt::black))
01514                      continue;
01515               for (it = PageColors.begin(); it != PageColors.end(); ++it)
01516               {
01517                      if (it.data().getColorModel() == colorModelRGB)
01518                      {
01519                             it.data().getRGB(&r, &g, &b);
01520                             tmpR.setRgb(r, g, b);
01521                             if (fill == tmpR)
01522                             {
01523                                    FillCol = it.key();
01524                                    found = true;
01525                                    break;
01526                             }
01527                      }
01528               }
01529               if (!found)
01530               {
01531                      ScColor tmp;
01532                      tmp.fromQColor(fill);
01533                      tmp.setSpotColor(false);
01534                      tmp.setRegistrationColor(false);
01535                      PageColors.insert("FromKivio"+fill.name(), tmp);
01536                      FillCol = "FromKivio"+fill.name();
01537                      QDomElement co = data.createElement("COLOR");
01538                      co.setAttribute("NAME",FillCol);
01539                      co.setAttribute("RGB",fill.name());
01540                      co.setAttribute("Spot","0");
01541                      co.setAttribute("Register","0");
01542                      group.appendChild(co);
01543               }
01544        }
01545        QDomElement obGroup;
01546        int groupElemCounter = 0;
01547        if (listItems.count() != 1)
01548        {
01549               group.setAttribute("COUNT", listItems.count()+1);
01550               obGroup = data.createElement("ITEM");
01551               writeDefaults(obGroup);
01552               obGroup.setAttribute("PWIDTH", 0);
01553               obGroup.setAttribute("PCOLOR", "None");
01554               obGroup.setAttribute("PCOLOR2", "None");
01555               obGroup.setAttribute("PLINEART", Dash);
01556               obGroup.setAttribute("PLINEEND", LineEnd);
01557               obGroup.setAttribute("PLINEJOIN", LineJoin);
01558               obGroup.setAttribute("ANNAME", name.simplifyWhiteSpace().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ));
01559               obGroup.setAttribute("GROUPS", 1);
01560               obGroup.setAttribute("NUMGROUP", 1);
01561               obGroup.setAttribute("isGroupControl", 1);
01562               obGroup.setAttribute("PTYPE", PageItem::Polygon);
01563               static double rect[] = {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
01564                                                                              1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
01565                                                                              0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0};
01566               FPointArray PoLine;
01567               PoLine.resize(0);
01568               for (int a = 0; a < 29; a += 4)
01569               {
01570                      double xa = GrW * rect[a];
01571                      double ya = GrH * rect[a+1];
01572                      double xb = GrW * rect[a+2];
01573                      double yb = GrH * rect[a+3];
01574                      PoLine.addPoint(0+xa, 0+ya);
01575                      PoLine.addPoint(0+xb, 0+yb);
01576               }
01577               obGroup.setAttribute("XPOS", 0);
01578               obGroup.setAttribute("YPOS",0);
01579               obGroup.setAttribute("WIDTH",GrW);
01580               obGroup.setAttribute("HEIGHT",GrH);
01581               obGroup.setAttribute("NUMPO", PoLine.size());
01582               QString polp = "";
01583               double xf, yf;
01584               QString tmpSt, tmpSt2;
01585               for (uint nxx=0; nxx<PoLine.size(); ++nxx)
01586               {
01587                      PoLine.point(nxx, &xf, &yf);
01588                      polp += tmpSt.setNum(xf) + " " + tmpSt2.setNum(yf) + " ";
01589               }
01590               obGroup.setAttribute("POCOOR", polp);
01591               group.appendChild(obGroup);
01592        }
01593        else
01594               group.setAttribute("COUNT", listItems.count());
01595        QDomNode DOC=elem.firstChild();
01596        while(!DOC.isNull())
01597        {
01598               QDomElement pg=DOC.toElement();
01599               if(pg.tagName()=="KivioShape")
01600               {
01601                      FillCol = "White";
01602                      StrokeCol = "Black";
01603                      fillStyle = 1;
01604                      strokewidth = 1.0;
01605                      Dash = Qt::SolidLine;
01606                      LineEnd = Qt::FlatCap;
01607                      LineJoin = Qt::MiterJoin;
01608                      FPointArray PoLine;
01609                      PoLine.resize(0);
01610                      double x = 0.0;
01611                      double y = 0.0;
01612                      double x1 = 0.0;
01613                      double y1 = 0.0;
01614                      double currx = 0.0;
01615                      double curry = 0.0;
01616                      double startx = 0.0;
01617                      double starty = 0.0;
01618                      QString typ = pg.attribute("type");
01619                      QDomNode point = DOC.firstChild();
01620                      bool first = true;
01621                      int count = 0;
01622                      while(!point.isNull())
01623                      {
01624                             QDomElement pt = point.toElement();
01625                             if(pt.tagName()=="KivioFillStyle")
01626                             {
01627                                    fillStyle = pt.attribute("colorStyle","1").toInt();
01628                                    QString colnam = pt.attribute("color","#000000");
01629                                    fill.setNamedColor("#"+colnam.right(6));
01630                                    if (fillStyle == 0)
01631                                           FillCol = CommonStrings::None;
01632                                    else
01633                                    {
01634                                           if (fill == Qt::white)
01635                                                  FillCol = "White";
01636                                           else if (fill == Qt::black)
01637                                                  FillCol = "Black";
01638                                           else
01639                                                  FillCol = "FromKivio"+fill.name();
01640                                    }
01641                             }
01642                             if(pt.tagName()=="KivioLineStyle")
01643                             {
01644                                    QString colnam = pt.attribute("color","#ffffff");
01645                                    stroke.setNamedColor("#"+colnam.right(6));
01646                                    if (stroke == Qt::white)
01647                                           StrokeCol = "White";
01648                                    else if (stroke == Qt::black)
01649                                           StrokeCol = "Black";
01650                                    else
01651                                           StrokeCol = "FromKivio"+stroke.name();
01652                                    strokewidth = pt.attribute("width", "1").toDouble();
01653                                    LineJoin = Qt::PenJoinStyle(pt.attribute("joinStyle", "0").toInt());
01654                                    Dash = Qt::PenStyle(pt.attribute("pattern").toInt());
01655                                    LineEnd = Qt::PenCapStyle(pt.attribute("capStyle", "0").toInt());
01656                             }
01657                             if(pt.tagName()=="KivioPoint")
01658                             {
01659                                    x = pt.attribute("x").toDouble();
01660                                    y = pt.attribute("y").toDouble();
01661                                    if (first)
01662                                    {
01663                                           currx = x;
01664                                           curry = y;
01665                                           startx = x;
01666                                           starty = y;
01667                                           first = false;
01668                                           if (pt.attribute("type") == "bezier")
01669                                                  count = 0;
01670                                           else
01671                                                  count = -1;
01672                                    }
01673                                    else
01674                                    {
01675                                           if (pt.attribute("type") != "bezier")
01676                                           {
01677                                                  PoLine.addPoint(currx, curry);
01678                                                  PoLine.addPoint(currx, curry);
01679                                                  PoLine.addPoint(x, y);
01680                                                  PoLine.addPoint(x, y);
01681                                                  currx = x;
01682                                                  curry = y;
01683                                           }
01684                                           else
01685                                           {
01686                                                  if (count == -1)
01687                                                  {
01688                                                         if (FPoint(currx, curry) != FPoint(x, y))
01689                                                         {
01690                                                                PoLine.addPoint(currx, curry);
01691                                                                PoLine.addPoint(currx, curry);
01692                                                                PoLine.addPoint(x, y);
01693                                                                PoLine.addPoint(x, y);
01694                                                         }
01695                                                         currx = x;
01696                                                         curry = y;
01697                                                         count++;
01698                                                  }
01699                                                  else if (count == 0)
01700                                                  {
01701                                                         PoLine.addPoint(currx, curry);
01702                                                         PoLine.addPoint(x, y);
01703                                                         count++;
01704                                                  }
01705                                                  else if (count == 1)
01706                                                  {
01707                                                         currx = x;
01708                                                         curry = y;
01709                                                         count++;
01710                                                  }
01711                                                  else if (count == 2)
01712                                                  {
01713                                                         PoLine.addPoint(x, y);
01714                                                         PoLine.addPoint(currx, curry);
01715                                                         currx = x;
01716                                                         curry = y;
01717                                                         count = -1;
01718                                                  }
01719                                           }
01720                                    }
01721                             }
01722                             if(pt.tagName()=="Line")
01723                             {
01724                                    if (!first)
01725                                           PoLine.setMarker();
01726                                    x = pt.attribute("x1").toDouble();
01727                                    y = pt.attribute("y1").toDouble();
01728                                    x1 = pt.attribute("x2").toDouble();
01729                                    y1 = pt.attribute("y2").toDouble();
01730                                    PoLine.addPoint(x, y);
01731                                    PoLine.addPoint(x, y);
01732                                    PoLine.addPoint(x1, y1);
01733                                    PoLine.addPoint(x1, y1);
01734                                    first = false;
01735                             }
01736                             point = point.nextSibling();
01737                      }
01738                      QDomElement ob = data.createElement("ITEM");
01739                      writeDefaults(ob);
01740                      ob.setAttribute("PWIDTH", strokewidth);
01741                      if (typ == "TextBox")
01742                      {
01743                             ob.setAttribute("PCOLOR", CommonStrings::None);
01744                             ob.setAttribute("PCOLOR2", CommonStrings::None);
01745                      }
01746                      else
01747                      {
01748                             ob.setAttribute("PCOLOR", FillCol);
01749                             ob.setAttribute("PCOLOR2", StrokeCol);
01750                      }
01751                      ob.setAttribute("PLINEART", Dash);
01752                      ob.setAttribute("PLINEEND", LineEnd);
01753                      ob.setAttribute("PLINEJOIN", LineJoin);
01754                      ob.setAttribute("ANNAME", pg.attribute("name"));
01755                      if (listItems.count() != 1)
01756                      {
01757                             ob.setAttribute("GROUPS", 1);
01758                             ob.setAttribute("NUMGROUP", 1);
01759                      }
01760                      else
01761                      {
01762                             ob.setAttribute("GROUPS", "");
01763                             ob.setAttribute("NUMGROUP", 0);
01764                      }
01765                      bool valid = false;
01766                      if ((typ == "Polygon") || (typ == "ClosedPath"))
01767                      {
01768                             ob.setAttribute("PTYPE", PageItem::Polygon);
01769                             valid = true;
01770                      }
01771                      else if ((typ == "Bezier") || (typ == "OpenPath") || (typ == "LineArray") || (typ == "Polyline"))
01772                      {
01773                             ob.setAttribute("PTYPE", PageItem::PolyLine);
01774                             valid = true;
01775                      }
01776                      else if ((typ == "Rectangle") || (typ == "TextBox"))
01777                      {
01778                             if (typ == "Rectangle")
01779                                    ob.setAttribute("PTYPE", PageItem::Polygon);
01780                             else
01781                                    ob.setAttribute("PTYPE", PageItem::TextFrame);
01782                             x = pg.attribute("x").toDouble();
01783                             y = pg.attribute("y").toDouble();
01784                             x1 = pg.attribute("w").toDouble();
01785                             y1 = pg.attribute("h").toDouble();
01786                             static double rect[] = {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
01787                                                                       1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
01788                                                                       0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0};
01789                             PoLine.resize(0);
01790                             for (int a = 0; a < 29; a += 4)
01791                             {
01792                                    double xa = x1 * rect[a];
01793                                    double ya = y1 * rect[a+1];
01794                                    double xb = x1 * rect[a+2];
01795                                    double yb = y1 * rect[a+3];
01796                                    PoLine.addPoint(x+xa, y+ya);
01797                                    PoLine.addPoint(x+xb, y+yb);
01798                             }
01799                             valid = true;
01800                      }
01801                      else if (typ == "Ellipse")
01802                      {
01803                             ob.setAttribute("PTYPE", PageItem::Polygon);
01804                             x = pg.attribute("x").toDouble();
01805                             y = pg.attribute("y").toDouble();
01806                             x1 = pg.attribute("w").toDouble();
01807                             y1 = pg.attribute("h").toDouble();
01808                             static double rect[] = {1.0, 0.5, 1.0, 0.77615235,0.5, 1.0, 0.77615235, 1.0,
01809                                                                       0.5, 1.0, 0.22385765, 1.0, 0.0, 0.5, 0.0, 0.77615235,
01810                                                                       0.0, 0.5, 0.0, 0.22385765, 0.5, 0.0, 0.22385765, 0.0,
01811                                                                       0.5, 0.0, 0.77615235, 0.0, 1.0, 0.5, 1.0, 0.22385765};
01812                             PoLine.resize(0);
01813                             for (int a = 0; a < 29; a += 4)
01814                             {
01815                                    double xa = x1 * rect[a];
01816                                    double ya = y1 * rect[a+1];
01817                                    double xb = x1 * rect[a+2];
01818                                    double yb = y1 * rect[a+3];
01819                                    PoLine.addPoint(x+xa, y+ya);
01820                                    PoLine.addPoint(x+xb, y+yb);
01821                             }
01822                             valid = true;
01823                      }
01824                      FPoint tp2(getMinClipF(&PoLine));
01825                      PoLine.translate(-tp2.x(), -tp2.y());
01826                      FPoint wh = getMaxClipF(&PoLine);
01827                      ob.setAttribute("XPOS", tp2.x());
01828                      ob.setAttribute("YPOS",tp2.y());
01829                      ob.setAttribute("WIDTH",wh.x());
01830                      ob.setAttribute("HEIGHT",wh.y());
01831                      ob.setAttribute("NUMPO", PoLine.size());
01832                      QString polp = "";
01833                      double xf, yf;
01834                      QString tmpSt, tmpSt2;
01835                      for (uint nxx=0; nxx<PoLine.size(); ++nxx)
01836                      {
01837                             PoLine.point(nxx, &xf, &yf);
01838                             polp += tmpSt.setNum(xf) + " " + tmpSt2.setNum(yf) + " ";
01839                      }
01840                      ob.setAttribute("POCOOR", polp);
01841                      if (valid)
01842                      {
01843                             group.appendChild(ob);
01844                             groupElemCounter++;
01845                      }
01846               }
01847               DOC = DOC.nextSibling();
01848        }
01849        if (listItems.count() != 1)
01850               obGroup.setAttribute("groupsLastItem", groupElemCounter);
01851        return data.toString();
01852 }