Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

scpreview.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 "scpreview.h"
00008 #include <QDomDocument>
00009 #include <QMap>
00010 #include <QPainter>
00011 #include <QRect>
00012 #include <QImage>
00013 #include <QRegion>
00014 #include <QRegExp>
00015 #include <QFileInfo>
00016 #include <QBitmap>
00017 #include <QDir>
00018 #include <QList>
00019 #include <QPolygon>
00020 #include <QTextStream>
00021 #include <QPixmap>
00022 #include <cmath>
00023 #include <cstdlib>
00024 
00025 #include "cmsettings.h"
00026 #include "missing.h"
00027 #include "sccolor.h"
00028 #include "scribus.h"
00029 #include "scribuscore.h"
00030 #include "splash.h"
00031 #include "util.h"
00032 #include "util_math.h"
00033 #include "prefsmanager.h"
00034 #include "scpainter.h"
00035 #include "commonstrings.h"
00036 #include "sccolorengine.h"
00037 
00038 
00039 using namespace std;
00040 
00041 
00042 ScPreview::ScPreview()
00043 {
00044     prefsManager = PrefsManager::instance();
00045     Farben.clear();
00046     MLineStyles.clear();
00047     Segments.clear();
00048 }
00049 
00050 QPixmap ScPreview::createPreview(QString data)
00051 {
00052     int a;
00053     struct CopyPasteBuffer OB;
00054     ScText *hg;
00055     ScText *hl;
00056     QList<ScText*> Ptexti;
00057     ScColor lf = ScColor();
00058     QFont fo;
00059     QMap<QString,QString> DoFonts;
00060     QMap<int,int> arrowID;
00061     QString tmpf, tmpx, tmp2, tmp3;
00062     int x, y, zae;
00063     double xf, yf, asce, chs;
00064     FPoint gv;
00065     int currItem, fillBlendmode, strokeBlendmode;
00066     QPolygon cl;
00067     QColor tmpfa;
00068     QString chstr;
00069     double CurY, EndX, CurX, wide, rota, wid;
00070     QList<ArrowDesc> arrowStyles;
00071     QStack<int> groupStack;
00072     arrowStyles = prefsManager->appPrefs.arrowStyles;
00073     QDomDocument docu("scridoc");
00074     docu.setContent(data);
00075     QDomElement elem=docu.documentElement();
00076     if ((elem.tagName() != "SCRIBUSELEM") && (elem.tagName() != "SCRIBUSELEMUTF8"))
00077     {
00078         QPixmap tmp = QPixmap(0, 0);
00079         return tmp;
00080     }
00081     double GrX = elem.attribute("XP").toDouble();
00082     double GrY = elem.attribute("YP").toDouble();
00083     double GrW = elem.attribute("W").toDouble();
00084     double GrH = elem.attribute("H").toDouble();
00085     double pmmax = 60 / qMax(GrW+50, GrH+50);
00086     QImage tmp = QImage(static_cast<int>(GrW)+50, static_cast<int>(GrH)+50, QImage::Format_ARGB32);
00087     tmp.fill( qRgba(255, 255, 255, 0) );
00088     ScPainter *pS = new ScPainter(&tmp, tmp.width(), tmp.height(), 1.0, 0);
00089     pS->beginLayer(1.0, 0);
00090     pS->translate(25,25);
00091     QDomNode DOC=elem.firstChild();
00092     DoFonts.clear();
00093     while(!DOC.isNull())
00094     {
00095         QDomElement pg=DOC.toElement();
00096         if(pg.tagName()=="Arrows")
00097         {
00098             struct ArrowDesc arrow;
00099             double xa, ya;
00100             arrow.name = pg.attribute("Name");
00101             QString tmp = pg.attribute("Points");
00102             QTextStream fp(&tmp, QIODevice::ReadOnly);
00103             for (uint cx = 0; cx < pg.attribute("NumPoints").toUInt(); ++cx)
00104             {
00105                 fp >> xa;
00106                 fp >> ya;
00107                 arrow.points.addPoint(xa, ya);
00108             }
00109             arrowStyles.append(arrow);
00110             arrowID.insert(pg.attribute("Index").toInt(), arrowStyles.count());
00111         }
00112         if(pg.tagName()=="FONT")
00113         {
00114             tmpf = GetAttr(&pg, "NAME");
00115             if ((!prefsManager->appPrefs.AvailFonts.contains(tmpf)) || (!prefsManager->appPrefs.AvailFonts[tmpf].usable()))
00116             {
00117                 if ((!prefsManager->appPrefs.GFontSub.contains(tmpf)) || (!prefsManager->appPrefs.AvailFonts[prefsManager->appPrefs.GFontSub[tmpf]].usable()))
00118                 {
00119                     ScCore->showSplash(false);
00120                     MissingFont *dia = new MissingFont(0, tmpf, 0);
00121                     dia->exec();
00122                     tmpf = dia->getReplacementFont();
00123                     delete dia;
00124                     ScCore->showSplash(true);
00125                     prefsManager->appPrefs.GFontSub[pg.attribute("NAME")] = tmpf;
00126                 }
00127                 else
00128                     tmpf = prefsManager->appPrefs.GFontSub[tmpf];
00129             }
00130             if (!DoFonts.contains(tmpf))
00131             {
00132 //              FT_Face face;
00133 //              error = FT_New_Face( library, prefsManager->appPrefs.AvailFonts[tmpf].fontFilePath(), prefsManager->appPrefs.AvailFonts[tmpf].faceIndex(), &face );
00134                 if ( prefsManager->appPrefs.AvailFonts[tmpf].usable() )
00135                     tmpf = prefsManager->appPrefs.toolSettings.defFont;
00136 /*              if (prefsManager->appPrefs.AvailFonts[tmpf]->ReadMetrics()) {
00137 //already done in ScFonts::addScalaableFont():
00138 //                  prefsManager->appPrefs.AvailFonts[tmpf]->CharWidth[13] = 0;
00139                 }
00140                 else
00141                 {
00142                     tmpf = prefsManager->appPrefs.toolSettings.defFont;
00143 //                  prefsManager->appPrefs.AvailFonts[tmpf]->ReadMetrics();
00144 //already done in ScFonts::addScalaableFont():
00145 //                  prefsManager->appPrefs.AvailFonts[tmpf]->CharWidth[13] = 0;
00146                 }
00147 */
00148             }
00149 //          fo = prefsManager->appPrefs.AvailFonts[tmpf]->Font;
00150 //          fo.setPointSize(12);
00151             DoFonts[GetAttr(&pg, "NAME")] = tmpf;
00152 //          DoFonts2[GetAttr(&pg, "NAME")] = fo;
00153         }
00154         if(pg.tagName()=="COLOR")
00155         {
00156             if (pg.hasAttribute("CMYK"))
00157                 lf.setNamedColor(GetAttr(&pg, "CMYK"));
00158             else
00159                 lf.fromQColor(QColor(GetAttr(&pg, "RGB")));
00160             Farben[GetAttr(&pg, "NAME")] = lf;
00161         }
00162         if(pg.tagName()=="MultiLine")
00163         {
00164             multiLine ml;
00165             QDomNode MuLn = DOC.firstChild();
00166             while(!MuLn.isNull())
00167             {
00168                 QDomElement MuL = MuLn.toElement();
00169                 struct SingleLine sl;
00170                 sl.Color = MuL.attribute("Color");
00171                 sl.Dash = MuL.attribute("Dash").toInt();
00172                 sl.LineEnd = MuL.attribute("LineEnd").toInt();
00173                 sl.LineJoin = MuL.attribute("LineJoin").toInt();
00174                 sl.Shade = MuL.attribute("Shade").toInt();
00175                 sl.Width = MuL.attribute("Width").toDouble();
00176                 ml.push_back(sl);
00177                 MuLn = MuLn.nextSibling();
00178             }
00179             if (!MLineStyles.contains(pg.attribute("Name")))
00180                 MLineStyles.insert(pg.attribute("Name"), ml);
00181         }
00182         DOC=DOC.nextSibling();
00183     }
00184     DOC=elem.firstChild();
00185     currItem = -1;
00186     while(!DOC.isNull())
00187     {
00188         QDomElement pg=DOC.toElement();
00189         if(pg.tagName()=="ITEM")
00190         {
00191             currItem++;
00192             QString CurDirP = QDir::currentPath();
00193             QDir::setCurrent(QDir::homePath());
00194             Segments.clear();
00195             // TODO: Nicer conversion
00196             OB.PType = static_cast<PageItem::ItemType>(pg.attribute("PTYPE").toInt());
00197             OB.Xpos = pg.attribute("XPOS").toDouble() - GrX;
00198             OB.Ypos = pg.attribute("YPOS").toDouble() - GrY;
00199             OB.Width = pg.attribute("WIDTH").toDouble();
00200             OB.Height = pg.attribute("HEIGHT").toDouble();
00201             OB.RadRect = pg.attribute("RADRECT", "0").toDouble();
00202             OB.ClipEdited = pg.attribute("CLIPEDIT", "0").toInt();
00203             OB.FrameType = pg.attribute("FRTYPE", "0").toInt();
00204             OB.Pwidth = pg.attribute("PWIDTH").toDouble();
00205             OB.Pcolor = pg.attribute("PCOLOR");
00206             OB.Pcolor2 = pg.attribute("PCOLOR2");
00207             OB.NamedLStyle = pg.attribute("NAMEDLST", "");
00208             if (!MLineStyles.contains(OB.NamedLStyle))
00209                 OB.NamedLStyle = "";
00210             OB.Shade = pg.attribute("SHADE").toInt();
00211             OB.Shade2 = pg.attribute("SHADE2").toInt();
00212             OB.TxtFill = pg.attribute("TXTFILL", "Black");
00213             OB.TxtStroke = pg.attribute("TXTSTROKE", CommonStrings::None);
00214             OB.ShTxtFill = pg.attribute("TXTFILLSH", "100").toInt();
00215             OB.ShTxtStroke = pg.attribute("TXTSTRSH", "100").toInt();
00216             OB.TxtScale = qRound(pg.attribute("TXTSCALE", "100").toDouble() * 10);
00217             OB.TxtScaleV = qRound(pg.attribute("TXTSCALEV", "100").toDouble() * 10);
00218             OB.TxTBase = qRound(pg.attribute("TXTBASE", "0").toDouble() * 10);
00219             OB.TxTStyle = pg.attribute("TXTSTYLE", "0").toInt();
00220             OB.GrType = pg.attribute("GRTYP", "0").toInt();
00221             OB.fill_gradient.clearStops();
00222             if (OB.GrType != 0)
00223             {
00224                 OB.GrStartX = pg.attribute("GRSTARTX", "0.0").toDouble();
00225                 OB.GrStartY = pg.attribute("GRSTARTY", "0.0").toDouble();
00226                 OB.GrEndX = pg.attribute("GRENDX", "0.0").toDouble();
00227                 OB.GrEndY = pg.attribute("GRENDY", "0.0").toDouble();
00228                 OB.GrColor = pg.attribute("GRCOLOR","");
00229                 if (!OB.GrColor.isEmpty())
00230                 {
00231                     OB.GrColor2 = pg.attribute("GRCOLOR2","");
00232                     OB.GrShade = pg.attribute("GRSHADE", "100").toInt();
00233                     OB.GrShade2 = pg.attribute("GRSHADE2", "100").toInt();
00234                 }
00235             }
00236             OB.Rot = pg.attribute("ROT").toDouble();
00237             OB.PLineArt = Qt::PenStyle(pg.attribute("PLINEART").toInt());
00238             OB.PLineEnd = Qt::PenCapStyle(pg.attribute("PLINEEND", "0").toInt());
00239             OB.PLineJoin = Qt::PenJoinStyle(pg.attribute("PLINEJOIN", "0").toInt());
00240             OB.LineSp = pg.attribute("LINESP").toDouble();
00241             OB.ExtraV = static_cast<int>(pg.attribute("EXTRAV", "0").toDouble()); // temporary compiler silencing
00242             OB.LocalScX = pg.attribute("LOCALSCX").toDouble();
00243             OB.LocalScY = pg.attribute("LOCALSCY").toDouble();
00244             OB.LocalX = pg.attribute("LOCALX").toDouble();
00245             OB.LocalY = pg.attribute("LOCALY").toDouble();
00246             OB.PicArt = pg.attribute("PICART").toInt();
00247             OB.flippedH = pg.attribute("FLIPPEDH").toInt();
00248             OB.flippedV = pg.attribute("FLIPPEDV").toInt();
00249             OB.ScaleType = pg.attribute("SCALETYPE", "1").toInt();
00250             OB.AspectRatio = pg.attribute("RATIO", "0").toInt();
00251             OB.isPrintable = pg.attribute("PRINTABLE").toInt();
00252             OB.isBookmark = false;
00253             OB.m_isAnnotation = pg.attribute("ANNOTATION", "0").toInt();
00254             if (pg.attribute("TRANSPARENT", "0").toInt() == 1)
00255                 OB.Pcolor = CommonStrings::None;
00256             //OB.Textflow = pg.attribute("TEXTFLOW").toInt();
00257             //OB.Textflow2 = pg.attribute("TEXTFLOW2", "0").toInt();
00258             if ( pg.hasAttribute("TEXTFLOWMODE") )
00259                 OB.TextflowMode = (PageItem::TextFlowMode) pg.attribute("TEXTFLOWMODE", "0").toInt();
00260             else if ( pg.attribute("TEXTFLOW").toInt() )
00261             {
00262                 if (pg.attribute("TEXTFLOW2", "0").toInt())
00263                     OB.TextflowMode = PageItem::TextFlowUsesBoundingBox;
00264                 else if (pg.attribute("TEXTFLOW3", "0").toInt())
00265                     OB.TextflowMode = PageItem::TextFlowUsesContourLine;
00266                 else
00267                     OB.TextflowMode = PageItem::TextFlowUsesFrameShape; 
00268             }
00269             else
00270                 OB.TextflowMode = PageItem::TextFlowDisabled;
00271             OB.Extra = pg.attribute("EXTRA").toDouble();
00272             OB.TExtra = pg.attribute("TEXTRA", "1").toDouble();
00273             OB.BExtra = pg.attribute("BEXTRA", "1").toDouble();
00274             OB.RExtra = pg.attribute("REXTRA", "1").toDouble();
00275             OB.PoShow = pg.attribute("PTLSHOW", "0").toInt();
00276             OB.BaseOffs = pg.attribute("BASEOF", "0").toDouble();
00277             OB.textAlignment = pg.attribute("ALIGN", "0").toInt();
00278             OB.IFont = DoFonts[pg.attribute("IFONT")];
00279             OB.ISize = qRound(pg.attribute("ISIZE", "12").toDouble() * 10.0);
00280             if (OB.PType == PageItem::LatexFrame) {
00281                 OB.Pfile = pg.attribute("LATEXTEMPFILE", ""); 
00282                 //Hack to create a preview for latex frames
00283             } else {
00284                 OB.Pfile = pg.attribute("PFILE");
00285             }
00286             OB.Pfile2 = pg.attribute("PFILE2","");
00287             OB.Pfile3 = pg.attribute("PFILE3","");
00288             OB.IProfile = pg.attribute("PRFILE","");
00289             OB.EmProfile = pg.attribute("EPROF","");
00290             OB.IRender = pg.attribute("IRENDER", "1").toInt();
00291             OB.UseEmbedded = pg.attribute("EMBEDDED", "1").toInt();
00292             OB.Locked = static_cast<bool>(pg.attribute("LOCK", "0").toInt());
00293             OB.Reverse = static_cast<bool>(pg.attribute("REVERS", "0").toInt());
00294             OB.Transparency = pg.attribute("TransValue", "0.0").toDouble();
00295             if (pg.hasAttribute("TransValueS"))
00296                 OB.TranspStroke = pg.attribute("TransValueS", "0.0").toDouble();
00297             else
00298                 OB.TranspStroke = OB.Transparency;
00299             fillBlendmode = pg.attribute("TransBlend", "0").toInt();
00300             strokeBlendmode = pg.attribute("TransBlendS", "0").toInt();
00301             if (pg.hasAttribute("NUMCLIP"))
00302             {
00303                 OB.Clip.resize(pg.attribute("NUMCLIP").toUInt());
00304                 tmpx = pg.attribute("CLIPCOOR");
00305                 QTextStream f(&tmpx, QIODevice::ReadOnly);
00306                 for (uint c=0; c<pg.attribute("NUMCLIP").toUInt(); ++c)
00307                 {
00308                     f >> x;
00309                     f >> y;
00310                     OB.Clip.setPoint(c, x, y);
00311                 }
00312             }
00313             else
00314                 OB.Clip.resize(0);
00315             if (pg.hasAttribute("NUMPO"))
00316             {
00317                 OB.PoLine.resize(pg.attribute("NUMPO").toUInt());
00318                 tmpx = pg.attribute("POCOOR");
00319                 QTextStream fp(&tmpx, QIODevice::ReadOnly);
00320                 for (uint cx=0; cx<pg.attribute("NUMPO").toUInt(); ++cx)
00321                 {
00322                     fp >> xf;
00323                     fp >> yf;
00324                     OB.PoLine.setPoint(cx, xf, yf);
00325                 }
00326             }
00327             else
00328                 OB.PoLine.resize(0);
00329             OB.Groups.clear();
00330             if (OB.Clip.size() == 0)
00331                 OB.Clip = FlattenPath(OB.PoLine, Segments);
00332             tmpx = "";
00333             QDomNode IT=DOC.firstChild();
00334             while(!IT.isNull())
00335             {
00336                 QDomElement it=IT.toElement();
00337                 if (it.tagName()=="CSTOP")
00338                 {
00339                     QString name = it.attribute("NAME");
00340                     double ramp = it.attribute("RAMP", "0.0").toDouble();
00341                     int shade = it.attribute("SHADE", "100").toInt();
00342                     SetQColor(&tmpfa, name, shade);
00343                     OB.fill_gradient.addStop(tmpfa, ramp, 0.5, 1.0, name, shade);
00344                 }
00345                 if (it.tagName()=="ITEXT")
00346                 {
00347                     tmp2 = it.attribute("CH");
00348                     tmp2.replace(QRegExp("\r"), QChar(5));
00349                     tmp2.replace(QRegExp("\n"), QChar(5));
00350                     tmp3 = "\t" + DoFonts[it.attribute("CFONT")] + "\t";
00351                     tmp3 += it.attribute("CSIZE") + "\t";
00352                     tmp3 += it.attribute("CCOLOR") + "\t";
00353 //                  tmp3 += it.attribute("CEXTRA") + "\t";
00354                     tmp3 += "0\t";
00355                     tmp3 += it.attribute("CSHADE") + "\t";
00356                     tmp3 += it.attribute("CSTYLE") + "\t";
00357                     tmp3 += "0\t";
00358                     tmp3 += it.attribute("CSTROKE",CommonStrings::None) + "\t";
00359                     tmp3 += it.attribute("CSHADE2","100") + "\t";
00360                     tmp3 += it.attribute("CSCALE","100") + "\n";
00361                     for (int cxx=0; cxx<tmp2.length(); cxx++)
00362                     {
00363                         tmpx += tmp2.at(cxx)+tmp3;
00364                     }
00365                 }
00366                 IT=IT.nextSibling();
00367             }
00368             OB.itemText = tmpx;
00369             if (!OB.itemText.isEmpty())
00370             {
00371                 QTextStream t(&OB.itemText, QIODevice::ReadOnly);
00372                 QString cc;
00373 #ifndef NLS_PROTO
00374                 while (!t.atEnd())
00375                 {
00376                     cc = t.readLine();
00377                     if (cc.isEmpty())
00378                         continue;
00379                     QStringList wt;
00380                     QStringList::Iterator it;
00381                     wt = cc.split("\t", QString::SkipEmptyParts);
00382                     it = wt.begin();
00383                     hg = new ScText;
00384                     hg->ch = it->at(0);
00385                     if (hg->ch == QChar(5))
00386                         hg->ch = QChar(13);
00387                     it++;
00388                     hg->setFont(prefsManager->appPrefs.AvailFonts[*it]);
00389                     it++;
00390                     hg->setFontSize(qRound((*it).toDouble() * 10.0));
00391                     it++;
00392                     hg->setFillColor(*it);
00393                     it++;
00394                     hg->setTracking((*it).toInt());
00395                     it++;
00396                     hg->setFillShade((*it).toInt());
00397                     it++;
00398                     // Qt4 if (it == NULL)
00399                     if (it == wt.end())
00400                         hg->setFeatures(QStringList(CharStyle::INHERIT));
00401                     else
00402                         hg->setFeatures(static_cast<StyleFlag>((*it).toInt()).featureList());
00403                     it++;
00404 //                  if (it == NULL)
00405 //                      hg->cab = 0;
00406 //                  else
00407 //                      hg->cab = (*it).toInt();
00408                     it++;
00409                     if (it == wt.end())
00410                         hg->setStrokeColor(CommonStrings::None);
00411                     else
00412                         hg->setStrokeColor(*it);
00413                     it++;
00414                     if (it == wt.end())
00415                         hg->setStrokeShade(100);
00416                     else
00417                         hg->setStrokeShade((*it).toInt());
00418                     it++;
00419                     if (it == wt.end())
00420                         hg->setScaleH(100);
00421                     else
00422                         hg->setScaleH((*it).toInt());
00423 
00424                     Ptexti.append(hg);
00425                 }
00426 #endif
00427             }
00428             tmpx = GetAttr(&pg, "TEXTCOOR","0 0");
00429             QTextStream ft(&tmpx, QIODevice::ReadOnly);
00430             for (uint ct=0; ct<GetAttr(&pg, "NUMTEXT","0").toUInt(); ct++)
00431             {
00432 #ifndef NLS_PROTO
00433                 ft >> Ptexti.at(ct)->glyph.xoffset;
00434                 ft >> Ptexti.at(ct)->glyph.yoffset;
00435 #endif
00436             }
00437             tmpx = "";
00438             if ((OB.PType == 5) && (OB.Height != 0))
00439             {
00440                 OB.Rot += atan2(OB.Height,OB.Width)*(180.0/M_PI);
00441                 OB.Width = sqrt(pow(OB.Width,2)+pow(OB.Height,2));
00442                 OB.Height = 0;
00443                 OB.Clip.setPoints(4, -1,-1, static_cast<int>(OB.Width+1),-1, static_cast<int>(OB.Width+1), static_cast<int>(OB.Height+1), -1, static_cast<int>(OB.Height+1));
00444             }
00445             OB.LayerNr = -1;
00446             OB.startArrowIndex =  arrowID[pg.attribute("startArrowIndex", "0").toInt()];
00447             OB.endArrowIndex =  arrowID[pg.attribute("endArrowIndex", "0").toInt()];
00448             if(static_cast<bool>(pg.attribute("isGroupControl", "0").toInt()))
00449             {
00450                 pS->save();
00451                 FPointArray cl = OB.PoLine.copy();
00452                 QMatrix mm;
00453                 mm.translate(OB.Xpos, OB.Ypos);
00454                 mm.rotate(static_cast<double>(OB.Rot));
00455                 cl.map( mm );
00456                 pS->beginLayer(1.0 - OB.Transparency, pg.attribute("TransBlend", "0").toInt(), &cl);
00457                 groupStack.push(pg.attribute("groupsLastItem", "0").toInt() + currItem);
00458                 DOC=DOC.nextSibling();
00459                 continue;
00460             }
00461             pS->save();
00462             if (fillBlendmode != 0)
00463                 pS->beginLayer(1.0 - OB.Transparency, fillBlendmode);
00464             else
00465                 pS->setBrushOpacity(1.0 - OB.Transparency);
00466             pS->translate(OB.Xpos, OB.Ypos);
00467             pS->rotate(static_cast<double>(OB.Rot));
00468             if (OB.Pcolor != CommonStrings::None)
00469             {
00470                 SetQColor(&tmpfa, OB.Pcolor, OB.Shade);
00471                 pS->setBrush(tmpfa);
00472                 pS->setFillMode(1);
00473             }
00474             else
00475                 pS->setFillMode(0);
00476             if (OB.GrType != 0)
00477             {
00478                 pS->setFillMode(2);
00479                 pS->fill_gradient.clearStops();
00480                 if ((!OB.GrColor.isEmpty()) && (!OB.GrColor2.isEmpty()))
00481                 {
00482                     if (OB.GrType == 5)
00483                     {
00484                         if ((OB.GrColor != CommonStrings::None) && (!OB.GrColor.isEmpty()))
00485                             SetQColor(&tmpfa, OB.GrColor, OB.GrShade);
00486                         pS->fill_gradient.addStop(tmpfa, 0.0, 0.5, 1.0);
00487                         if ((OB.GrColor2 != CommonStrings::None) && (!OB.GrColor2.isEmpty()))
00488                             SetQColor(&tmpfa, OB.GrColor2, OB.GrShade2);
00489                         pS->fill_gradient.addStop(tmpfa, 1.0, 0.5, 1.0);
00490                     }
00491                     else
00492                     {
00493                         if ((OB.GrColor2 != CommonStrings::None) && (!OB.GrColor2.isEmpty()))
00494                             SetQColor(&tmpfa, OB.GrColor2, OB.GrShade2);
00495                         pS->fill_gradient.addStop(tmpfa, 0.0, 0.5, 1.0);
00496                         if ((OB.GrColor != CommonStrings::None) && (!OB.GrColor.isEmpty()))
00497                             SetQColor(&tmpfa, OB.GrColor, OB.GrShade);
00498                         pS->fill_gradient.addStop(tmpfa, 1.0, 0.5, 1.0);
00499                     }
00500                 }
00501                 else
00502                     pS->fill_gradient = OB.fill_gradient;
00503                 QMatrix grm;
00504                 grm.rotate(OB.Rot);
00505                 FPointArray gra;
00506                 switch (OB.GrType)
00507                 {
00508                 case 1:
00509                     gra.setPoints(2, 0, 0, OB.Width, 0);
00510                     gra.map(grm);
00511                     pS->setGradient(VGradient::linear, gra.point(0), gra.point(1));
00512                     break;
00513                 case 2:
00514                     gra.setPoints(2, 0, 0, OB.Height, 0);
00515                     grm.rotate(90);
00516                     gra.map(grm);
00517                     pS->setGradient(VGradient::linear, gra.point(0), gra.point(1));
00518                     break;
00519                 case 3:
00520                     gra.setPoints(2, 0, 0, OB.Width, OB.Height);
00521                     gra.map(grm);
00522                     pS->setGradient(VGradient::linear, gra.point(0), gra.point(1));
00523                     break;
00524                 case 4:
00525                     gra.setPoints(2, 0, OB.Height, OB.Width, 0);
00526                     gra.map(grm);
00527                     pS->setGradient(VGradient::linear, gra.point(0), gra.point(1));
00528                     break;
00529                 case 5:
00530                     if (OB.Width > OB.Height)
00531                         gv = FPoint(OB.Width, OB.Height / 2.0);
00532                     else
00533                         gv = FPoint(OB.Width / 2.0, OB.Height);
00534                     pS->setGradient(VGradient::radial, FPoint(OB.Width / 2.0,OB.Height / 2.0), gv, FPoint(OB.Width / 2.0,OB.Height / 2.0));
00535                     break;
00536                 case 6:
00537                     gra.setPoints(2, OB.GrStartX, OB.GrStartY, OB.GrEndX, OB.GrEndY);
00538                     gra.map(grm);
00539                     pS->setGradient(VGradient::linear, gra.point(0), gra.point(1));
00540                     break;
00541                 }
00542             }
00543             if (OB.Pcolor2 != CommonStrings::None)
00544             {
00545                 SetQColor(&tmpfa, OB.Pcolor2, OB.Shade2);
00546                 if ((OB.Pwidth == 0) && (OB.PType != 5))
00547                     pS->setLineWidth(0);
00548                 else
00549                     pS->setPen(tmpfa, OB.Pwidth, Qt::PenStyle(OB.PLineArt), Qt::PenCapStyle(OB.PLineEnd), Qt::PenJoinStyle(OB.PLineJoin));
00550             }
00551             else
00552                 pS->setLineWidth(0);
00553             bool doStroke;
00554             int mode;
00555             doStroke = true;
00556             switch (OB.PType)
00557             {
00558             case PageItem::ImageFrame:
00559             case PageItem::LatexFrame:
00560                 if ((OB.Pcolor != CommonStrings::None) || (OB.GrType != 0))
00561                 {
00562                     pS->setupPolygon(&OB.PoLine);
00563                     pS->drawPolygon();
00564                 }
00565                 if (!OB.Pfile.isEmpty())
00566                 {
00567                     QFileInfo fi = QFileInfo(OB.Pfile);
00568                     if (fi.exists())
00569                     {
00570                         pS->setupPolygon(&OB.PoLine);
00571                         pS->setClipPath();
00572                         pS->save();
00573                         if (OB.flippedH)
00574                         {
00575                             pS->translate(OB.Width, 0);
00576                             pS->scale(-1, 1);
00577                         }
00578                         if (OB.flippedV)
00579                         {
00580                             pS->translate(0, OB.Height);
00581                             pS->scale(1, -1);
00582                         }
00583                         ScImage pixm;
00584                         CMSettings cms(0, "", 0);
00585                         pixm.LoadPicture(OB.Pfile, cms, false, false, ScImage::RGBData, 72);
00586                         pS->scale(OB.LocalScX, OB.LocalScY);
00587                         pS->translate(static_cast<int>(OB.LocalX), static_cast<int>(OB.LocalY));
00588                         QImage img(pixm.qImage());
00589                         pS->drawImage(&img);
00590                         pS->restore();
00591                     }
00592                 }
00593                 break;
00594             case PageItem::TextFrame:
00595 #ifndef NLS_PROTO
00596                 if (Ptexti.count() != 0)
00597                 {
00598                     pS->save();
00599                     if (OB.Pcolor != CommonStrings::None)
00600                     {
00601                         pS->setupPolygon(&OB.PoLine);
00602                         pS->drawPolygon();
00603                     }
00604                     if (OB.flippedH)
00605                     {
00606                         pS->translate(OB.Width, 0);
00607                         pS->scale(-1, 1);
00608                     }
00609                     if (OB.flippedV)
00610                     {
00611                         pS->translate(0, OB.Height);
00612                         pS->scale(1, -1);
00613                     }
00614                     if ((OB.Width < 4) || (OB.Height < 4))
00615                         break;
00616                     for (int a = 0; a < Ptexti.count(); a++)
00617                     {
00618                         hl = Ptexti.at(a);
00619                         if (hl->ch == QChar(13))
00620                             continue;
00621                         chstr = hl->ch;
00622                         chs = hl->fontSize();
00623                         if (chs < 10)
00624                             continue;
00625                         if (hl->effects() != ScStyle_Default)
00626                         {
00627                             if (hl->effects() & 1)
00628                                 chs = static_cast<int>(hl->fontSize() * prefsManager->appPrefs.typographicSettings.scalingSuperScript / 100);
00629                             if (hl->effects() & 2)
00630                                 chs = static_cast<int>(hl->fontSize() * prefsManager->appPrefs.typographicSettings.scalingSubScript / 100);
00631                             if (hl->effects() & 64)
00632                             {
00633                                 if (chstr.toUpper() != chstr)
00634                                 {
00635                                     chs = static_cast<int>(hl->fontSize() * prefsManager->appPrefs.typographicSettings.valueSmallCaps / 100);
00636                                     chstr = chstr.toUpper();
00637                                 }
00638                             }
00639                         }
00640                         mode = 0;
00641                         if (hl->fillColor() != CommonStrings::None)
00642                         {
00643                             SetQColor(&tmpfa, hl->fillColor(), hl->fillShade());
00644                             pS->setBrush(tmpfa);
00645                             mode = 2;
00646                         }
00647                         if (hl->strokeColor() != CommonStrings::None)
00648                         {
00649                             SetQColor(&tmpfa, hl->strokeColor(), hl->strokeShade());
00650                             pS->setPen(tmpfa, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
00651                             mode += 1;
00652                         }
00653                         DrawZeichenS(pS, hl->glyph.xoffset, hl->glyph.yoffset, chstr, hl->font().scName(), OB.Reverse, hl->effects(), mode, chs);
00654                     }
00655                     pS->restore();
00656                 }
00657                 break;
00658 #endif
00659             case PageItem::Line:
00660                 if (OB.NamedLStyle.isEmpty())
00661                     pS->drawLine(FPoint(0, 0), FPoint(OB.Width, 0));
00662                 else
00663                 {
00664                     multiLine ml = MLineStyles[OB.NamedLStyle];
00665                     for (int it = ml.size()-1; it > -1; it--)
00666                     {
00667                         SetQColor(&tmpfa, ml[it].Color, ml[it].Shade);
00668                         pS->setPen(tmpfa,
00669                                    qMax(static_cast<int>(ml[it].Width), 1),
00670                                    static_cast<Qt::PenStyle>(ml[it].Dash),
00671                                    static_cast<Qt::PenCapStyle>(ml[it].LineEnd),
00672                                    static_cast<Qt::PenJoinStyle>(ml[it].LineJoin));
00673                         pS->drawLine(FPoint(0, 0), FPoint(OB.Width, 0));
00674                     }
00675                 }
00676                 if (OB.startArrowIndex != 0)
00677                 {
00678                     QMatrix arrowTrans;
00679                     FPointArray arrow = arrowStyles.at(OB.startArrowIndex-1).points.copy();
00680                     arrowTrans.translate(0, 0);
00681                     arrowTrans.scale(OB.Pwidth, OB.Pwidth);
00682                     arrowTrans.scale(-1,1);
00683                     arrow.map(arrowTrans);
00684                     pS->setBrush(pS->pen());
00685                     pS->setLineWidth(0);
00686                     pS->setFillMode(ScPainter::Solid);
00687                     pS->setupPolygon(&arrow);
00688                     pS->drawPolygon();
00689                 }
00690                 if (OB.endArrowIndex != 0)
00691                 {
00692                     QMatrix arrowTrans;
00693                     FPointArray arrow = arrowStyles.at(OB.endArrowIndex-1).points.copy();
00694                     arrowTrans.translate(OB.Width, 0);
00695                     arrowTrans.scale(OB.Pwidth, OB.Pwidth);
00696                     arrow.map(arrowTrans);
00697                     pS->setBrush(pS->pen());
00698                     pS->setLineWidth(0);
00699                     pS->setFillMode(ScPainter::Solid);
00700                     pS->setupPolygon(&arrow);
00701                     pS->drawPolygon();
00702                 }
00703                 doStroke = false;
00704                 break;
00705             /* OBSOLETE Craig R 2005-02-06
00706             case 1:
00707             case 3:
00708             */
00709             case PageItem::ItemType1:
00710             case PageItem::ItemType3:
00711             case PageItem::Polygon:
00712                 pS->setupPolygon(&OB.PoLine);
00713                 pS->drawPolygon();
00714                 break;
00715             case PageItem::PolyLine:
00716                 if ((OB.Pcolor != CommonStrings::None) || (OB.GrType != 0))
00717                 {
00718                     FPointArray cli;
00719                     FPoint Start;
00720                     bool firstp = true;
00721                     for (uint n = 0; n < OB.PoLine.size()-3; n += 4)
00722                     {
00723                         if (firstp)
00724                         {
00725                             Start = OB.PoLine.point(n);
00726                             firstp = false;
00727                         }
00728                         if (OB.PoLine.point(n).x() > 900000)
00729                         {
00730                             cli.addPoint(OB.PoLine.point(n-2));
00731                             cli.addPoint(OB.PoLine.point(n-2));
00732                             cli.addPoint(Start);
00733                             cli.addPoint(Start);
00734                             cli.setMarker();
00735                             firstp = true;
00736                             continue;
00737                         }
00738                         cli.addPoint(OB.PoLine.point(n));
00739                         cli.addPoint(OB.PoLine.point(n+1));
00740                         cli.addPoint(OB.PoLine.point(n+2));
00741                         cli.addPoint(OB.PoLine.point(n+3));
00742                     }
00743                     if (cli.size() > 2)
00744                     {
00745                         FPoint l1 = cli.point(cli.size()-2);
00746                         cli.addPoint(l1);
00747                         cli.addPoint(l1);
00748                         cli.addPoint(Start);
00749                         cli.addPoint(Start);
00750                     }
00751                     pS->setupPolygon(&cli);
00752                     pS->fillPath();
00753                 }
00754                 pS->setupPolygon(&OB.PoLine, false);
00755                 if (OB.NamedLStyle.isEmpty())
00756                     pS->strokePath();
00757                 else
00758                 {
00759                     multiLine ml = MLineStyles[OB.NamedLStyle];
00760                     for (int it = ml.size()-1; it > -1; it--)
00761                     {
00762                         SetQColor(&tmpfa, ml[it].Color, ml[it].Shade);
00763                         pS->setPen(tmpfa, ml[it].Width,
00764                                    static_cast<Qt::PenStyle>(ml[it].Dash),
00765                                    static_cast<Qt::PenCapStyle>(ml[it].LineEnd),
00766                                    static_cast<Qt::PenJoinStyle>(ml[it].LineJoin));
00767                         pS->drawPolyLine();
00768                     }
00769                 }
00770                 if (OB.startArrowIndex != 0)
00771                 {
00772                     FPoint Start = OB.PoLine.point(0);
00773                     for (uint xx = 1; xx < OB.PoLine.size(); xx += 2)
00774                     {
00775                         FPoint Vector = OB.PoLine.point(xx);
00776                         if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
00777                         {
00778                             double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
00779                             QMatrix arrowTrans;
00780                             FPointArray arrow = arrowStyles.at(OB.startArrowIndex-1).points.copy();
00781                             arrowTrans.translate(Start.x(), Start.y());
00782                             arrowTrans.rotate(r);
00783                             arrowTrans.scale(OB.Pwidth, OB.Pwidth);
00784                             arrow.map(arrowTrans);
00785                             pS->setBrush(pS->pen());
00786                             pS->setLineWidth(0);
00787                             pS->setFillMode(ScPainter::Solid);
00788                             pS->setupPolygon(&arrow);
00789                             pS->drawPolygon();
00790                             break;
00791                         }
00792                     }
00793                 }
00794                 if (OB.endArrowIndex != 0)
00795                 {
00796                     FPoint End = OB.PoLine.point(OB.PoLine.size()-2);
00797                     for (uint xx = OB.PoLine.size()-1; xx > 0; xx -= 2)
00798                     {
00799                         FPoint Vector = OB.PoLine.point(xx);
00800                         if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
00801                         {
00802                             double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
00803                             QMatrix arrowTrans;
00804                             FPointArray arrow = arrowStyles.at(OB.endArrowIndex-1).points.copy();
00805                             arrowTrans.translate(End.x(), End.y());
00806                             arrowTrans.rotate(r);
00807                             arrowTrans.scale(OB.Pwidth, OB.Pwidth);
00808                             arrow.map(arrowTrans);
00809                             pS->setBrush(pS->pen());
00810                             pS->setLin