22
22
***************************************************************************/
27
#include <qfileinfo.h>
28
#include <qtextstream.h>
29
// #include <qdatastream.h>
30
// #include <qregexp.h>
33
#include <qcheckbox.h>
36
// #include <algorithm>
42
//#ifdef HAVE_UNISTD_H
48
#define __STDC__ 1 // hack to get md5_buffer correctly identified
56
// #include <setjmp.h>
57
#include "commonstrings.h"
58
// #include "pagestructs.h"
59
// #include "prefsfile.h"
60
// #include "prefscontext.h"
61
// #include "prefstable.h"
62
// #include "prefsmanager.h"
63
// #include "qprocess.h"
27
#include <QCryptographicHash>
28
#include <QDomElement>
64
31
#include "scmessagebox.h"
65
#include "scpixmapcache.h"
67
// #include "text/nlsconfig.h"
71
#define XMD_H // shut JPEGlib up
72
#if defined(Q_OS_UNIXWARE)
73
# define HAVE_BOOLEAN // libjpeg under Unixware seems to need this
79
# undef const // remove crazy C hackery in jconfig.h
84
32
#include "scribus.h"
85
33
#include "scribusdoc.h"
86
#include "scribusview.h"
87
/*#include <ft2build.h>
88
#include FT_FREETYPE_H
34
#include "scpainter.h"
38
#if !defined(_WIN32) && !defined(Q_OS_MAC)
95
43
using namespace std;
97
45
void sDebug(QString message)
99
qDebug("%s", message.ascii());
47
qDebug("%s", message.toAscii().constData());
102
int System(const QStringList & args, const QString fileStdErr, const QString fileStdOut)
50
int System(const QString exename, const QStringList & args, const QString fileStdErr, const QString fileStdOut, bool* cancel)
104
QStringList stdErrData;
105
QStringList stdOutData;
110
/* wait a little bit */
111
while( proc.isRunning() || proc.canReadLineStdout() || proc.canReadLineStderr() )
113
// Otherwise Scribus will sleep a *lot* when proc has huge std output
114
if ( !proc.canReadLineStdout() && !proc.canReadLineStderr()) {
121
// Some configurations needs stdout and stderr to be read
122
// if needed before the created process can exit
123
if ( proc.canReadLineStdout() )
124
stdOutData.append( proc.readLineStdout() );
125
if ( proc.canReadLineStderr() )
126
stdErrData.append( proc.readLineStderr() );
128
// TODO: What about proc.normalExit() ?
129
int ex = proc.exitStatus();
130
QStringList::iterator pIterator;
131
QStringList::iterator pEnd;
132
if ( !fileStdErr.isEmpty() )
134
QFile ferr(fileStdErr);
135
if ( ferr.open(IO_WriteOnly) )
137
pEnd = stdErrData.end();
138
QTextStream errStream(&ferr);
139
for ( pIterator = stdErrData.begin(); pIterator != pEnd; pIterator++ )
140
errStream << *pIterator << endl;
145
if ( !fileStdOut.isEmpty() )
147
QFile fout(fileStdOut);
148
if ( fout.open(IO_WriteOnly) )
150
pEnd = stdOutData.end();
151
QTextStream outStream(&fout);
152
for ( pIterator = stdOutData.begin(); pIterator != pEnd; pIterator++ )
153
outStream << *pIterator << endl;
53
if (!fileStdOut.isEmpty())
54
proc.setStandardOutputFile(fileStdOut);
55
if (!fileStdErr.isEmpty())
56
proc.setStandardErrorFile(fileStdErr);
57
proc.start(exename, args);
58
if (proc.waitForStarted(5000))
60
while (!proc.waitForFinished(5000))
62
qApp->processEvents();
63
if (cancel && (*cancel == true))
70
if (cancel && (*cancel == true))
72
int ex = proc.exitCode();
160
76
// On Windows, return short path name, else return longPath;
161
QString getShortPathName(QString longPath)
77
QString getShortPathName(const QString & longPath)
163
79
QString shortPath(longPath);
164
80
#if defined _WIN32
165
81
QFileInfo fInfo(longPath);
168
char shortName[MAX_PATH + 1];
84
WCHAR shortName[MAX_PATH + 1];
169
85
// An error should not be blocking as ERROR_INVALID_PARAMETER can simply mean
170
86
// that volume does not support 8.3 filenames, so return longPath in this case
171
int ret = GetShortPathName(QDir::convertSeparators(longPath).local8Bit(), shortName, sizeof(shortName));
172
if( ret != ERROR_INVALID_PARAMETER && ret < sizeof(shortName))
173
shortPath = shortName;
87
QString nativePath = QDir::convertSeparators(longPath);
88
int ret = GetShortPathNameW((LPCWSTR) nativePath.utf16(), shortName, MAX_PATH);
89
if (ret != ERROR_INVALID_PARAMETER && ret < MAX_PATH)
90
shortPath = QString::fromUtf16((const ushort*) shortName);
179
int copyFile(QString source, QString target)
96
// On Windows, return short path name, else return longPath;
97
QString getLongPathName(const QString & shortPath)
182
if ((source.isNull()) || (target.isNull()))
184
if (source == target)
190
QByteArray bb( 65536 );
191
if (s.open(IO_ReadOnly))
99
QString longPath(shortPath);
101
QFileInfo fInfo(longPath);
193
if (t.open(IO_WriteOnly))
195
bytesread = s.readBlock( bb.data(), bb.size() );
196
while( bytesread > 0 )
198
t.writeBlock( bb.data(), bytesread );
199
bytesread = s.readBlock( bb.data(), bb.size() );
104
WCHAR longName[MAX_PATH + 1];
105
// An error should not be blocking as ERROR_INVALID_PARAMETER can simply mean
106
// that volume does not support long filenames, so return shortPath in this case
107
QString nativePath = QDir::convertSeparators(shortPath);
108
int ret = GetLongPathNameW((LPCWSTR) nativePath.utf16(), longName, MAX_PATH);
109
if (ret != ERROR_INVALID_PARAMETER && ret < MAX_PATH)
110
longPath = QString::fromUtf16((const ushort*) longName);
208
int moveFile(QString source, QString target)
210
if ((source.isNull()) || (target.isNull()))
212
if (source == target)
214
copyFile(source, target);
215
QFile::remove(source);
219
116
QString GetAttr(QDomElement *el, QString at, QString def)
350
QPointArray RegularPolygon(double w, double h, uint c, bool star, double factor, double rota)
352
uint cx = star ? c * 2 : c;
353
double seg = 360.0 / cx;
354
double sc = rota + 180.0;
358
//QPointArray pts = QPointArray();
360
for (uint x = 0; x < cx; ++x)
362
sc = seg * x + 180.0 + rota;
365
double wf = x % 2 == 0 ? w / 2 : w / 2 * di;
366
double hf = x % 2 == 0 ? h / 2 : h / 2 * di;
367
mx = qRound(sin(sc / 180 * M_PI) * (wf) + (w/2));
368
my = qRound(cos(sc / 180 * M_PI) * (hf) + (h/2));
372
mx = qRound(sin(sc / 180 * M_PI) * (w/2) + (w/2));
373
my = qRound(cos(sc / 180 * M_PI) * (h/2) + (h/2));
376
pts.setPoint(x, mx, my);
381
FPointArray RegularPolygonF(double w, double h, uint c, bool star, double factor, double rota)
383
uint cx = star ? c * 2 : c;
384
double seg = 360.0 / cx;
385
double sc = rota + 180.0;
391
for (uint x = 0; x < cx; ++x)
393
sc = seg * x + 180.0 + rota;
396
double wf = x % 2 == 0 ? w / 2 : w / 2 * di;
397
double hf = x % 2 == 0 ? h / 2 : h / 2 * di;
398
mx = qRound(sin(sc / 180 * M_PI) * (wf) + (w/2));
399
my = qRound(cos(sc / 180 * M_PI) * (hf) + (h/2));
403
mx = sin(sc / 180 * M_PI) * (w/2) + (w/2);
404
my = cos(sc / 180 * M_PI) * (h/2) + (h/2);
407
pts.setPoint(x, mx, my);
412
QPointArray FlattenPath(FPointArray ina, QValueList<uint> &Segs)
415
QPointArray outa, cli;
419
for (uint poi=0; poi<ina.size()-3; poi += 4)
421
if (ina.point(poi).x() > 900000 && cli.size() > 0)
423
outa.resize(outa.size()+1);
424
outa.setPoint(outa.size()-1, cli.point(cli.size()-1));
425
Segs.append(outa.size());
428
BezierPoints(&Bez, ina.pointQ(poi), ina.pointQ(poi+1), ina.pointQ(poi+3), ina.pointQ(poi+2));
429
cli = Bez.cubicBezier();
430
outa.putPoints(outa.size(), cli.size()-1, cli);
432
outa.resize(outa.size()+1);
433
outa.setPoint(outa.size()-1, cli.point(cli.size()-1));
438
double xy2Deg(double x, double y)
440
return (atan2(y,x)*(180.0/M_PI));
443
void BezierPoints(QPointArray *ar, QPoint n1, QPoint n2, QPoint n3, QPoint n4)
452
void Level2Layer(ScribusDoc *currentDoc, struct Layer *ll, int Level)
454
uint layerCount=currentDoc->layerCount();
455
for (uint la2 = 0; la2 < layerCount; ++la2)
457
if (currentDoc->Layers[la2].Level == Level)
459
ll->isViewable = currentDoc->Layers[la2].isViewable;
460
ll->isPrintable = currentDoc->Layers[la2].isPrintable;
461
ll->LNr = currentDoc->Layers[la2].LNr;
462
ll->Name = currentDoc->Layers[la2].Name;
463
ll->flowControl = currentDoc->Layers[la2].flowControl;
464
ll->transparency = currentDoc->Layers[la2].transparency;
465
ll->blendMode = currentDoc->Layers[la2].blendMode;
471
/* CB Replaced by ScribusDoc::layerLevelFromNumber
472
int Layer2Level(ScribusDoc *currentDoc, int LayerNr)
474
int retVal=currentDoc->layerLevelFromNumber(LayerNr);
475
int layerCount=currentDoc->layerCount();
476
for (uint la2 = 0; la2 < layerCount; ++la2)
478
if (currentDoc->Layers[la2].LNr == LayerNr)
479
return currentDoc->Layers[la2].Level;
484
206
QString CompressStr(QString *in)
486
208
QString out = "";
487
QByteArray bb(in->length());
488
for (uint ax = 0; ax < in->length(); ++ax)
489
bb[ax] = uchar(QChar(in->at(ax)));
490
uLong exlen = uint(bb.size() * 0.001 + 16) + bb.size();
491
QByteArray bc(exlen);
492
int errcode = compress2((Byte *)bc.data(), &exlen, (Byte *)bb.data(), uLong(bb.size()), 9);
495
qDebug("compress2 failed with code %i", errcode);
209
QByteArray bb(in->length(), ' ');
210
if (bb.size() == in->length())
212
for (int ax = 0; ax < in->length(); ++ax)
214
// bb.insert(ax, in->at(ax)); JG monstruously inefficient due to frequent memory reallocation
215
bb[ax] = in->at(ax).cell();
216
assert(in->at(ax).row() == 0);
218
uLong exlen = (uLong)(bb.size() * 0.001 + 16) + bb.size();
219
QByteArray bc(exlen, ' ');
220
if( bc.size() == static_cast<qint32>(exlen) )
222
int errcode = compress2((Byte *)bc.data(), &exlen, (Byte *)bb.data(), uLong(bb.size()), 9);
225
qDebug("compress2 failed with code %i", errcode);
229
for (uint cl = 0; cl < exlen; ++cl)
230
out += QChar(bc[cl]);
235
qDebug("insufficient memory to allocate %i bytes", in->length());
241
qDebug("insufficient memory to allocate %i bytes", in->length());
499
for (uint cl = 0; cl < exlen; ++cl)
500
out += QChar(bc[cl]);
505
QByteArray CompressArray(QByteArray *in)
247
QByteArray CompressArray(const QByteArray& in)
508
uLong exlen = uint(in->size() * 0.001 + 16) + in->size();
509
QByteArray temp(exlen);
510
int errcode = compress2((Byte *)temp.data(), &exlen, (Byte *)in->data(), uLong(in->size()), 9);
250
uLong exlen = uint(in.size() * 0.001 + 16) + in.size();
251
QByteArray temp(exlen, ' ');
252
int errcode = compress2((Byte *)temp.data(), &exlen, (Byte *)in.data(), uLong(in.size()), 9);
513
qDebug("compress2 failed with code %i", errcode);
517
255
temp.resize(exlen);
259
qDebug("compress2 failed with code %i", errcode);
263
char *toAscii85( quint32 value, bool& allZero )
266
static char asciiVal[6];
268
for (i = 0; i < 5; ++i)
273
asciiVal[4-i] = digit + 33;
274
value = (value - digit) / 85;
523
280
char *toHex( uchar u )
525
282
static char hexVal[3];
767
void GetItemProps(bool newVersion, QDomElement *obj, struct CopyPasteBuffer *OB)
772
OB->PType = static_cast<PageItem::ItemType>(obj->attribute("PTYPE").toInt());
773
OB->Width=obj->attribute("WIDTH").toDouble();
774
OB->Height=obj->attribute("HEIGHT").toDouble();
775
OB->RadRect = obj->attribute("RADRECT", "0").toDouble();
776
OB->ClipEdited = obj->attribute("CLIPEDIT", "0").toInt();
777
OB->FrameType = obj->attribute("FRTYPE", "0").toInt();
778
OB->Pwidth=obj->attribute("PWIDTH").toDouble();
779
OB->Pcolor = obj->attribute("PCOLOR");
780
if ((!newVersion) && (OB->PType == 4))
782
OB->TxtFill = obj->attribute("PCOLOR2");
783
OB->Pcolor2 = CommonStrings::None;
787
OB->Pcolor2 = obj->attribute("PCOLOR2");
788
OB->TxtFill = obj->attribute("TXTFILL", "Black");
790
OB->Shade = obj->attribute("SHADE").toInt();
791
OB->Shade2 = obj->attribute("SHADE2").toInt();
792
OB->FillRule = obj->attribute("fillRule", "1").toInt();
793
OB->TxtStroke=obj->attribute("TXTSTROKE", CommonStrings::None);
794
OB->ShTxtFill=obj->attribute("TXTFILLSH", "100").toInt();
795
OB->ShTxtStroke=obj->attribute("TXTSTRSH", "100").toInt();
796
OB->TxtScale=qRound(obj->attribute("TXTSCALE", "100").toDouble() * 10);
797
OB->TxtScaleV=qRound(obj->attribute("TXTSCALEV", "100").toDouble() * 10);
798
OB->TxTBase=qRound(obj->attribute("TXTBASE", "0").toDouble() * 10);
799
OB->TxTStyle=obj->attribute("TXTSTYLE", "0").toInt();
800
OB->TxtShadowX=qRound(obj->attribute("TXTSHX", "5").toDouble() * 10);
801
OB->TxtShadowY=qRound(obj->attribute("TXTSHY", "-5").toDouble() * 10);
802
OB->TxtOutline=qRound(obj->attribute("TXTOUT", "1").toDouble() * 10);
803
OB->TxtUnderPos=qRound(obj->attribute("TXTULP", "-0.1").toDouble() * 10);
804
OB->TxtUnderWidth=qRound(obj->attribute("TXTULW", "-0.1").toDouble() * 10);
805
OB->TxtStrikePos=qRound(obj->attribute("TXTSTP", "-0.1").toDouble() * 10);
806
OB->TxtStrikeWidth=qRound(obj->attribute("TXTSTW", "-0.1").toDouble() * 10);
807
OB->Cols = obj->attribute("COLUMNS", "1").toInt();
808
OB->ColGap = obj->attribute("COLGAP", "0.0").toDouble();
809
OB->GrType = obj->attribute("GRTYP", "0").toInt();
810
OB->fill_gradient.clearStops();
815
OB->pattern = obj->attribute("pattern", "");
816
OB->patternScaleX = obj->attribute("pScaleX", "100.0").toDouble();
817
OB->patternScaleY = obj->attribute("pScaleY", "100.0").toDouble();
818
OB->patternOffsetX = obj->attribute("pOffsetX", "0.0").toDouble();
819
OB->patternOffsetY = obj->attribute("pOffsetY", "0.0").toDouble();
820
OB->patternRotation = obj->attribute("pRotation", "0.0").toDouble();
824
OB->GrStartX = obj->attribute("GRSTARTX", "0.0").toDouble();
825
OB->GrStartY = obj->attribute("GRSTARTY", "0.0").toDouble();
826
OB->GrEndX = obj->attribute("GRENDX", "0.0").toDouble();
827
OB->GrEndY = obj->attribute("GRENDY", "0.0").toDouble();
828
OB->GrColor = obj->attribute("GRCOLOR","");
829
if (OB->GrColor.isEmpty())
830
OB->GrColor = "Black";
831
OB->GrColor2 = obj->attribute("GRCOLOR2","Black");
832
if (OB->GrColor2.isEmpty())
833
OB->GrColor2 = "Black";
834
OB->GrShade = obj->attribute("GRSHADE", "100").toInt();
835
OB->GrShade2 = obj->attribute("GRSHADE2", "100").toInt();
838
OB->Rot=obj->attribute("ROT").toDouble();
839
OB->PLineArt=Qt::PenStyle(obj->attribute("PLINEART").toInt());
840
OB->PLineEnd=Qt::PenCapStyle(obj->attribute("PLINEEND", "0").toInt());
841
OB->PLineJoin=Qt::PenJoinStyle(obj->attribute("PLINEJOIN", "0").toInt());
842
OB->LineSp=obj->attribute("LINESP").toDouble();
843
OB->LineSpMode = obj->attribute("LINESPMode", "0").toInt();
844
OB->LocalScX=obj->attribute("LOCALSCX").toDouble();
845
OB->LocalScY=obj->attribute("LOCALSCY").toDouble();
846
OB->LocalX=obj->attribute("LOCALX").toDouble();
847
OB->LocalY=obj->attribute("LOCALY").toDouble();
848
OB->PicArt=obj->attribute("PICART").toInt();
849
OB->flippedH = obj->attribute("FLIPPEDH").toInt() % 2;
850
OB->flippedV = obj->attribute("FLIPPEDV").toInt() % 2;
851
/* OB->BBoxX=obj->attribute("BBOXX").toDouble();
852
OB->BBoxH=obj->attribute("BBOXH").toDouble(); */
853
OB->ScaleType = obj->attribute("SCALETYPE", "1").toInt();
854
OB->AspectRatio = obj->attribute("RATIO", "0").toInt();
855
OB->isPrintable=obj->attribute("PRINTABLE").toInt();
856
OB->m_isAnnotation=obj->attribute("ANNOTATION", "0").toInt();
857
OB->m_annotation.setType(obj->attribute("ANTYPE", "0").toInt());
858
OB->m_annotation.setAction(obj->attribute("ANACTION",""));
859
OB->m_annotation.setE_act(obj->attribute("ANEACT",""));
860
OB->m_annotation.setX_act(obj->attribute("ANXACT",""));
861
OB->m_annotation.setD_act(obj->attribute("ANDACT",""));
862
OB->m_annotation.setFo_act(obj->attribute("ANFOACT",""));
863
OB->m_annotation.setBl_act(obj->attribute("ANBLACT",""));
864
OB->m_annotation.setK_act(obj->attribute("ANKACT",""));
865
OB->m_annotation.setF_act(obj->attribute("ANFACT",""));
866
OB->m_annotation.setV_act(obj->attribute("ANVACT",""));
867
OB->m_annotation.setC_act(obj->attribute("ANCACT",""));
868
OB->m_annotation.setActionType(obj->attribute("ANACTYP", "0").toInt());
869
OB->m_annotation.setExtern(obj->attribute("ANEXTERN",""));
870
if ((!OB->m_annotation.Extern().isEmpty()) && (OB->m_annotation.ActionType() != 8))
872
QFileInfo efp(OB->m_annotation.Extern());
873
OB->m_annotation.setExtern(efp.absFilePath());
875
OB->m_annotation.setZiel(obj->attribute("ANZIEL", "0").toInt());
876
OB->AnName=obj->attribute("ANNAME","");
877
OB->m_annotation.setToolTip(obj->attribute("ANTOOLTIP",""));
878
OB->m_annotation.setRollOver(obj->attribute("ANROLL",""));
879
OB->m_annotation.setDown(obj->attribute("ANDOWN",""));
880
OB->m_annotation.setBwid(obj->attribute("ANBWID", "1").toInt());
881
OB->m_annotation.setBsty(obj->attribute("ANBSTY", "0").toInt());
882
OB->m_annotation.setFeed(obj->attribute("ANFEED", "1").toInt());
883
OB->m_annotation.setFlag(obj->attribute("ANFLAG", "0").toInt());
884
OB->m_annotation.setFont(obj->attribute("ANFONT", "4").toInt());
885
OB->m_annotation.setFormat(obj->attribute("ANFORMAT", "0").toInt());
886
OB->m_annotation.setVis(obj->attribute("ANVIS", "0").toInt());
887
OB->m_annotation.setIsChk(static_cast<bool>(obj->attribute("ANCHK", "0").toInt()));
888
OB->m_annotation.setAAact(static_cast<bool>(obj->attribute("ANAA", "0").toInt()));
889
OB->m_annotation.setHTML(static_cast<bool>(obj->attribute("ANHTML", "0").toInt()));
890
OB->m_annotation.setUseIcons(static_cast<bool>(obj->attribute("ANICON", "0").toInt()));
891
OB->m_annotation.setChkStil(obj->attribute("ANCHKS", "0").toInt());
892
OB->m_annotation.setMaxChar(obj->attribute("ANMC", "-1").toInt());
893
OB->m_annotation.setBorderColor(obj->attribute("ANBCOL",CommonStrings::None));
894
OB->m_annotation.setIPlace(obj->attribute("ANPLACE", "1").toInt());
895
OB->m_annotation.setScaleW(obj->attribute("ANSCALE", "0").toInt());
896
if (obj->attribute("TRANSPARENT", "0").toInt() == 1)
897
OB->Pcolor = CommonStrings::None;
898
OB->textAlignment=obj->attribute("ALIGN", "0").toInt();
899
if ( obj->hasAttribute("TEXTFLOWMODE") )
900
OB->TextflowMode = (PageItem::TextFlowMode) obj->attribute("TEXTFLOWMODE", "0").toInt();
901
else if ( obj->attribute("TEXTFLOW").toInt() )
903
if (obj->attribute("TEXTFLOW2", "0").toInt())
904
OB->TextflowMode = PageItem::TextFlowUsesBoundingBox;
905
else if (obj->attribute("TEXTFLOW3", "0").toInt())
906
OB->TextflowMode = PageItem::TextFlowUsesContourLine;
908
OB->TextflowMode = PageItem::TextFlowUsesFrameShape;
911
OB->TextflowMode = PageItem::TextFlowDisabled;
912
OB->Extra=obj->attribute("EXTRA").toDouble();
913
OB->TExtra=obj->attribute("TEXTRA", "1").toDouble();
914
OB->BExtra=obj->attribute("BEXTRA", "1").toDouble();
915
OB->RExtra=obj->attribute("REXTRA", "1").toDouble();
916
OB->PoShow = obj->attribute("PLTSHOW", "0").toInt();
917
OB->BaseOffs = obj->attribute("BASEOF", "0").toDouble();
918
OB->textPathType = obj->attribute("textPathType", "0").toInt();
919
OB->textPathFlipped = static_cast<bool>(obj->attribute("textPathFlipped", "0").toInt());
920
OB->ISize = qRound(obj->attribute("ISIZE", "12").toDouble() * 10);
921
if (obj->hasAttribute("EXTRAV"))
922
OB->ExtraV = qRound(obj->attribute("EXTRAV", "0").toDouble() / obj->attribute("ISIZE", "12").toDouble() * 1000.0);
924
OB->ExtraV = obj->attribute("TXTKERN").toInt();
925
OB->Pfile=obj->attribute("PFILE");
926
OB->Pfile2=obj->attribute("PFILE2","");
927
OB->Pfile3=obj->attribute("PFILE3","");
928
OB->IProfile=obj->attribute("PRFILE","");
929
OB->EmProfile=obj->attribute("EPROF","");
930
OB->IRender = obj->attribute("IRENDER", "1").toInt();
931
OB->UseEmbedded = obj->attribute("EMBEDDED", "1").toInt();
932
OB->Locked = static_cast<bool>(obj->attribute("LOCK", "0").toInt());
933
OB->LockRes = static_cast<bool>(obj->attribute("LOCKR", "0").toInt());
934
OB->Reverse = static_cast<bool>(obj->attribute("REVERS", "0").toInt());
935
OB->isTableItem = static_cast<bool>(obj->attribute("isTableItem", "0").toInt());
936
OB->TopLine = static_cast<bool>(obj->attribute("TopLine", "0").toInt());
937
OB->LeftLine = static_cast<bool>(obj->attribute("LeftLine", "0").toInt());
938
OB->RightLine = static_cast<bool>(obj->attribute("RightLine", "0").toInt());
939
OB->BottomLine = static_cast<bool>(obj->attribute("BottomLine", "0").toInt());
940
OB->TopLinkID = obj->attribute("TopLINK", "-1").toInt();
941
OB->LeftLinkID = obj->attribute("LeftLINK", "-1").toInt();
942
OB->RightLinkID = obj->attribute("RightLINK", "-1").toInt();
943
OB->BottomLinkID = obj->attribute("BottomLINK", "-1").toInt();
944
OB->Transparency = obj->attribute("TransValue", "0.0").toDouble();
945
if (obj->hasAttribute("TransValueS"))
946
OB->TranspStroke = obj->attribute("TransValueS", "0.0").toDouble();
948
OB->TranspStroke = OB->Transparency;
949
OB->TransBlend = obj->attribute("TransBlend", "0").toInt();
950
OB->TransBlendS = obj->attribute("TransBlendS", "0").toInt();
952
if (obj->hasAttribute("NUMCLIP"))
954
OB->Clip.resize(obj->attribute("NUMCLIP").toUInt());
955
tmp = obj->attribute("CLIPCOOR");
956
QTextStream fc(&tmp, IO_ReadOnly);
957
for (uint c=0; c<obj->attribute("NUMCLIP").toUInt(); ++c)
961
OB->Clip.setPoint(c, x, y);
967
if (obj->hasAttribute("NUMPO"))
969
OB->PoLine.resize(obj->attribute("NUMPO").toUInt());
970
tmp = obj->attribute("POCOOR");
971
QTextStream fp(&tmp, IO_ReadOnly);
972
for (uint cx=0; cx<obj->attribute("NUMPO").toUInt(); ++cx)
976
OB->PoLine.setPoint(cx, xf, yf);
980
OB->PoLine.resize(0);
982
if (obj->hasAttribute("NUMCO"))
984
OB->ContourLine.resize(obj->attribute("NUMCO").toUInt());
985
tmp = obj->attribute("COCOOR");
986
QTextStream fp(&tmp, IO_ReadOnly);
987
for (uint cx=0; cx<obj->attribute("NUMCO").toUInt(); ++cx)
991
OB->ContourLine.setPoint(cx, xf, yf);
995
OB->ContourLine.resize(0);
997
if ((obj->hasAttribute("NUMTAB")) && (obj->attribute("NUMTAB", "0").toInt() != 0))
999
ParagraphStyle::TabRecord tb;
1000
tmp = obj->attribute("TABS");
1001
QTextStream tgv(&tmp, IO_ReadOnly);
1002
OB->TabValues.clear();
1003
for (int cxv = 0; cxv < obj->attribute("NUMTAB", "0").toInt(); cxv += 2)
1007
tb.tabPosition = xf2;
1008
tb.tabType = static_cast<int>(xf);
1009
tb.tabFillChar = QChar();
1010
OB->TabValues.append(tb);
1015
OB->TabValues.clear();
1016
if ((obj->hasAttribute("NUMDASH")) && (obj->attribute("NUMDASH", "0").toInt() != 0))
1018
tmp = obj->attribute("DASHS");
1019
QTextStream dgv(&tmp, IO_ReadOnly);
1020
OB->DashValues.clear();
1021
for (int cxv = 0; cxv < obj->attribute("NUMDASH", "0").toInt(); ++cxv)
1024
OB->DashValues.append(xf);
1029
OB->DashValues.clear();
1030
OB->DashOffset = obj->attribute("DASHOFF", "0.0").toDouble();
1033
FPoint getMaxClipF(FPointArray* Clip)
1038
uint clipSize=Clip->size();
1039
for (uint c = 0; c < clipSize; ++c)
1041
np = Clip->point(c);
1042
if (np.x() > 900000)
1053
FPoint getMinClipF(FPointArray* Clip)
1058
uint clipSize=Clip->size();
1059
for (uint c = 0; c < clipSize; ++c)
1061
np = Clip->point(c);
1062
if (np.x() > 900000)
1073
498
QString checkFileExtension(const QString &currName, const QString &extension)
1075
500
QString newName(currName);
1076
501
//If filename ends with a period, just add the extension
1077
502
if (newName.right(1)==".")
1079
newName+=extension.lower();
504
newName+=extension.toLower();
1082
507
//If filename doesnt end with the period+extension, add it on
1083
QString dotExt("." + extension.lower());
1084
if (!newName.endsWith(dotExt,false))
508
QString dotExt("." + extension.toLower());
509
if (!newName.endsWith(dotExt, Qt::CaseInsensitive))
1085
510
newName+=dotExt;
1089
514
QString getFileNameByPage(ScribusDoc* currDoc, uint pageNo, QString extension)
1092
number = number.setNum(pageNo + currDoc->FirstPnum);
516
uint number = pageNo + currDoc->FirstPnum;
1093
517
QString defaultName = currDoc->DocName;
1094
518
if (defaultName.isNull())
1095
519
defaultName = "export";
1098
522
QFileInfo fi(defaultName);
1099
defaultName = fi.baseName(true);
1101
return QString("%1-%2%3.%4").arg(defaultName).arg(QObject::tr("page", "page export")).arg(number).arg(extension);
1104
bool compareDouble(double a, double b)
1106
if(a > -21473 && b > -21473 && a < 21474 && b < 21474)
1108
long al = static_cast<long>(10000 * a);
1109
long bl = static_cast<long>(10000 * b);
1115
inline double square(double x)
1120
inline double distance(double x, double y)
1122
return sqrt(x*x+y*y);
1125
double constrainAngle(double angle, double constrain)
1127
double newAngle=angle;
1128
double constrainTo=constrain;
1131
newAngle=qRound(angle/constrainTo)*constrainTo;
1132
if (newAngle==360.0)
1137
double getRotationFromMatrix(QWMatrix& matrix, double def)
1140
double norm = sqrt(fabs(matrix.det()));
1141
if (norm > 0.0000001)
1143
double m11 = matrix.m11() / norm;
1144
double m12 = matrix.m12() / norm;
1145
double m21 = matrix.m21() / norm;
1146
double m22 = matrix.m22() / norm;
1147
if (fabs(m11) <= 1.0 && fabs(m12) <= 1.0 && fabs(m21) <= 1.0 && fabs(m22) <= 1.0)
1149
QWMatrix mat(m11, m12, m21, m22, 0, 0);
1150
if (abs(mat.det()-1.0) < 0.00001 && (mat.m12() == -mat.m21()))
1152
double ac = acos(mat.m11());
1153
value = (mat.m21() >= 0.0) ? ac : (-ac);
523
defaultName = fi.completeBaseName();
525
return QString("%1-%2%3.%4").arg(defaultName).arg(QObject::tr("page", "page export")).arg(number, 3, 10, QChar('0')).arg(extension);
1160
528
const QString getStringFromSequence(DocumentSectionType type, uint position)
1370
738
} while (!tmp.isEmpty());
1374
int findParagraphStyle(ScribusDoc* doc, const ParagraphStyle& parStyle)
1376
bool named = !parStyle.name().isEmpty();
1377
//qDebug(QString("looking up %1/ %2").arg(parStyle.name()).arg(parStyle.alignment()));
1379
for (uint i=0; i < doc->paragraphStyles().count(); ++i)
1381
//qDebug(QString("%1 %2").arg(i).arg(doc->paragraphStyles()[i].name()));
1382
if (parStyle.name() == doc->paragraphStyles()[i].name()) {
1394
int findParagraphStyle(ScribusDoc* doc, const QString &name)
1396
for (uint i=0; i < doc->paragraphStyles().count(); ++i)
1398
if (name == doc->paragraphStyles()[i].name()) {
1407
QPixmap getQCheckBoxPixmap(const bool checked, const QColor background)
1409
QCheckBox *tmpItem = new QCheckBox("", 0, "tmpItem");
1410
tmpItem->setMaximumSize(QSize(30, 30));
1411
tmpItem->setMinimumSize(QSize(30, 30));
1412
tmpItem->setPaletteBackgroundColor(background);
1413
tmpItem->setChecked(checked);
1414
QPixmap pm = QPixmap::grabWidget(tmpItem);
1415
pm.setMask(pm.createHeuristicMask());
1421
741
void tDebug(QString message)
1423
743
QDateTime debugTime;
1424
qDebug("%s", QString("%1\t%2").arg(debugTime.currentDateTime().toString("hh:mm:ss:zzz")).arg(message).ascii());
1427
QString setupImageFormats()
1429
QString formats = "";
1430
QString formatD = QObject::tr("All Supported Formats")+" (";
1433
for ( uint i = 0; i < QImageIO::inputFormats().count(); ++i )
1435
form1 = QString(QImageIO::inputFormats().at(i)).lower();
1436
form2 = QString(QImageIO::inputFormats().at(i)).upper();
1437
if (form1 == "jpeg")
1442
if ((form1 == "png") || (form1 == "xpm") || (form1 == "gif"))
1444
formats += form2 + " (*."+form1+" *."+form2+");;";
1445
formatD += "*."+form1+" *."+form2+" ";
1447
else if (form1 == "jpg")
1449
// JPEG is a special case because both .jpg and .jpeg
1450
// are acceptable extensions.
1451
formats += "JPEG (*.jpg *.jpeg *.JPG *.JPEG);;";
1452
formatD += "*.jpg *.jpeg *.JPG *.JPEG ";
1455
formats += "TIFF (*.tif *.tiff *.TIF *.TIFF);;";
1456
formatD += "*.tif *.tiff *.TIF *.TIFF";
1457
formats += "PSD (*.psd *.PSD);;";
1458
formatD += " *.psd *.PSD";
1459
formats += "EPS (*.eps *.EPS);;EPSI (*.epsi *.EPSI);;PDF (*.pdf *.PDF);;" + QObject::tr("All Files (*)");
1460
formatD += " *.epsi *.EPSI *.eps *.EPS *.pdf *.PDF";
1461
formatD += ");;"+formats;
1465
QString getImageType(QString filename)
744
qDebug("%s", QString("%1\t%2").arg(debugTime.currentDateTime().toString("hh:mm:ss:zzz")).arg(message).toAscii().constData());
748
QString readLinefromDataStream(QDataStream &s)
1467
750
QString ret = "";
1473
if (f.open(IO_ReadOnly))
1475
f.readBlock(buf.data(), 20);
1476
if ((buf[0] == '%') && (buf[1] == '!') && (buf[2] == 'P') && (buf[3] == 'S') && (buf[4] == '-') && (buf[5] == 'A'))
1478
else if ((buf[0] == '\xC5') && (buf[1] == '\xD0') && (buf[2] == '\xD3') && (buf[3] == '\xC6'))
1480
else if ((buf[0] == 'G') && (buf[1] == 'I') && (buf[2] == 'F') && (buf[3] == '8'))
1482
else if ((buf[0] == '\xFF') && (buf[1] == '\xD8') && (buf[2] == '\xFF'))
1484
else if ((buf[0] == '%') && (buf[1] == 'P') && (buf[2] == 'D') && (buf[3] == 'F'))
1486
else if ((buf[0] == '\x89') && (buf[1] == 'P') && (buf[2] == 'N') && (buf[3] == 'G'))
1488
else if ((buf[0] == '8') && (buf[1] == 'B') && (buf[2] == 'P') && (buf[3] == 'S'))
1490
else if (((buf[0] == 'I') && (buf[1] == 'I') && (buf[2] == '\x2A')) || ((buf[0] == 'M') && (buf[1] == 'M') && (buf[3] == '\x2A')))
1492
else if ((buf[0] == '/') && (buf[1] == '*') && (buf[2] == ' ') && (buf[3] == 'X') && (buf[4] == 'P') && (buf[5] == 'M'))
755
if (charData == '\x0A')
757
if (charData == '\x0D')
759
quint64 oldPos = s.device()->pos();
761
if (charData != '\x0A')
762
s.device()->seek(oldPos);
765
ret += QChar(charData);
767
return ret.trimmed();
770
void setCurrentComboItem(QComboBox *box, QString text)
772
box->blockSignals(true);
773
int ind = box->findText(text);
775
box->setCurrentIndex(ind);
776
box->blockSignals(false);
779
QString getDashString(int dashtype, double linewidth)
782
QVector<double> dashArray;
783
getDashArray(dashtype, linewidth, dashArray);
784
for (int a = 0; a < dashArray.size(); ++a)
786
dashString += QString::number(dashArray.at(a));
787
if (a < (dashArray.size() - 1))
793
void getDashArray(int dashtype, double linewidth, QVector<float> &m_array) {
795
getDashArray(dashtype, linewidth, tmp);
797
for (int i = 0; i < tmp.count(); ++i) {
798
m_array << static_cast<float>(tmp[i]);
802
void getDashArray(int dashtype, double linewidth, QVector<double> &m_array)
805
if ((dashtype == 1) || (dashtype == 0))
807
double Dt = qMax(1.0*linewidth, 0.1);
808
double Sp = qMax(2.0*linewidth, 0.1);
809
double Da = qMax(4.0*linewidth, 0.1);
821
m_array << Da << Sp << Dt << Sp;
824
m_array << Da << Sp << Dt << Sp << Dt << Sp;
826
// Additional line styles taken from Inkscape
828
m_array << qMax(1.0 * linewidth, 0.01) << qMax(1.0 * linewidth, 0.01);
831
m_array << qMax(1.0 * linewidth, 0.01) << qMax(3.0 * linewidth, 0.01);
834
m_array << qMax(1.0 * linewidth, 0.01) << qMax(4.0 * linewidth, 0.01);
837
m_array << qMax(1.0 * linewidth, 0.01) << qMax(6.0 * linewidth, 0.01);
840
m_array << qMax(1.0 * linewidth, 0.01) << qMax(8.0 * linewidth, 0.01);
843
m_array << qMax(1.0 * linewidth, 0.01) << qMax(12.0 * linewidth, 0.01);
846
m_array << qMax(1.0 * linewidth, 0.01) << qMax(24.0 * linewidth, 0.01);
849
m_array << qMax(1.0 * linewidth, 0.01) << qMax(48.0 * linewidth, 0.01);
852
m_array << qMax(2.0 * linewidth, 0.01) << qMax(1.0 * linewidth, 0.01);
855
m_array << qMax(3.0 * linewidth, 0.01) << qMax(1.0 * linewidth, 0.01);
858
m_array << qMax(4.0 * linewidth, 0.01) << qMax(1.0 * linewidth, 0.01);
861
m_array << qMax(6.0 * linewidth, 0.01) << qMax(1.0 * linewidth, 0.01);
864
m_array << qMax(8.0 * linewidth, 0.01) << qMax(1.0 * linewidth, 0.01);
867
m_array << qMax(10.0 * linewidth, 0.01) << qMax(1.0 * linewidth, 0.01);
870
m_array << qMax(12.0 * linewidth, 0.01) << qMax(1.0 * linewidth, 0.01);
873
m_array << qMax(2.0 * linewidth, 0.01) << qMax(2.0 * linewidth, 0.01);
876
m_array << qMax(3.0 * linewidth, 0.01) << qMax(3.0 * linewidth, 0.01);
879
m_array << qMax(4.0 * linewidth, 0.01) << qMax(4.0 * linewidth, 0.01);
882
m_array << qMax(6.0 * linewidth, 0.01) << qMax(6.0 * linewidth, 0.01);
885
m_array << qMax(8.0 * linewidth, 0.01) << qMax(8.0 * linewidth, 0.01);
888
m_array << qMax(10.0 * linewidth, 0.01) << qMax(10.0 * linewidth, 0.01);
891
m_array << qMax(12.0 * linewidth, 0.01) << qMax(12.0 * linewidth, 0.01);
894
m_array << qMax(2.0 * linewidth, 0.01) << qMax(4.0 * linewidth, 0.01);
897
m_array << qMax(2.0 * linewidth, 0.01) << qMax(6.0 * linewidth, 0.01);
900
m_array << qMax(6.0 * linewidth, 0.01) << qMax(2.0 * linewidth, 0.01);
903
m_array << qMax(4.0 * linewidth, 0.01) << qMax(8.0 * linewidth, 0.01);
906
m_array << qMax(8.0 * linewidth, 0.01) << qMax(4.0 * linewidth, 0.01);
909
m_array << qMax(2.0 * linewidth, 0.01) << qMax(1.0 * linewidth, 0.01);
910
m_array << qMax(0.5 * linewidth, 0.01) << qMax(1.0 * linewidth, 0.01);
913
m_array << qMax(8.0 * linewidth, 0.01) << qMax(2.0 * linewidth, 0.01);
914
m_array << qMax(1.0 * linewidth, 0.01) << qMax(2.0 * linewidth, 0.01);
917
m_array << qMax(0.5 * linewidth, 0.01) << qMax(0.5 * linewidth, 0.01);
920
m_array << qMax(0.25 * linewidth, 0.01) << qMax(0.25 * linewidth, 0.01);
923
m_array << qMax(0.1 * linewidth, 0.01) << qMax(0.1 * linewidth, 0.01);
930
#if !defined(_WIN32) && !defined(Q_OS_MAC)
933
* Please never commit code that uses it.
934
* @param nFrames specify how much frames you want to be printed
936
void printBacktrace ( int nFrames )
938
void ** trace = new void*[nFrames + 1];
939
char **messages = ( char ** ) NULL;
940
int i, trace_size = 0;
942
trace_size = backtrace ( trace, nFrames + 1 );
943
messages = backtrace_symbols ( trace, trace_size );
946
for ( i=1; i < trace_size; ++i )
948
QString msg ( messages[i] );
949
int sep1 ( msg.indexOf ( "(" ) );
950
int sep2 ( msg.indexOf ( "+" ) );
951
QString mName ( msg.mid ( sep1 + 1,sep2-sep1 -1) );
954
if(mName.startsWith("_Z"))
959
outbuf = abi::__cxa_demangle(mName.trimmed().toAscii().data(), outbuf, &length, &status);
960
name = QString::fromAscii( outbuf,length );
966
QString bts ( "[ScBT] %1. %2" );
967
qDebug ("%s", bts.arg( i ).arg( name ).toUtf8().data() );