diff --git a/Scribus.pro b/Scribus.pro index 32dd3c258..e3aa03d93 100644 --- a/Scribus.pro +++ b/Scribus.pro @@ -200,6 +200,7 @@ HEADERS += scribus/actionmanager.h \ scribus/scpreview.h \ scribus/scprintengine.h \ scribus/scprintengine_gdi.h \ + scribus/scprintengine_pdf.h \ scribus/scprintengine_ps.h \ scribus/scraction.h \ scribus/scribus.h \ @@ -1359,6 +1360,7 @@ SOURCES += scribus/actionmanager.cpp \ scribus/scplugin.cpp \ scribus/scpreview.cpp \ scribus/scprintengine_gdi.cpp \ + scribus/scprintengine_pdf.cpp \ scribus/scprintengine_ps.cpp \ scribus/scraction.cpp \ scribus/scribus.cpp \ diff --git a/scribus/CMakeLists.txt b/scribus/CMakeLists.txt index c091a1e66..33c757c15 100644 --- a/scribus/CMakeLists.txt +++ b/scribus/CMakeLists.txt @@ -743,6 +743,7 @@ set(SCRIBUS_SOURCES scpattern.cpp scplugin.cpp scpreview.cpp + scprintengine_pdf.cpp scprintengine_ps.cpp scraction.cpp scribus.cpp diff --git a/scribus/actionsearch.cpp b/scribus/actionsearch.cpp index 0b0b5b0f5..4eca79ba2 100644 --- a/scribus/actionsearch.cpp +++ b/scribus/actionsearch.cpp @@ -17,7 +17,7 @@ #include ActionSearch::ActionSearch(QMenuBar *menuBar) - : menuBar{menuBar} + : menuBar{menuBar} { } @@ -55,7 +55,7 @@ void ActionSearch::readMenuActions(QMenu* menu) menus.prepend(title); currentMenu = dynamic_cast(currentMenu->parentWidget()); } - QString menuName = menus.join(" > "); + QString menuName(menus.join(" > ")); for (auto action: menu->actions()) { diff --git a/scribus/canvasmode.cpp b/scribus/canvasmode.cpp index 6a3755138..d232f4b59 100644 --- a/scribus/canvasmode.cpp +++ b/scribus/canvasmode.cpp @@ -893,13 +893,13 @@ void CanvasMode::commonkeyPressEvent_NormalNodeEdit(QKeyEvent *e) if (m_keyRepeat) return; m_keyRepeat = true; - int keyMod=0; - if (e->modifiers() & Qt::ShiftModifier) - keyMod |= Qt::SHIFT; - if (e->modifiers() & Qt::ControlModifier) - keyMod |= Qt::CTRL; - if (e->modifiers() & Qt::AltModifier) - keyMod |= Qt::ALT; +// int keyMod=0; +// if (e->modifiers() & Qt::ShiftModifier) +// keyMod |= Qt::SHIFT; +// if (e->modifiers() & Qt::ControlModifier) +// keyMod |= Qt::CTRL; +// if (e->modifiers() & Qt::AltModifier) +// keyMod |= Qt::ALT; //User presses escape and we have a doc open, and we have an item selected if (kk == Qt::Key_Escape) { diff --git a/scribus/canvasmode_drawbezier.cpp b/scribus/canvasmode_drawbezier.cpp index 4a42f78f1..0973985d1 100644 --- a/scribus/canvasmode_drawbezier.cpp +++ b/scribus/canvasmode_drawbezier.cpp @@ -272,8 +272,6 @@ void BezierMode::mouseMoveEvent(QMouseEvent *m) { if ((m_mouseButtonPressed) && (m->buttons() & Qt::LeftButton)) { - double newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x()); - double newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y()); QPoint startP = m_canvas->canvasToGlobal(QPointF(m_xp, m_yp)); m_view->redrawMarker->setGeometry(QRect(m_view->mapFromGlobal(startP), m_view->mapFromGlobal(m->globalPos())).normalized()); m_view->setRedrawMarkerShown(true); diff --git a/scribus/canvasmode_editmeshpatch.cpp b/scribus/canvasmode_editmeshpatch.cpp index f621b23c6..5ad03940c 100644 --- a/scribus/canvasmode_editmeshpatch.cpp +++ b/scribus/canvasmode_editmeshpatch.cpp @@ -629,8 +629,10 @@ void CanvasMode_EditMeshPatch::mouseMoveEvent(QMouseEvent *m) m_canvas->displayXYHUD(m->globalPos(), npf.x(), npf.y()); if (m_view->editStrokeGradient == 9) { - FPoint mp, mp_orig; - double xx, yy; + FPoint mp; + FPoint mp_orig; + double xx = 0.0; + double yy = 0.0; if (m_patchPoint == useTL) { mp_orig = m_currItem->meshGradientPatches[m_currItem->selectedMeshPointX].TL.gridPoint; diff --git a/scribus/downloadmanager/scdlmgr.cpp b/scribus/downloadmanager/scdlmgr.cpp index ffb9c2aed..489cead87 100644 --- a/scribus/downloadmanager/scdlmgr.cpp +++ b/scribus/downloadmanager/scdlmgr.cpp @@ -15,9 +15,9 @@ ScDLManager::ScDLManager(QObject *parent) : QObject(parent) { m_thread=new ScDLThread(); - connect(m_thread, SIGNAL(fileReceived(const QString &)), this, SLOT(dlReceived(const QString&))); - connect(m_thread, SIGNAL(fileFailed(const QString &)), this, SLOT(dlFailed(const QString&))); - connect(m_thread, SIGNAL(fileStarted(const QString &)), this, SLOT(dlStarted(const QString &))); + connect(m_thread, SIGNAL(fileReceived(const QString &)), this, SLOT(dlReceived(QString))); + connect(m_thread, SIGNAL(fileFailed(const QString &)), this, SLOT(dlFailed(QString))); + connect(m_thread, SIGNAL(fileStarted(const QString &)), this, SLOT(dlStarted(QString))); connect(m_thread, SIGNAL(fileDownloadProgress(qint64,qint64)), this, SIGNAL(fileDownloadProgress(qint64,qint64))); //connect(thread, SIGNAL(finished()), this, SIGNAL(finished())); connect(m_thread, SIGNAL(finished()), this, SLOT(moveFinishedDownloads())); diff --git a/scribus/fonts/sfnt.cpp b/scribus/fonts/sfnt.cpp index 364c8a82a..2b55f9cba 100644 --- a/scribus/fonts/sfnt.cpp +++ b/scribus/fonts/sfnt.cpp @@ -64,12 +64,12 @@ namespace sfnt { putWord16(bb, pos, val); } - const QByteArray tag(const QByteArray& bb, uint pos) + QByteArray tag(const QByteArray& bb, uint pos) { return QByteArray::fromRawData(bb.constData() + pos, 4); } - const QByteArray tag(uint word) + QByteArray tag(uint word) { QByteArray result; result.resize(4); @@ -100,330 +100,330 @@ namespace sfnt { -const uint post_format10_names_count = 258; - - -static const char* post_format10_names[] = { - ".notdef", - ".null", - "nonmarkingreturn", - "space", - "exclam", - "quotedbl", - "numbersign", - "dollar", - "percent", - "ampersand", - "quotesingle", - "parenleft", - "parenright", - "asterisk", - "plus", - "comma", - "hyphen", - "period", - "slash", - "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", - "colon", - "semicolon", - "less", - "equal", - "greater", - "question", - "at", - "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", - "bracketleft", - "backslash", - "bracketright", - "asciicircum", - "underscore", - "grave", - "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", - "braceleft", - "bar", - "braceright", - "asciitilde", - "Adieresis", - "Aring", - "Ccedilla", - "Eacute", - "Ntilde", - "Odieresis", - "Udieresis", - "aacute", - "agrave", - "acircumflex", - "adieresis", - "atilde", - "aring", - "ccedilla", - "eacute", - "egrave", - "ecircumflex", - "edieresis", - "iacute", - "igrave", - "icircumflex", - "idieresis", - "ntilde", - "oacute", - "ograve", - "ocircumflex", - "odieresis", - "otilde", - "uacute", - "ugrave", - "ucircumflex", - "udieresis", - "dagger", - "degree", - "cent", - "sterling", - "section", - "bullet", - "paragraph", - "germandbls", - "registered", - "copyright", - "trademark", - "acute", - "dieresis", - "notequal", - "AE", - "Oslash", - "infinity", - "plusminus", - "lessequal", - "greaterequal", - "yen", - "mu", - "partialdiff", - "summation", - "product", - "pi", - "integral", - "ordfeminine", - "ordmasculine", - "Omega", - "ae", - "oslash", - "questiondown", - "exclamdown", - "logicalnot", - "radical", - "florin", - "approxequal", - "Delta", - "guillemotleft", - "guillemotright", - "ellipsis", - "nonbreakingspace", - "Agrave", - "Atilde", - "Otilde", - "OE", - "oe", - "endash", - "emdash", - "quotedblleft", - "quotedblright", - "quoteleft", - "quoteright", - "divide", - "lozenge", - "ydieresis", - "Ydieresis", - "fraction", - "currency", - "guilsinglleft", - "guilsinglright", - "fi", - "fl", - "daggerdbl", - "periodcentered", - "quotesinglbase", - "quotedblbase", - "perthousand", - "Acircumflex", - "Ecircumflex", - "Aacute", - "Edieresis", - "Egrave", - "Iacute", - "Icircumflex", - "Idieresis", - "Igrave", - "Oacute", - "Ocircumflex", - "apple", - "Ograve", - "Uacute", - "Ucircumflex", - "Ugrave", - "dotlessi", - "circumflex", - "tilde", - "macron", - "breve", - "dotaccent", - "ring", - "cedilla", - "hungarumlaut", - "ogonek", - "caron", - "Lslash", - "lslash", - "Scaron", - "scaron", - "Zcaron", - "zcaron", - "brokenbar", - "Eth", - "eth", - "Yacute", - "yacute", - "Thorn", - "thorn", - "minus", - "multiply", - "onesuperior", - "twosuperior", - "threesuperior", - "onehalf", - "onequarter", - "threequarters", - "franc", - "Gbreve", - "gbreve", - "Idotaccent", - "Scedilla", - "scedilla", - "Cacute", - "cacute", - "Ccaron", - "ccaron", - "dcroat" -}; - - - -bool PostTable::usable() const -{ - return m_usable; -} - -void PostTable::setUsable(bool usable) -{ - m_usable = usable; -} - -QString PostTable::errorMsg() const -{ - return m_errorMsg; -} - -void PostTable::setErrorMsg(const QString& errorMsg) -{ - m_errorMsg = errorMsg; -} - -uint PostTable::numberOfGlyphs() const -{ - if (m_names.length() > 0) - return m_names.length(); - return post_format10_names_count; -} - -QString PostTable::nameFor(uint glyph) const -{ - if (glyph < (uint) m_names.length()) - return m_names[glyph]; - if (glyph < sfnt::post_format10_names_count) - return post_format10_names[glyph]; - return ".notdef"; -} - - -void PostTable::readFrom(FT_Face face) -{ - QByteArray postData; - FT_ULong size = 0; - int error = FT_Load_Sfnt_Table ( face, TTAG_post , 0, nullptr, &size ); - //qDebug() << "load post" << error << size; - if (error || size == 0) + const uint post_format10_names_count = 258; + + + static const char* post_format10_names[] = { + ".notdef", + ".null", + "nonmarkingreturn", + "space", + "exclam", + "quotedbl", + "numbersign", + "dollar", + "percent", + "ampersand", + "quotesingle", + "parenleft", + "parenright", + "asterisk", + "plus", + "comma", + "hyphen", + "period", + "slash", + "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", + "colon", + "semicolon", + "less", + "equal", + "greater", + "question", + "at", + "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", + "bracketleft", + "backslash", + "bracketright", + "asciicircum", + "underscore", + "grave", + "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", + "braceleft", + "bar", + "braceright", + "asciitilde", + "Adieresis", + "Aring", + "Ccedilla", + "Eacute", + "Ntilde", + "Odieresis", + "Udieresis", + "aacute", + "agrave", + "acircumflex", + "adieresis", + "atilde", + "aring", + "ccedilla", + "eacute", + "egrave", + "ecircumflex", + "edieresis", + "iacute", + "igrave", + "icircumflex", + "idieresis", + "ntilde", + "oacute", + "ograve", + "ocircumflex", + "odieresis", + "otilde", + "uacute", + "ugrave", + "ucircumflex", + "udieresis", + "dagger", + "degree", + "cent", + "sterling", + "section", + "bullet", + "paragraph", + "germandbls", + "registered", + "copyright", + "trademark", + "acute", + "dieresis", + "notequal", + "AE", + "Oslash", + "infinity", + "plusminus", + "lessequal", + "greaterequal", + "yen", + "mu", + "partialdiff", + "summation", + "product", + "pi", + "integral", + "ordfeminine", + "ordmasculine", + "Omega", + "ae", + "oslash", + "questiondown", + "exclamdown", + "logicalnot", + "radical", + "florin", + "approxequal", + "Delta", + "guillemotleft", + "guillemotright", + "ellipsis", + "nonbreakingspace", + "Agrave", + "Atilde", + "Otilde", + "OE", + "oe", + "endash", + "emdash", + "quotedblleft", + "quotedblright", + "quoteleft", + "quoteright", + "divide", + "lozenge", + "ydieresis", + "Ydieresis", + "fraction", + "currency", + "guilsinglleft", + "guilsinglright", + "fi", + "fl", + "daggerdbl", + "periodcentered", + "quotesinglbase", + "quotedblbase", + "perthousand", + "Acircumflex", + "Ecircumflex", + "Aacute", + "Edieresis", + "Egrave", + "Iacute", + "Icircumflex", + "Idieresis", + "Igrave", + "Oacute", + "Ocircumflex", + "apple", + "Ograve", + "Uacute", + "Ucircumflex", + "Ugrave", + "dotlessi", + "circumflex", + "tilde", + "macron", + "breve", + "dotaccent", + "ring", + "cedilla", + "hungarumlaut", + "ogonek", + "caron", + "Lslash", + "lslash", + "Scaron", + "scaron", + "Zcaron", + "zcaron", + "brokenbar", + "Eth", + "eth", + "Yacute", + "yacute", + "Thorn", + "thorn", + "minus", + "multiply", + "onesuperior", + "twosuperior", + "threesuperior", + "onehalf", + "onequarter", + "threequarters", + "franc", + "Gbreve", + "gbreve", + "Idotaccent", + "Scedilla", + "scedilla", + "Cacute", + "cacute", + "Ccaron", + "ccaron", + "dcroat" + }; + + + + bool PostTable::usable() const { - m_errorMsg = "no post table"; - m_usable = false; - return; + return m_usable; } - postData.resize(size); - error = FT_Load_Sfnt_Table ( face, TTAG_post , 0, reinterpret_cast(postData.data()), &size ); - if (error) + + void PostTable::setUsable(bool usable) { - m_errorMsg = "can't load post table"; - m_usable = false; - return; + m_usable = usable; } - - switch (sfnt::word(postData, ttf_post_format)) + + QString PostTable::errorMsg() const { - case sfnt::post_format10: - m_usable = true; - m_names.clear(); - return; - case sfnt::post_format20: - break; - case sfnt::post_format30: - m_errorMsg = QString("post table has no glyph names"); - m_usable = false; - return; - case sfnt::post_format25: - case sfnt::post_format40: - default: - m_errorMsg = QString("unsupported post format %1").arg(sfnt::word(postData,0)); - m_usable = false; - return; - + return m_errorMsg; } - QMap usedNames; - QList pascalStrings; - - uint nrOfGlyphs = sfnt::word16(postData, ttf_post_header_length); - uint stringPos = ttf_post_header_length + 2 + 2 * nrOfGlyphs; - while (stringPos < (uint) postData.length()) + + void PostTable::setErrorMsg(const QString& errorMsg) { - int strLen = byte(postData, stringPos); - ++stringPos; - pascalStrings.append(postData.mid(stringPos, strLen)); - stringPos += strLen; + m_errorMsg = errorMsg; } - uint pos = ttf_post_header_length + 2; - for (uint gid = 0; gid < nrOfGlyphs; ++gid) + + uint PostTable::numberOfGlyphs() const { - uint nameIndex = sfnt::word16(postData, pos); - pos += 2; - QString name; - if (nameIndex < sfnt::post_format10_names_count) - name = sfnt::post_format10_names[nameIndex]; - else if (nameIndex < pascalStrings.length() + sfnt::post_format10_names_count) - name = pascalStrings[nameIndex - sfnt::post_format10_names_count]; - else { + if (m_names.length() > 0) + return m_names.length(); + return post_format10_names_count; + } + + QString PostTable::nameFor(uint glyph) const + { + if (glyph < (uint) m_names.length()) + return m_names[glyph]; + if (glyph < sfnt::post_format10_names_count) + return post_format10_names[glyph]; + return ".notdef"; + } + + + void PostTable::readFrom(FT_Face face) + { + QByteArray postData; + FT_ULong size = 0; + int error = FT_Load_Sfnt_Table ( face, TTAG_post , 0, nullptr, &size ); + //qDebug() << "load post" << error << size; + if (error || size == 0) + { + m_errorMsg = "no post table"; m_usable = false; - m_errorMsg = QString("missing name %1 for glyph %2").arg(nameIndex).arg(gid); return; } - if (name != ".notdef" && name[0] != QChar(0) && usedNames.contains(name)) + postData.resize(size); + error = FT_Load_Sfnt_Table ( face, TTAG_post , 0, reinterpret_cast(postData.data()), &size ); + if (error) { + m_errorMsg = "can't load post table"; m_usable = false; - m_errorMsg = QString("duplicate name %1 used for glyphs %2 and %3").arg(name).arg(gid).arg(usedNames[name]); return; } - usedNames[name] = gid; - m_names.append(name); + + switch (sfnt::word(postData, ttf_post_format)) + { + case sfnt::post_format10: + m_usable = true; + m_names.clear(); + return; + case sfnt::post_format20: + break; + case sfnt::post_format30: + m_errorMsg = QString("post table has no glyph names"); + m_usable = false; + return; + case sfnt::post_format25: + case sfnt::post_format40: + default: + m_errorMsg = QString("unsupported post format %1").arg(sfnt::word(postData,0)); + m_usable = false; + return; + + } + QMap usedNames; + QList pascalStrings; + + uint nrOfGlyphs = sfnt::word16(postData, ttf_post_header_length); + uint stringPos = ttf_post_header_length + 2 + 2 * nrOfGlyphs; + while (stringPos < (uint) postData.length()) + { + int strLen = byte(postData, stringPos); + ++stringPos; + pascalStrings.append(postData.mid(stringPos, strLen)); + stringPos += strLen; + } + uint pos = ttf_post_header_length + 2; + for (uint gid = 0; gid < nrOfGlyphs; ++gid) + { + uint nameIndex = sfnt::word16(postData, pos); + pos += 2; + QString name; + if (nameIndex < sfnt::post_format10_names_count) + name = sfnt::post_format10_names[nameIndex]; + else if (nameIndex < pascalStrings.length() + sfnt::post_format10_names_count) + name = pascalStrings[nameIndex - sfnt::post_format10_names_count]; + else { + m_usable = false; + m_errorMsg = QString("missing name %1 for glyph %2").arg(nameIndex).arg(gid); + return; + } + if (name != ".notdef" && name[0] != QChar(0) && usedNames.contains(name)) + { + m_usable = false; + m_errorMsg = QString("duplicate name %1 used for glyphs %2 and %3").arg(name).arg(gid).arg(usedNames[name]); + return; + } + usedNames[name] = gid; + m_names.append(name); + } + m_errorMsg = ""; + m_usable = true; } - m_errorMsg = ""; - m_usable = true; -} @@ -446,65 +446,64 @@ void PostTable::readFrom(FT_Face face) } -QByteArray extractFace(const QByteArray& coll, int faceIndex) -{ - QByteArray result; - - const int numFonts = word(coll, ttc_numFonts); - if (faceIndex >= static_cast(numFonts)) + QByteArray extractFace(const QByteArray& coll, int faceIndex) { - return result; - } + QByteArray result; - uint faceOffset = sfnt::word(coll, ttc_OffsetTables + 4 * faceIndex); - uint nTables = sfnt::word16(coll, faceOffset + ttf_numtables); - - //qDebug() << QObject::tr("extracting face %1 from font %2 (offset=%3, nTables=%4)").arg(faceIndex).arg("collection").arg(faceOffset).arg(nTables); - - uint headerLength = ttf_TableRecords + ttf_TableRecord_Size * nTables; - - uint tableLengths = 0; - // sum table lengths incl padding - for (uint i=0; i < nTables; ++i) - { - tableLengths += sfnt::word(coll, faceOffset + ttf_TableRecords + ttf_TableRecord_Size * i + ttf_TableRecord_length); - tableLengths = (tableLengths+3) & ~3; - } - result.resize(headerLength + tableLengths); - if (!result.data()) - { - result.resize(0); - return result; - } - - // write header - // sDebug(QObject::tr("memcpy header: %1 %2 %3").arg(0).arg(faceOffset).arg(headerLength)); - if (!copy(result, 0, coll, faceOffset, headerLength)) - { - result.resize(0); - return result; - } - uint pos = headerLength; - for (uint i=0; i < nTables; ++i) - { - uint sourceDirEntry = faceOffset + ttf_TableRecords + ttf_TableRecord_Size * i; - uint destDirEntry = ttf_TableRecords + ttf_TableRecord_Size * i; - - int tableSize = copyTable(result, destDirEntry, pos, coll, sourceDirEntry); - if (tableSize < 0) + const int numFonts = word(coll, ttc_numFonts); + if (faceIndex >= static_cast(numFonts)) + { + return result; + } + + uint faceOffset = sfnt::word(coll, ttc_OffsetTables + 4 * faceIndex); + uint nTables = sfnt::word16(coll, faceOffset + ttf_numtables); + + //qDebug() << QObject::tr("extracting face %1 from font %2 (offset=%3, nTables=%4)").arg(faceIndex).arg("collection").arg(faceOffset).arg(nTables); + + uint headerLength = ttf_TableRecords + ttf_TableRecord_Size * nTables; + + uint tableLengths = 0; + // sum table lengths incl padding + for (uint i=0; i < nTables; ++i) + { + tableLengths += sfnt::word(coll, faceOffset + ttf_TableRecords + ttf_TableRecord_Size * i + ttf_TableRecord_length); + tableLengths = (tableLengths+3) & ~3; + } + result.resize(headerLength + tableLengths); + if (!result.data()) { result.resize(0); return result; } - pos += tableSize; - // pad - while ((pos & 3) != 0) - result.data()[pos++] = '\0'; - } - return result; -} + // write header + // sDebug(QObject::tr("memcpy header: %1 %2 %3").arg(0).arg(faceOffset).arg(headerLength)); + if (!copy(result, 0, coll, faceOffset, headerLength)) + { + result.resize(0); + return result; + } + uint pos = headerLength; + for (uint i=0; i < nTables; ++i) + { + uint sourceDirEntry = faceOffset + ttf_TableRecords + ttf_TableRecord_Size * i; + uint destDirEntry = ttf_TableRecords + ttf_TableRecord_Size * i; + int tableSize = copyTable(result, destDirEntry, pos, coll, sourceDirEntry); + if (tableSize < 0) + { + result.resize(0); + return result; + } + pos += tableSize; + + // pad + while ((pos & 3) != 0) + result.data()[pos++] = '\0'; + } + return result; + } uint getTableDirEntry(const QByteArray& ttf, const QByteArray& ttfTag) { @@ -521,8 +520,7 @@ QByteArray extractFace(const QByteArray& coll, int faceIndex) return 0; } - - const QByteArray getTable(const QByteArray& ttf, const QByteArray& ttfTag) + QByteArray getTable(const QByteArray& ttf, const QByteArray& ttfTag) { uint pos = getTableDirEntry(ttf, ttfTag); if (pos <= 0) @@ -593,7 +591,7 @@ QByteArray extractFace(const QByteArray& coll, int faceIndex) { const QByteArray head = getTable(ttf, "head"); uint idxToLocFormat = word16(head, ttf_head_indexToLocFormat); -// qDebug() << "loca format:" << (void*)idxToLocFormat; + // qDebug() << "loca format:" << (void*)idxToLocFormat; return idxToLocFormat == 1; } @@ -619,7 +617,7 @@ QByteArray extractFace(const QByteArray& coll, int faceIndex) return result; } - const QByteArray writeLoca(const QList& loca, bool longFormat) + QByteArray writeLoca(const QList& loca, bool longFormat) { QByteArray result; if (longFormat) @@ -724,91 +722,91 @@ QByteArray extractFace(const QByteArray& coll, int faceIndex) switch (format) { case 4: - { - uint segCount2 = word16(cmaps, startOfUnicodeTable + ttf_cmap4_segCountX2); - uint endCodes = startOfUnicodeTable + ttf_cmap4_EndCodes; - uint startCodes = endCodes + segCount2 + ttf_cmap4_StartCodes_EndCodes; - uint idDeltas = startCodes + segCount2 + ttf_cmap4_IdDeltas_StartCodes; - uint idRangeOffsets = idDeltas + segCount2 + ttf_cmap4_IdRangeOffsets_IdDeltas; - //uint glyphIndexArray = idRangeOffsets + segCount2 + ttf_cmap4_GlyphIds_IdRangeOffsets; - - for (uint seg = 0; seg < segCount2; seg+=2) { - uint start = word16(cmaps, startCodes + seg); - uint end = word16(cmaps, endCodes + seg); - uint idDelta = word16(cmaps, idDeltas + seg); - uint idRangeOffset = word16(cmaps, idRangeOffsets + seg); - for (uint c = start; c <= end; ++c) + uint segCount2 = word16(cmaps, startOfUnicodeTable + ttf_cmap4_segCountX2); + uint endCodes = startOfUnicodeTable + ttf_cmap4_EndCodes; + uint startCodes = endCodes + segCount2 + ttf_cmap4_StartCodes_EndCodes; + uint idDeltas = startCodes + segCount2 + ttf_cmap4_IdDeltas_StartCodes; + uint idRangeOffsets = idDeltas + segCount2 + ttf_cmap4_IdRangeOffsets_IdDeltas; + //uint glyphIndexArray = idRangeOffsets + segCount2 + ttf_cmap4_GlyphIds_IdRangeOffsets; + + for (uint seg = 0; seg < segCount2; seg+=2) { - quint16 glyph; - if (idRangeOffset > 0) + uint start = word16(cmaps, startCodes + seg); + uint end = word16(cmaps, endCodes + seg); + uint idDelta = word16(cmaps, idDeltas + seg); + uint idRangeOffset = word16(cmaps, idRangeOffsets + seg); + for (uint c = start; c <= end; ++c) { - uint glyphIndexAdress = idRangeOffset + 2*(c-start) + (idRangeOffsets + seg); - glyph = word16(cmaps, glyphIndexAdress); - if (glyph != 0) - glyph += idDelta; - } - else - { - glyph = c + idDelta; - } - if (!result.contains(c)) - { - // search would always find the one in the segment with the lower endcode, i.e. earlier segment - if (c < 256 || glyph == 0) - //qDebug() << "(" << QChar(c) << "," << glyph << ")"; - result[c] = glyph; - } - else - { - // nothing to do. No idea if fonts with overlapping cmap4 segments exist, though. + quint16 glyph; + if (idRangeOffset > 0) + { + uint glyphIndexAdress = idRangeOffset + 2*(c-start) + (idRangeOffsets + seg); + glyph = word16(cmaps, glyphIndexAdress); + if (glyph != 0) + glyph += idDelta; + } + else + { + glyph = c + idDelta; + } + if (!result.contains(c)) + { + // search would always find the one in the segment with the lower endcode, i.e. earlier segment + if (c < 256 || glyph == 0) + //qDebug() << "(" << QChar(c) << "," << glyph << ")"; + result[c] = glyph; + } + else + { + // nothing to do. No idea if fonts with overlapping cmap4 segments exist, though. + } } } + break; } - break; - } case 6: - { - uint firstCode = word16(cmaps, startOfUnicodeTable + ttf_cmap6_firstCode); - uint count = word16(cmaps, startOfUnicodeTable + ttf_cmap6_entryCount); - pos = word16(cmaps, startOfUnicodeTable + ttf_cmap6_glyphIndexArray); - for (uint i = 0; i < count; ++i) { - result[firstCode + i] = word16(cmaps, pos); - pos += 2; + uint firstCode = word16(cmaps, startOfUnicodeTable + ttf_cmap6_firstCode); + uint count = word16(cmaps, startOfUnicodeTable + ttf_cmap6_entryCount); + pos = word16(cmaps, startOfUnicodeTable + ttf_cmap6_glyphIndexArray); + for (uint i = 0; i < count; ++i) + { + result[firstCode + i] = word16(cmaps, pos); + pos += 2; + } + break; } - break; - } case 12: - { - uint nGroups = word(cmaps, startOfUnicodeTable + ttf_cmap12_nGroups); - pos = startOfUnicodeTable + ttf_cmap12_Groups; - for (uint grp = 0; grp < nGroups; ++grp) { - uint start = word(cmaps, pos + ttf_cmap12_Group_startCharCode); - uint end = word(cmaps, pos + ttf_cmap12_Group_endCharCode); - uint gid = word(cmaps, pos + ttf_cmap12_Group_startGlyphCode); - for (uint c = start; c <= end; ++c) + uint nGroups = word(cmaps, startOfUnicodeTable + ttf_cmap12_nGroups); + pos = startOfUnicodeTable + ttf_cmap12_Groups; + for (uint grp = 0; grp < nGroups; ++grp) { - result[c] = gid; - ++gid; + uint start = word(cmaps, pos + ttf_cmap12_Group_startCharCode); + uint end = word(cmaps, pos + ttf_cmap12_Group_endCharCode); + uint gid = word(cmaps, pos + ttf_cmap12_Group_startGlyphCode); + for (uint c = start; c <= end; ++c) + { + result[c] = gid; + ++gid; + } + pos += ttf_cmap12_Group_Size; } - pos += ttf_cmap12_Group_Size; + break; } - break; - } default: - { - qDebug() << "unsupported cmap format" << format; - break; - } + { + qDebug() << "unsupported cmap format" << format; + break; + } } return result; } - const QByteArray writeCMap(const QMap& cmap) + QByteArray writeCMap(const QMap& cmap) { // we always write only one table: platform=3(MS), encoding=1(Unicode 16bit) QByteArray result; @@ -833,7 +831,7 @@ QByteArray extractFace(const QByteArray& coll, int faceIndex) chars.append(ch); cmapHasData = true; } -// qDebug() << QChar(ch) << QChar::requiresSurrogates(ch) << cit.value(); + // qDebug() << QChar(ch) << QChar::requiresSurrogates(ch) << cit.value(); } std::sort(chars.begin(), chars.end()); @@ -947,11 +945,11 @@ QByteArray extractFace(const QByteArray& coll, int faceIndex) putWord16(result, startOfTable + ttf_cmap4_length, result.size() - startOfTable); return result; - } + } QList copyGlyphComponents(QByteArray& destGlyf, const QByteArray& srcGlyf, uint srcOffset, - QMap& newForOldGid, uint& nextFreeGid) + QMap& newForOldGid, uint& nextFreeGid) { QList result; @@ -1010,7 +1008,7 @@ QByteArray extractFace(const QByteArray& coll, int faceIndex) pos += 2; } } while ( flags & ttf_glyf_ComponentFlag_MORE_COMPONENTS ); - + if (haveInstructions) { uint numInstr = word16(srcGlyf, pos); @@ -1026,8 +1024,8 @@ QByteArray extractFace(const QByteArray& coll, int faceIndex) QList copyGlyph(QList& destLoca, QByteArray& destGlyf, uint destGid, - const QList& srcLoca, const QByteArray& srcGlyf, uint srcGid, - QMap& newForOldGid, uint& nextFreeGid) + const QList& srcLoca, const QByteArray& srcGlyf, uint srcGid, + QMap& newForOldGid, uint& nextFreeGid) { QList compositeElements; uint glyphStart = srcLoca[srcGid]; @@ -1071,7 +1069,7 @@ QByteArray extractFace(const QByteArray& coll, int faceIndex) QMap tables; -// qDebug() << "loca table:" << (void*) oldLoca[0] << (void*) oldLoca[1] << (void*) oldLoca[2] << (void*) oldLoca[3] << (void*) oldLoca[4] << (void*) oldLoca[5] << (void*) oldLoca[6] << (void*) oldLoca[7]; + // qDebug() << "loca table:" << (void*) oldLoca[0] << (void*) oldLoca[1] << (void*) oldLoca[2] << (void*) oldLoca[3] << (void*) oldLoca[4] << (void*) oldLoca[5] << (void*) oldLoca[6] << (void*) oldLoca[7]; QMap newForOldGid; @@ -1101,8 +1099,8 @@ QByteArray extractFace(const QByteArray& coll, int faceIndex) { uint oldGid = glyphs[i]; glyphs.append(copyGlyph(newLoca, newGlyf, i, - oldLoca, oldGlyf, oldGid, - newForOldGid, nextFreeGid)); + oldLoca, oldGlyf, oldGid, + newForOldGid, nextFreeGid)); } newLoca.append(newGlyf.length()); diff --git a/scribus/fonts/sfnt.h b/scribus/fonts/sfnt.h index 2c5e4f01b..6f36f07db 100644 --- a/scribus/fonts/sfnt.h +++ b/scribus/fonts/sfnt.h @@ -31,8 +31,8 @@ namespace sfnt void putWord16(QByteArray & bb, uint pos, quint16 val); void appendWord16(QByteArray& bb, quint16 val); bool copy(QByteArray & dst, uint to, const QByteArray & src, uint from, uint len); - const QByteArray tag(QByteArray const & bb, uint pos); - const QByteArray getTable(const QByteArray& ttf, const QByteArray& ttfTag); + QByteArray tag(QByteArray const & bb, uint pos); + QByteArray getTable(const QByteArray& ttf, const QByteArray& ttfTag); QByteArray subsetFace(const QByteArray& ttf, QList& glyphs); diff --git a/scribus/imagedataloaders/scimgdataloader_ps.cpp b/scribus/imagedataloaders/scimgdataloader_ps.cpp index 99184cf7c..c7c75a4f5 100644 --- a/scribus/imagedataloaders/scimgdataloader_ps.cpp +++ b/scribus/imagedataloaders/scimgdataloader_ps.cpp @@ -671,7 +671,6 @@ bool ScImgDataLoader_PS::loadPicture(const QString& fn, int page, int gsRes, boo { m_image.load(tmpFile); x = 0; - y = 0; b = m_image.width() / gsRes * 72.0; h = m_image.height() / gsRes * 72.0; } @@ -904,7 +903,6 @@ void ScImgDataLoader_PS::decodeA85(QByteArray &psdata, const QString& tmp) psdata.resize(psdata.size()+1); psdata[psdata.size()-1] = data; } - quintet = 0; } break; } diff --git a/scribus/imagedataloaders/scimgdataloader_tiff.cpp b/scribus/imagedataloaders/scimgdataloader_tiff.cpp index f78ee311f..977863e44 100644 --- a/scribus/imagedataloaders/scimgdataloader_tiff.cpp +++ b/scribus/imagedataloaders/scimgdataloader_tiff.cpp @@ -1354,7 +1354,7 @@ bool ScImgDataLoader_TIFF::loadLayerChannels( QDataStream & s, const PSDHeader & return false; } channel_num = qMin(channel_num, (uint) 39); - uint components[40]; + uint components[40] = {0}; for (uint channel = 0; channel < channel_num; channel++) { switch (layerInfo[layer].channelType[channel]) diff --git a/scribus/langmgr.cpp b/scribus/langmgr.cpp index e86e00a5a..6bc9601c9 100644 --- a/scribus/langmgr.cpp +++ b/scribus/langmgr.cpp @@ -747,7 +747,7 @@ int LanguageManager::langTableIndex(const QString &abbrev) return -1; } -const QString LanguageManager::getLangFromAbbrev(QString langAbbrev, bool getTranslated) +QString LanguageManager::getLangFromAbbrev(QString langAbbrev, bool getTranslated) { // qDebug()<<"Trying to find:"<= 0) @@ -845,7 +845,7 @@ const QString LanguageManager::getShortAbbrevFromAbbrevDecomposition(const QStri return ""; } -const QString LanguageManager::getAlternativeAbbrevfromAbbrev(const QString& langAbbrev) +QString LanguageManager::getAlternativeAbbrevfromAbbrev(const QString& langAbbrev) { int i=langTableIndex(langAbbrev); if (i != -1) @@ -1138,7 +1138,7 @@ LanguageManager::~LanguageManager() m_langTable.clear(); } -const QString LanguageManager::getHyphFilename(const QString & langAbbrev) +QString LanguageManager::getHyphFilename(const QString & langAbbrev) { int j = langTableIndex(langAbbrev); if (j != -1 && m_langTable[j].m_hyphAvailable) diff --git a/scribus/langmgr.h b/scribus/langmgr.h index f1e225939..37c03b642 100644 --- a/scribus/langmgr.h +++ b/scribus/langmgr.h @@ -46,13 +46,13 @@ class SCRIBUS_API LanguageManager void languageChange(); QStringList languageList(bool getTranslated=true); - const QString getLangFromAbbrev(QString, bool getTranslated=true); - const QString getAbbrevFromLang(const QString&, bool useInstalled=true); - const QString getLangFromTransLang(const QString& transLang); - const QString getTransLangFromLang(const QString& lang); - const QString getShortAbbrevFromAbbrev(QString langAbbrev); - const QString getShortAbbrevFromAbbrevDecomposition(const QString& langAbbrev); - const QString getAlternativeAbbrevfromAbbrev(const QString& langAbbrev); + QString getLangFromAbbrev(QString, bool getTranslated=true); + QString getAbbrevFromLang(const QString&, bool useInstalled=true); + QString getLangFromTransLang(const QString& transLang); + QString getTransLangFromLang(const QString& lang); + QString getShortAbbrevFromAbbrev(QString langAbbrev); + QString getShortAbbrevFromAbbrevDecomposition(const QString& langAbbrev); + QString getAlternativeAbbrevfromAbbrev(const QString& langAbbrev); QStringList getAbbrevDecomposition(const QString& langAbbrev); void fillInstalledStringList(QStringList *stringListToFill); void fillInstalledGUIStringList(QStringList *stringListToFill); @@ -65,7 +65,7 @@ class SCRIBUS_API LanguageManager bool findHyphDictionaries(QStringList& sl); void findHyphDictionarySets(QStringList& dictionaryPaths, QMap& dictionaryMap); - const QString getHyphFilename(const QString& langAbbrev); + QString getHyphFilename(const QString& langAbbrev); int langTableIndex(const QString& abbrev); bool isAvailableTranslation(QString langAbbrev); diff --git a/scribus/loadsaveplugin.cpp b/scribus/loadsaveplugin.cpp index b7f83115d..41748dd72 100644 --- a/scribus/loadsaveplugin.cpp +++ b/scribus/loadsaveplugin.cpp @@ -57,17 +57,17 @@ FileFormat* LoadSavePlugin::getFormatByExt(const QString& ext) return &(*it); } -const QStringList LoadSavePlugin::fileDialogLoadFilter() +QStringList LoadSavePlugin::fileDialogLoadFilter() { return getDialogFilter(true); } -const QStringList LoadSavePlugin::fileDialogSaveFilter() +QStringList LoadSavePlugin::fileDialogSaveFilter() { return getDialogFilter(false); } -const QStringList LoadSavePlugin::getExtensionsForColors(const int id) +QStringList LoadSavePlugin::getExtensionsForColors(const int id) { QList::const_iterator it(findFormat(id)); QList::const_iterator itEnd(formats.constEnd()); @@ -103,7 +103,7 @@ const QStringList LoadSavePlugin::getExtensionsForColors(const int id) return filterList; } -const QStringList LoadSavePlugin::getExtensionsForImport(const int id) +QStringList LoadSavePlugin::getExtensionsForImport(const int id) { QList::const_iterator it(findFormat(id)); QList::const_iterator itEnd(formats.constEnd()); @@ -139,7 +139,7 @@ const QStringList LoadSavePlugin::getExtensionsForImport(const int id) return filterList; } -const QStringList LoadSavePlugin::getExtensionsForPreview(const int id) +QStringList LoadSavePlugin::getExtensionsForPreview(const int id) { QList::const_iterator it(findFormat(id)); QList::const_iterator itEnd(formats.constEnd()); diff --git a/scribus/loadsaveplugin.h b/scribus/loadsaveplugin.h index 7ae6e082c..1ffcde358 100644 --- a/scribus/loadsaveplugin.h +++ b/scribus/loadsaveplugin.h @@ -56,19 +56,19 @@ class SCRIBUS_API LoadSavePlugin : public ScPlugin // Static functions: // Return a list of file extensions - static const QStringList getExtensionsForColors(const int id = 47); + static QStringList getExtensionsForColors(const int id = 47); // Return a list of file extensions - static const QStringList getExtensionsForImport(const int id = 47); + static QStringList getExtensionsForImport(const int id = 47); // Return a list of file extensions - static const QStringList getExtensionsForPreview(const int id = 47); + static QStringList getExtensionsForPreview(const int id = 47); // Return a list of format descriptions suitable for use with // QFileDialog. You can convert it to QString form with // fileDialogSaveFilter().join(";;") - static const QStringList fileDialogLoadFilter(); + static QStringList fileDialogLoadFilter(); // Same deal but for save - static const QStringList fileDialogSaveFilter(); + static QStringList fileDialogSaveFilter(); // Get the highest priority format of a given id, or 0 if // not found / not available. diff --git a/scribus/marks.cpp b/scribus/marks.cpp index 1854f8e99..73353378c 100644 --- a/scribus/marks.cpp +++ b/scribus/marks.cpp @@ -46,7 +46,7 @@ void Mark::setMark(const QString& l, MarkType t) m_data.destmarkType = t; } -const QString Mark::getString() const +QString Mark::getString() const { return m_data.strtxt; } diff --git a/scribus/marks.h b/scribus/marks.h index c05ebdd34..c6de42a4b 100644 --- a/scribus/marks.h +++ b/scribus/marks.h @@ -69,7 +69,7 @@ class SCRIBUS_API Mark void setMark(const QString& l, MarkType t); MarkType getMarkType() const { return m_data.markType; } void setMarkType(MarkType t) { m_data.markType = t; } - const QString getString() const; + QString getString() const; void setString(const QString& str ); TextNote* getNotePtr() const { return m_data.notePtr; } void setNotePtr(TextNote *note); diff --git a/scribus/openpalettemanager.h b/scribus/openpalettemanager.h index 188f57a30..9bfe68219 100644 --- a/scribus/openpalettemanager.h +++ b/scribus/openpalettemanager.h @@ -60,7 +60,7 @@ class OpenPaletteManager : public QObject /** * create a new OpenPalette */ - static void newPalette(QWidget * parent = 0); + static void newPalette(QWidget* parent = nullptr); /** * Return number of palettes diff --git a/scribus/pageitem.cpp b/scribus/pageitem.cpp index b054d08c9..9d0f57713 100644 --- a/scribus/pageitem.cpp +++ b/scribus/pageitem.cpp @@ -1324,9 +1324,7 @@ bool PageItem::canBeLinkedTo(const PageItem* nxt) const } // If object is placed on a master page, it can be linked only to objects placed on same master page // Same for objects placed on standard pages : they can only be linked to objects placed on standard pages - if (OnMasterPage != nxt->OnMasterPage) - return false; - return true; + return OnMasterPage == nxt->OnMasterPage; } void PageItem::link(PageItem* nxt, bool addPARSEP) diff --git a/scribus/pageitemsettersmanager.h b/scribus/pageitemsettersmanager.h index ac7a887eb..44e0d21e6 100644 --- a/scribus/pageitemsettersmanager.h +++ b/scribus/pageitemsettersmanager.h @@ -41,7 +41,7 @@ class PageItemSettersManager : public QObject static PageItemSettersManager * instance; static PageItemSettersManager * that(); - PageItemSettersManager(QObject * parent = 0); + PageItemSettersManager(QObject* parent = nullptr); QList setters; Selection * selection; diff --git a/scribus/pluginmanager.cpp b/scribus/pluginmanager.cpp index 92bcfebc6..6c7e4c154 100644 --- a/scribus/pluginmanager.cpp +++ b/scribus/pluginmanager.cpp @@ -681,7 +681,7 @@ PluginManager & PluginManager::instance() return (*ScCore->pluginManager); } -const QString PluginManager::getPluginPath(const QString & pluginName) const +QString PluginManager::getPluginPath(const QString & pluginName) const { // It is not legal to call this function without a valid // plug in name. diff --git a/scribus/pluginmanager.h b/scribus/pluginmanager.h index 87b61e752..b17a044f6 100644 --- a/scribus/pluginmanager.h +++ b/scribus/pluginmanager.h @@ -111,7 +111,7 @@ class SCRIBUS_API PluginManager : public QObject /*! \brief Return the path to the file for the named plugin. An invalid plugin name is an error.*/ - const QString getPluginPath(const QString & pluginName) const; + QString getPluginPath(const QString & pluginName) const; /*! \brief Whether the given plug-in will be enabled on start-up. Usable as an lvalue. An invalid plugin name is an error. */ diff --git a/scribus/plugins/barcodegenerator/barcodegenerator.h b/scribus/plugins/barcodegenerator/barcodegenerator.h index 8965735d6..2e9d71340 100644 --- a/scribus/plugins/barcodegenerator/barcodegenerator.h +++ b/scribus/plugins/barcodegenerator/barcodegenerator.h @@ -63,7 +63,7 @@ class BarcodeGenerator : public QDialog /*! \brief Create modal BC dialog. \param parent Parent of the dialog. \param name name od the QObject to debug */ - BarcodeGenerator(QWidget* parent = 0, const char* name = 0); + BarcodeGenerator(QWidget* parent = nullptr, const char* name = 0); //! \brief Erase the temporary files here. ~BarcodeGenerator(); diff --git a/scribus/plugins/barcodegenerator/barcodegeneratorrenderthread.h b/scribus/plugins/barcodegenerator/barcodegeneratorrenderthread.h index ad385bb87..f95674c4f 100644 --- a/scribus/plugins/barcodegenerator/barcodegeneratorrenderthread.h +++ b/scribus/plugins/barcodegenerator/barcodegeneratorrenderthread.h @@ -18,7 +18,7 @@ class BarcodeGeneratorRenderThread : public QThread Q_OBJECT public: - BarcodeGeneratorRenderThread(QObject *parent = 0); + BarcodeGeneratorRenderThread(QObject* parent = nullptr); ~BarcodeGeneratorRenderThread(); void render(const QString&); diff --git a/scribus/plugins/gettext/csvim/csvim.cpp b/scribus/plugins/gettext/csvim/csvim.cpp index c14f242d5..0e0bd9fa6 100644 --- a/scribus/plugins/gettext/csvim/csvim.cpp +++ b/scribus/plugins/gettext/csvim/csvim.cpp @@ -35,21 +35,16 @@ void GetText(const QString& filename, const QString& encoding, bool /* textOnly /******* Class CsvIm **************************************************************/ -CsvIm::CsvIm(const QString& fname, const QString& enc, gtWriter *w, - const QString& fdelim, const QString& vdelim, bool hasheader, bool usevdelim) +CsvIm::CsvIm(const QString& fname, const QString& enc, gtWriter *w, + const QString& fdelim, const QString& vdelim, bool hasheader, bool usevdelim) : + fieldDelimiter(fdelim), + valueDelimiter(vdelim), + hasHeader(hasheader), + useVDelim(usevdelim), + filename(fname), + encoding(enc), + writer(w) { - fieldDelimiter = fdelim; - valueDelimiter = vdelim; - hasHeader = hasheader; - useVDelim = usevdelim; - filename = fname; - encoding = enc; - writer = w; - header = ""; - data = ""; - rowNumber = 0; - colIndex = 0; - colCount = 0; setupPStyles(); loadFile(); setupTabulators(); @@ -59,18 +54,15 @@ void CsvIm::setupPStyles() { pstyleData = new gtParagraphStyle(*(writer->getDefaultStyle())); pstyleData->setName(writer->getFrameName() + "-" + QObject::tr("CSV_data")); - if (hasHeader) - { - pstyleHeader = new gtParagraphStyle(*pstyleData); - pstyleHeader->setName(writer->getFrameName() + "-" + QObject::tr("CSV_header")); - pstyleHeader->setSpaceBelow(7.0); - int size = pstyleData->getFont()->getSize(); - size += 10; - pstyleHeader->getFont()->setSize(size); - pstyleHeader->getFont()->setWeight(BOLD); - } - else - pstyleHeader = nullptr; + if (!hasHeader) + return; + pstyleHeader = new gtParagraphStyle(*pstyleData); + pstyleHeader->setName(writer->getFrameName() + "-" + QObject::tr("CSV_header")); + pstyleHeader->setSpaceBelow(7.0); + int size = pstyleData->getFont()->getSize(); + size += 10; + pstyleHeader->getFont()->setSize(size); + pstyleHeader->getFont()->setWeight(BOLD); } void CsvIm::setFieldDelimiter(const QString& fdelim) diff --git a/scribus/plugins/gettext/csvim/csvim.h b/scribus/plugins/gettext/csvim/csvim.h index 69dce27c7..23eec33ca 100644 --- a/scribus/plugins/gettext/csvim/csvim.h +++ b/scribus/plugins/gettext/csvim/csvim.h @@ -43,14 +43,15 @@ class CsvIm bool useVDelim { true }; QString filename; QString encoding; - gtWriter *writer { nullptr }; + gtWriter *writer {nullptr}; + QString header; QString data; - int rowNumber { 0 }; - int colIndex { 0 }; - int colCount { 0 }; - gtParagraphStyle *pstyleData { nullptr }; - gtParagraphStyle *pstyleHeader { nullptr }; + int rowNumber {0}; + int colIndex {0}; + int colCount {0}; + gtParagraphStyle *pstyleData {nullptr}; + gtParagraphStyle *pstyleHeader {nullptr}; void loadFile(); void parseLine(const QString& line, bool isHeader); diff --git a/scribus/plugins/gettext/textfilter/tffilter.h b/scribus/plugins/gettext/textfilter/tffilter.h index 3f008b624..ae1a4ba6f 100644 --- a/scribus/plugins/gettext/textfilter/tffilter.h +++ b/scribus/plugins/gettext/textfilter/tffilter.h @@ -76,7 +76,7 @@ class tfFilter : public QWidget tfFilter(QWidget *parent, const char *name, int action, const QString& regExp, const QString& replace, const QString& pstyleName, int less, int more, int style, bool match, bool enabled, bool regexp); - tfFilter(QWidget *parent = 0, const char *name = 0); + tfFilter(QWidget* parent = nullptr, const char *name = 0); ~tfFilter(); void setRemovable(bool b); int getAction(); diff --git a/scribus/plugins/import/pdf/CMakeLists.txt b/scribus/plugins/import/pdf/CMakeLists.txt index 85760d96e..1ee6cf74e 100644 --- a/scribus/plugins/import/pdf/CMakeLists.txt +++ b/scribus/plugins/import/pdf/CMakeLists.txt @@ -20,6 +20,7 @@ set(IMPORTPDF_PLUGIN_SOURCES importpdfplugin.cpp pdfimportoptions.cpp slaoutput.cpp + pdftextrecognition.cpp ) if(HAVE_POPPLER) diff --git a/scribus/plugins/import/pdf/pdfimportoptions.h b/scribus/plugins/import/pdf/pdfimportoptions.h index 493dd6791..9c5e4d02c 100644 --- a/scribus/plugins/import/pdf/pdfimportoptions.h +++ b/scribus/plugins/import/pdf/pdfimportoptions.h @@ -19,7 +19,7 @@ class PdfImportOptions : public QDialog Q_OBJECT public: - explicit PdfImportOptions(QWidget *parent = 0); + explicit PdfImportOptions(QWidget* parent = nullptr); ~PdfImportOptions(); void setUpOptions(const QString& fileName, int actPage, int numPages, bool interact, bool cropPossible, PdfPlug* plug); QString getPagesString(); diff --git a/scribus/plugins/import/pdf/pdftextrecognition.cpp b/scribus/plugins/import/pdf/pdftextrecognition.cpp new file mode 100644 index 000000000..bf8613821 --- /dev/null +++ b/scribus/plugins/import/pdf/pdftextrecognition.cpp @@ -0,0 +1,413 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ + +#include "pdftextrecognition.h" + +#ifndef DEBUG_TEXT_IMPORT + #define DEBUG_TEXT_IMPORT +#endif + +/* +* constructor, initialize the textRegions vector and set the addChar mode +*/ +PdfTextRecognition::PdfTextRecognition() +{ + m_textRegions.push_back(activeTextRegion); + setCharMode(AddCharMode::ADDFIRSTCHAR); +} + +/* +* nothing to do in the destructor yet +*/ +PdfTextRecognition::~PdfTextRecognition() +{ +} + +/* +* add a new text region and make it the active region +*/ +void PdfTextRecognition::addTextRegion() +{ + activeTextRegion = TextRegion(); + m_textRegions.push_back(activeTextRegion); + setCharMode(PdfTextRecognition::AddCharMode::ADDFIRSTCHAR); +} + +/* +* function called via integration with poppler's addChar callback. It decides how to add the charter based on the mode that is set +*/ +void PdfTextRecognition::addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, POPPLER_CONST_082 Unicode* u, int uLen) +{ + + switch (this->m_addCharMode) + { + case AddCharMode::ADDFIRSTCHAR: + AddFirstChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen); + break; + case AddCharMode::ADDBASICCHAR: + AddBasicChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen); + break; + case AddCharMode::ADDCHARWITHNEWSTYLE: + AddCharWithNewStyle(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen); + break; + case AddCharMode::ADDCHARWITHPREVIOUSSTYLE: + AddCharWithPreviousStyle(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen); + break; + } +} + +/* +* basic test to see if the point lies in a new line or region +*/ +bool PdfTextRecognition::isNewLineOrRegion(QPointF newPosition) +{ + return (activeTextRegion.collinear(activeTextRegion.lastXY.y(), activeTextRegion.textRegionLines.back().baseOrigin.y()) && + !activeTextRegion.collinear(newPosition.y(), activeTextRegion.lastXY.y())) + || (activeTextRegion.collinear(newPosition.y(), activeTextRegion.lastXY.y()) + && !activeTextRegion.isCloseToX(newPosition.x(), activeTextRegion.lastXY.x())); +} + + +/* +* basic functionality to be performed when addChar is called +* FIXME: what to do when uLen != 1 +*/ +PdfGlyph PdfTextRecognition::AddCharCommon(GfxState* state, double x, double y, double dx, double dy, Unicode const* u, int uLen) +{ + //qDebug() << "AddBasicChar() '" << u << " : " << uLen; + PdfGlyph newGlyph; + newGlyph.dx = dx; + newGlyph.dy = dy; + + // Convert the character to UTF-16 since that's our SVG document's encoding + + if (uLen > 1) + qDebug() << "FIXME: AddBasicChar() '" << u << " : " << uLen; + newGlyph.code = static_cast(u[uLen - 1]); + newGlyph.rise = state->getRise(); + return newGlyph; +} + +/* +* Tell the text region to add a glyph so that line segments and regions be created +* If the character being added is the first character in a textregion or after a change in positioning or styles or the end of a line +* The success == TextRegion::LineType::FAIL test is an invariant test that should never pass. if a rogue glyph is detected then it means there is a bug in the logic probably in TextRegion::addGlyphAtPoint or TextRegion::linearTest or TextRegion::moveToPoint +*/ +PdfGlyph PdfTextRecognition::AddFirstChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) +{ + //qDebug() << "AddFirstChar() '" << u << " : " << uLen; + PdfGlyph newGlyph = PdfTextRecognition::AddCharCommon(state, x, y, dx, dy, u, uLen); + activeTextRegion.glyphs.push_back(newGlyph); + setCharMode(AddCharMode::ADDBASICCHAR); + + //only need to be called for the very first point + auto success = activeTextRegion.addGlyphAtPoint(QPointF(x, y), newGlyph); + if (success == TextRegion::LineType::FAIL) + qDebug("FIXME: Rogue glyph detected, this should never happen because the cursor should move before glyphs in new regions are added."); + return newGlyph; +} + +/* +* just add a character to the textregion without doing anything special +*/ +PdfGlyph PdfTextRecognition::AddBasicChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) +{ + PdfGlyph newGlyph = AddCharCommon(state, x, y, dx, dy, u, uLen); + activeTextRegion.lastXY = QPointF(x, y); + activeTextRegion.glyphs.push_back(newGlyph); + return newGlyph; +} + +/* +* Apply a new style to this glyph ands glyphs that follow and add it to the style stack +* TODO: Currently not implemented, just stub code +*/ +PdfGlyph PdfTextRecognition::AddCharWithNewStyle(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) +{ + //qDebug() << "AddCharWithNewStyle() '" << u << " : " << uLen; + auto newGlyph = AddCharCommon(state, x, y, dx, dy, u, uLen); + activeTextRegion.glyphs.push_back(newGlyph); + return newGlyph; +} + +/* +* return to the previous style on the style stack +* TODO: Currently not implemented, just stub code +*/ +PdfGlyph PdfTextRecognition::AddCharWithPreviousStyle(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) +{ + //qDebug() << "AddCharWithPreviousStyle() '" << u << " : " << uLen; + auto newGlyph = AddCharCommon(state, x, y, dx, dy, u, uLen); + activeTextRegion.glyphs.push_back(newGlyph); + return newGlyph; +} + +/* +* functions to do fuzzy testing on the proximity of points to one another and in relation to the textregion +* FIXME: There should be a parameter in the UI to set the matching tolerance but hard code for now +*/ + +/* +* In geometry, collinearity of a set of points is the property of their lying on a single line. A set of points with this property is said to be collinear. +* In greater generality, the term has been used for aligned objects, that is, things being "in a line" or "in a row". +* PDF never deviates from the line when it comes to collinear, but allow for 1pixel of divergence +*/ +bool TextRegion::collinear(qreal a, qreal b) +{ + return abs(a - b) < 1 ? true : false; +} + +/* +* like collinear but we allow a deviation of 6 text widths from between positions or 1 text width from the textregion's x origin +* FIXME: This should use the char width not linespacing which is y +*/ +bool TextRegion::isCloseToX(qreal x1, qreal x2) +{ + + return (abs(x2 - x1) <= lineSpacing * 6) || (abs(x1 - this->textRegioBasenOrigin.x()) <= lineSpacing); +} + +/* +* like collinear but we allow a deviation of 3 text heights downwards but none upwards +*/ +bool TextRegion::isCloseToY(qreal y1, qreal y2) +{ + return (y2 - y1) >= 0 && y2 - y1 <= lineSpacing * 3; +} + +/* +* less than, page upwards, the last y value but bot more than the line spacing less, could also use the base line of the last line to be more accurate +*/ +bool TextRegion::adjunctLesser(qreal testY, qreal lastY, qreal baseY) +{ + return (testY > lastY + && testY <= baseY + lineSpacing + && lastY <= baseY + lineSpacing); +} + +/* +* greater, page downwards, than the last y value but not more than 3/4 of a line space below baseline +*/ +bool TextRegion::adjunctGreater(qreal testY, qreal lastY, qreal baseY) +{ + return (testY <= lastY + && testY >= baseY - lineSpacing * 0.75 + && lastY != baseY); +} + +/* +* Test to see if the point is part of the current block of text or is part of a new block of text(FrameworkLineTests::FAIL). +* checks to see if it's the first point, on the same line, super and sub script, returning to baseline from super script or if we are on a new line. +* matching is fuzzy allowing for multiple linespaces and text indentation. right hand justifications still needs to be dealt with as well as identifying if we are on a new paragraph +* tests are weaker if we are on the first and moving to the second lines of text because we don't have enough information about how the text in the region +* is formatted and in those cases the linespace is taken to be twice the glyph width. +* FIXME: This needs fixing when font support is added and the ascending and descending values for the font should be used instead of the glyphs width. +* TODO: support LineType::STYLESUBSCRIPT +* TODO: support NEWLINE new paragraphs with multiple linespaces and indented x insteads of just ignoring the relative x position +* TODO: I don't know if the invariant qDebug cases should always report an error or only do so when DEBUG_TEXT_IMPORT is defined. My feeling is they should always report because it meanms something has happened that shouldn't have and it's useful feedback. +*/ +TextRegion::LineType TextRegion::linearTest(QPointF point, bool xInLimits, bool yInLimits) +{ + if (collinear(point.y(), lastXY.y())) + if (collinear(point.x(), lastXY.x())) + return LineType::FIRSTPOINT; + else if (xInLimits) + return LineType::SAMELINE; + #ifdef DEBUG_TEXT_IMPORT + else + qDebug() << "FIRSTPOINT/SAMELINE oops:" << "point:" << point << " textRegioBasenOrigin:" << textRegioBasenOrigin << " baseline:" << this->lineBaseXY << " lastXY:" << lastXY << " linespacing:" << lineSpacing << " textRegionLines.size:" << textRegionLines.size(); + #endif + else if (adjunctLesser(point.y(), lastXY.y(), lineBaseXY.y())) + return LineType::STYLESUPERSCRIPT; + else if (adjunctGreater(point.y(), lastXY.y(), lineBaseXY.y())) + if (collinear(point.y(), lineBaseXY.y())) + return LineType::STYLENORMALRETURN; + else + return LineType::STYLESUPERSCRIPT; + else if (isCloseToX(point.x(), textRegioBasenOrigin.x())) + if (isCloseToY(point.y(), lastXY.y()) && !collinear(point.y(), lastXY.y())) + if (textRegionLines.size() >= 2) + return LineType::NEWLINE; + else if (textRegionLines.size() == 1) + return LineType::NEWLINE; + #ifdef DEBUG_TEXT_IMPORT + else + qDebug() << "NEWLINE oops2:" << "point:" << point << " textRegioBasenOrigin:" << textRegioBasenOrigin << " baseline:" << this->lineBaseXY << " lastXY:" << lastXY << "linespacing:" << lineSpacing << "textRegionLines.size:" << textRegionLines.size() << " textRegionLines[textRegionLines.size() - 2].width:" << textRegionLines[textRegionLines.size() - 2].width << " maxWidth:" << maxWidth; + #endif + #ifdef DEBUG_TEXT_IMPORT + else + qDebug() << "NEWLINE oops:" << "point:" << point << " textRegioBasenOrigin:" << textRegioBasenOrigin << " baseline:" << this->lineBaseXY << " lastXY:" << lastXY << "linespacing:" << lineSpacing << "textRegionLines.size:" << textRegionLines.size(); + #endif + #ifdef DEBUG_TEXT_IMPORT //This isn't an invariant case like the others, we actually expect this to happen some of the time + qDebug() << "FAILED with oops:" << "point:" << point << " textRegioBasenOrigin:" << textRegioBasenOrigin << " baseline:" << this->lineBaseXY <<" lastXY:"<< lastXY << " linespacing:" << lineSpacing << " textRegionLines.size:" << textRegionLines.size(); + #endif + return LineType::FAIL; +} + +/* +* Perform some fuzzy checks to see if newPoint can reasonably be ascribed to the current textframe. +* FIXME: It may be that move and addGlyph need different versions of isCloseToX and isCloseToY but keep them the same just for now +*/ +TextRegion::LineType TextRegion::isRegionConcurrent(QPointF newPoint) +{ + if (glyphs.empty()) + { + lineBaseXY = newPoint; + lastXY = newPoint; + } + + bool xInLimits = isCloseToX(newPoint.x(), lastXY.x()); + bool yInLimits = isCloseToY(newPoint.y(), lastXY.y()); + LineType pass = linearTest(newPoint, xInLimits, yInLimits); + return pass; +} + +/* +* Move the position of the cursor to a new point, +* test if that point is within the current textframe or within a new textframe. +* initialize the textregion and setup lines and segments +* TODO: iscloseto x and y may need to be different from addGlyph but use thge common isRegionbConcurrent for now +* need to check to see if we are creating a new paragraph or not. +* basically if the cursor is returned to x origin before it reached x width. +* Also needs to have support for rotated text, but I expect I'll add this by removing the text rotation +* from calls to movepoint and addGlyph and instead rotating the whole text region as a block +*/ +TextRegion::LineType TextRegion::moveToPoint(QPointF newPoint) +{ + //qDebug() << "moveToPoint: " << newPoint; + + if (glyphs.empty()) + { + lineBaseXY = newPoint; + lastXY = newPoint; + } + LineType mode = isRegionConcurrent(newPoint); + if (mode == LineType::FAIL) + return mode; + + TextRegionLine* textRegionLine = nullptr; + if (mode == LineType::NEWLINE || mode == LineType::FIRSTPOINT) + { + if (mode != LineType::FIRSTPOINT || textRegionLines.empty()) + textRegionLines.push_back(TextRegionLine()); + + textRegionLine = &textRegionLines.back(); + textRegionLine->baseOrigin = newPoint; + if (mode == LineType::NEWLINE) + { + textRegionLine->maxHeight = abs(newPoint.y() - lastXY.y()); + if (textRegionLines.size() == 2) + lineSpacing = abs(newPoint.y() - lastXY.y()) + 1; + } + } + + textRegionLine = &textRegionLines.back(); + if ((mode == LineType::FIRSTPOINT && textRegionLine->segments.empty()) || mode == LineType::NEWLINE + || mode != LineType::FIRSTPOINT && textRegionLine->segments[0].glyphIndex != textRegionLine->glyphIndex) + { + TextRegionLine newSegment = TextRegionLine(); + textRegionLine->segments.push_back(newSegment); + } + TextRegionLine* segment = &textRegionLine->segments.back(); + segment->baseOrigin = newPoint; + segment->maxHeight = (mode == LineType::STYLESUPERSCRIPT) ? + abs(lineSpacing - (newPoint.y() - lastXY.y())) : + textRegionLines.back().maxHeight; + + if (mode != LineType::NEWLINE && mode != LineType::FIRSTPOINT) + { + textRegionLines.back().segments.back().width = abs(textRegionLines.back().segments.back().baseOrigin.x() - newPoint.x()); + textRegionLine = &textRegionLines.back(); + textRegionLine->width = abs(textRegionLine->baseOrigin.x() - newPoint.x()); + } + + maxHeight = abs(textRegioBasenOrigin.y() - newPoint.y()) > maxHeight ? abs(textRegioBasenOrigin.y() - newPoint.y()) : maxHeight; + lastXY = newPoint; + + return mode; +} + +/* +* Add a new glyph to the current line segment, lines and segments should already have been setup by the +* moveto function which should generally be called prior to addGlyph to setup the lines and segments correctly. +* does some basic calculations to determine and save withs and heights and linespacings of texts etc... +* FIXME: these need to be changed to use the mode average of all glyps added to the text frame instead of just picking the first ones we come accross +* the mode average can also be used to determine the base font style when fonts are added +* left and right hand margins however need to use the maximum and minimum, support for right hand justification +* and centered text needs to be added as we only support left and fully justified at the moment. +* Approximated heights and widths and linespaces need to use the correct font data when font support has been added, +* but for now just use the x advance value. using font data should also allow for the support of rotated text that may use a mixture of x and y advance +*/ +TextRegion::LineType TextRegion::addGlyphAtPoint(QPointF newGlyphPoint, PdfGlyph newGlyph) +{ + QPointF movedGlyphPoint = QPointF(newGlyphPoint.x() + newGlyph.dx, newGlyphPoint.y() + newGlyph.dy); + if (glyphs.size() == 1) + { + lineSpacing = newGlyph.dx * 3; + lastXY = newGlyphPoint; + lineBaseXY = newGlyphPoint; + } else if (textRegionLines.size() == 1) + lineSpacing = maxWidth * 3; + + LineType mode = isRegionConcurrent(newGlyphPoint); + if (mode == LineType::FAIL) + return mode; + + maxHeight = abs(textRegioBasenOrigin.y() - movedGlyphPoint.y()) + lineSpacing > maxHeight ? abs(textRegioBasenOrigin.y() - movedGlyphPoint.y()) + lineSpacing : maxHeight; + + TextRegionLine* textRegionLine = &textRegionLines.back(); + if (mode == LineType::NEWLINE || mode == LineType::FIRSTPOINT) + { + textRegionLine->glyphIndex = glyphs.size() - 1; + textRegionLine->baseOrigin = QPointF(textRegioBasenOrigin.x(), newGlyphPoint.y()); + } + + TextRegionLine* segment = &textRegionLine->segments.back(); + segment->width = abs(movedGlyphPoint.x() - segment->baseOrigin.x()); + segment->glyphIndex = glyphs.size() - 1; + qreal thisHeight = textRegionLines.size() > 1 ? + abs(newGlyphPoint.y() - textRegionLines[textRegionLines.size() - 2].baseOrigin.y()) : + newGlyph.dx; + + segment->maxHeight = thisHeight > segment->maxHeight ? thisHeight : segment->maxHeight; + textRegionLine->maxHeight = textRegionLine->maxHeight > thisHeight ? textRegionLine->maxHeight : thisHeight; + textRegionLine->width = abs(movedGlyphPoint.x() - textRegionLine->baseOrigin.x()); + + maxWidth = textRegionLine->width > maxWidth ? textRegionLine->width : maxWidth; + if (textRegionLine->segments.size() == 1) + lineBaseXY = textRegionLine->baseOrigin; + + lastXY = movedGlyphPoint; + + return mode; +} + +/* +* Render the text region to the frame, +* nothing clever for now, just apply the whole block of text to the textNode +* TODO: Add support for fonts and styles based on line segments +* add support for rotated text +*/ +void TextRegion::renderToTextFrame(PageItem* textNode) +{ + textNode->setWidthHeight(this->maxWidth, this->maxHeight); + QString bodyText = ""; + for (int glyphIndex = this->textRegionLines.begin()->glyphIndex; glyphIndex <= this->textRegionLines.back().segments.back().glyphIndex; glyphIndex++) + bodyText += glyphs[glyphIndex].code; + + textNode->itemText.insertChars(bodyText); + textNode->frameTextEnd(); +} + +/* +* Quick test to see if this is a virgin textregion +*/ +bool TextRegion::isNew() +{ + return textRegionLines.empty() || + glyphs.empty(); +} diff --git a/scribus/plugins/import/pdf/pdftextrecognition.h b/scribus/plugins/import/pdf/pdftextrecognition.h new file mode 100644 index 000000000..78f8ffde2 --- /dev/null +++ b/scribus/plugins/import/pdf/pdftextrecognition.h @@ -0,0 +1,135 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#ifndef PDFTEXTRECOGNITION_H +#define PDFTEXTRECOGNITION_H + +#include +#include +#include + +#include "pageitem.h" +#include "importpdfconfig.h" + +#include +#include + +/* PDF TextBox Framework */ +/* +* Holds all the details for each glyph in the text imported from the pdf file. +* +*/ +struct PdfGlyph +{ + double dx; // X advance value + double dy; // Y advance value + double rise; // Text rise parameter + QChar code; // UTF-16 coded character +}; + + +class TextRegionLine +{ +public: + qreal maxHeight = {}; + //we can probably use maxHeight for this. + qreal width = {}; + int glyphIndex = {}; + QPointF baseOrigin = QPointF({}, {}); + std::vector segments = std::vector(); + +}; + +class TextRegion +{ +public: + enum class LineType + { + FIRSTPOINT, + SAMELINE, + STYLESUPERSCRIPT, + STYLENORMALRETURN, + STYLEBELOWBASELINE, + NEWLINE, + ENDOFLINE, //TODO: Implement an end of line test + FAIL + }; +# + /* +* the bounding box shape splines in percentage of width and height. In this case 100% as we want to clip shape to be the full TextBox width and height. */ + static constexpr double boundingBoxShape[32] = { 0.0,0.0 + ,0.0,0.0 + ,100.0,0.0 + ,100.0,0.0 + ,100.0,0.0 + ,100.0,0.0 + ,100.0,100.0 + ,100.0,100.0 + ,100.0,100.0 + ,100.0,100.0 + ,0.0,100.0 + ,0.0,100.0 + ,0.0,100.0 + ,0.0,100.0 + ,0.0,0.0 + ,0.0,0.0 + }; + + QPointF textRegioBasenOrigin = QPointF({}, {}); + qreal maxHeight = {}; + qreal lineSpacing = { 1 }; + std::vector textRegionLines = std::vector(); + qreal maxWidth = {}; + QPointF lineBaseXY = QPointF({ }, { }); //updated with the best match left value from all the textRegionLines and the best bottom value from the textRegionLines.segments; + QPointF lastXY = QPointF({}, {}); + static bool collinear(qreal a, qreal b); + bool isCloseToX(qreal x1, qreal x2); + bool isCloseToY(qreal y1, qreal y2); + bool adjunctLesser(qreal testY, qreal lastY, qreal baseY); + bool adjunctGreater(qreal testY, qreal lastY, qreal baseY); + TextRegion::LineType linearTest(QPointF point, bool xInLimits, bool yInLimits); + TextRegion::LineType isRegionConcurrent(QPointF newPoint); + TextRegion::LineType moveToPoint(QPointF newPoint); + TextRegion::LineType addGlyphAtPoint(QPointF newGlyphPoint, PdfGlyph new_glyph); + void renderToTextFrame(PageItem* textNode); + std::vector glyphs; + bool isNew(); +}; + +class PdfTextRecognition +{ +public: + PdfTextRecognition(); + ~PdfTextRecognition(); + + enum class AddCharMode + { + ADDFIRSTCHAR, + ADDBASICCHAR, + ADDCHARWITHNEWSTYLE, + ADDCHARWITHPREVIOUSSTYLE, + ADDCHARWITHBASESTLYE + }; + + void setCharMode(AddCharMode mode) + { + m_addCharMode = mode; + } + + TextRegion&& activeTextRegion = TextRegion(); //faster and cleaner than calling back on the vector all the time. + void addTextRegion(); + void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, POPPLER_CONST_082 Unicode* u, int uLen); + bool isNewLineOrRegion(QPointF newPosition); +private: + std::vector m_textRegions = std::vector(); + AddCharMode m_addCharMode = AddCharMode::ADDFIRSTCHAR; + PdfGlyph AddCharCommon(GfxState* state, double x, double y, double dx, double dy, Unicode const* u, int uLen); + PdfGlyph AddFirstChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen); + PdfGlyph AddBasicChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen); + PdfGlyph AddCharWithNewStyle(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen); + PdfGlyph AddCharWithPreviousStyle(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen); +}; +#endif diff --git a/scribus/plugins/import/pdf/slaoutput.cpp b/scribus/plugins/import/pdf/slaoutput.cpp index ecc17c487..8d2524f52 100644 --- a/scribus/plugins/import/pdf/slaoutput.cpp +++ b/scribus/plugins/import/pdf/slaoutput.cpp @@ -20,6 +20,9 @@ for which a new license (GPL+exception) is in place. #include "util_math.h" #include +#ifndef DEBUG_TEXT_IMPORT + #define DEBUG_TEXT_IMPORT +#endif namespace { // Compute the intersection of two paths while considering the fillrule of each of them. @@ -285,15 +288,6 @@ SlaOutputDev::SlaOutputDev(ScribusDoc* doc, QList *Elements, QStringL currentLayer = m_doc->activeLayer(); layersSetByOCG = false; importTextAsVectors = true; - - m_textRegions.push_back(activeTextRegion); - //have a map of reusable addchar implementations instead of creating and deleting them all the time. - addCharModes[ADDCHARMODE::ADDFIRSTCHAR] = new AddFirstChar(this); - addCharModes[ADDCHARMODE::ADDBASICCHAR] = new AddBasicChar(this); - addCharModes[ADDCHARMODE::ADDCHARWITHNEWSTYLE] = new AddCharWithNewStyle(this); - addCharModes[ADDCHARMODE::ADDCHARWITHPREVIOUSSTYLE] = new AddCharWithPreviousStyle(this); - - addChar = addCharModes[ADDCHARMODE::ADDFIRSTCHAR]; } SlaOutputDev::~SlaOutputDev() @@ -302,11 +296,6 @@ SlaOutputDev::~SlaOutputDev() tmpSel->clear(); delete tmpSel; delete m_fontEngine; - //FIXME: could probably enumberate this - delete addCharModes[ADDCHARMODE::ADDFIRSTCHAR]; - delete addCharModes[ADDCHARMODE::ADDBASICCHAR]; - delete addCharModes[ADDCHARMODE::ADDCHARWITHNEWSTYLE]; - delete addCharModes[ADDCHARMODE::ADDCHARWITHPREVIOUSSTYLE]; } /* get Actions not implemented by Poppler */ @@ -2525,11 +2514,11 @@ void SlaOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str ImageStream * imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits()); imgStr->reset(); unsigned int *dest = nullptr; - unsigned char * buffer = new unsigned char[width * height * 4]; + unsigned char * buffer = new unsigned char[(long)width * (long)height * 4]; QImage * image = nullptr; for (int y = 0; y < height; y++) { - dest = (unsigned int *)(buffer + y * 4 * width); + dest = (unsigned int *)(buffer + y * 4 * (long)width); Guchar * pix = imgStr->getLine(); colorMap->getRGBLine(pix, dest, width); } @@ -2544,11 +2533,11 @@ void SlaOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str ImageStream *mskStr = new ImageStream(maskStr, maskWidth, maskColorMap->getNumPixelComps(), maskColorMap->getBits()); mskStr->reset(); Guchar *mdest = nullptr; - unsigned char * mbuffer = new unsigned char[maskWidth * maskHeight]; - memset(mbuffer, 0, maskWidth * maskHeight); + unsigned char * mbuffer = new unsigned char[(long)maskWidth * (long)maskHeight]; + memset(mbuffer, 0, (long)maskWidth * (long)maskHeight); for (int y = 0; y < maskHeight; y++) { - mdest = (Guchar *)(mbuffer + y * maskWidth); + mdest = (Guchar *)(mbuffer + y * (long)maskWidth); Guchar * pix = mskStr->getLine(); maskColorMap->getGrayLine(pix, mdest, maskWidth); } @@ -2605,11 +2594,11 @@ void SlaOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str, i ImageStream * imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits()); imgStr->reset(); unsigned int *dest = nullptr; - unsigned char * buffer = new unsigned char[width * height * 4]; + unsigned char * buffer = new unsigned char[(long)width * (long)height * 4]; QImage * image = nullptr; for (int y = 0; y < height; y++) { - dest = (unsigned int *)(buffer + y * 4 * width); + dest = (unsigned int *)(buffer + y * 4 * (long)width); Guchar * pix = imgStr->getLine(); colorMap->getRGBLine(pix, dest, width); } @@ -2625,11 +2614,11 @@ void SlaOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str, i mskStr->reset(); Guchar *mdest = nullptr; int invert_bit = maskInvert ? 1 : 0; - unsigned char * mbuffer = new unsigned char[maskWidth * maskHeight]; - memset(mbuffer, 0, maskWidth * maskHeight); + unsigned char * mbuffer = new unsigned char[(long)maskWidth * (long)maskHeight]; + memset(mbuffer, 0, (long)maskWidth * (long)maskHeight); for (int y = 0; y < maskHeight; y++) { - mdest = (Guchar *)(mbuffer + y * maskWidth); + mdest = (Guchar *)(mbuffer + y * (long)maskWidth); Guchar * pix = mskStr->getLine(); for (int x = 0; x < maskWidth; x++) { @@ -2736,7 +2725,8 @@ void SlaOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int widt } } - if (image != nullptr && !image->isNull()) { + if (image != nullptr && !image->isNull()) + { createImageFrame(*image, state, colorMap->getNumPixelComps()); } @@ -3058,11 +3048,13 @@ void SlaOutputDev::updateFontForVector(GfxState *state) tmpBuf = nullptr; fontLoc = nullptr; - if (!(gfxFont = state->getFont())) { + if (!(gfxFont = state->getFont())) + { goto err1; } fontType = gfxFont->getType(); - if (fontType == fontType3) { + if (fontType == fontType3) + { goto err1; } @@ -3102,7 +3094,8 @@ void SlaOutputDev::updateFontForVector(GfxState *state) fontsrc->setBuf(tmpBuf, tmpBufLen, gTrue); // load the font file - switch (fontType) { + switch (fontType) + { case fontType1: if (!(fontFile = m_fontEngine->loadType1Font( id, @@ -3268,16 +3261,11 @@ void SlaOutputDev::updateFontForVector(GfxState *state) fontsrc->unref(); } -void SlaOutputDev::drawChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, POPPLER_CONST_082 Unicode* u, int uLen) +void SlaOutputDev::drawCharAsVector(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, POPPLER_CONST_082 Unicode* u, int uLen) { //qDebug() << "SlaOutputDev::drawChar x:" << x << "y:" << y << "dx:" << dx << "dy" << dy << "code:" << code; - //for importing text as glyphs double x1, y1, x2, y2; - //if (import_text_as_vectors) { updateFontForVector(state); //this sets m_font a splashfont - //TODO: add support for fonts when importing pdf text - //_updateFontForText(state); //and this sets font_style and has a lkot more detail about the font, both work on the same details from gfxfont - if (!m_font) return; @@ -3330,48 +3318,60 @@ void SlaOutputDev::drawChar(GfxState* state, double x, double y, double dx, doub FPointArray textPath; textPath.fromQPainterPath(qPath); FPoint wh = textPath.widthHeight(); - if (importTextAsVectors) { - //qDebug() << "drawChar() "; - if (textRenderingMode > 3) - { - QTransform mm; - mm.scale(1, -1); - mm.translate(x, -y); - // Remember the glyph for later clipping - m_clipTextPath.addPath(m_ctm.map(mm.map(qPath))); - } - if ((textPath.size() > 3) && ((wh.x() != 0.0) || (wh.y() != 0.0)) && (textRenderingMode != 7)) + //qDebug() << "drawChar() "; + if (textRenderingMode > 3) + { + QTransform mm; + mm.scale(1, -1); + mm.translate(x, -y); + // Remember the glyph for later clipping + m_clipTextPath.addPath(m_ctm.map(mm.map(qPath))); + } + if ((textPath.size() > 3) && ((wh.x() != 0.0) || (wh.y() != 0.0)) && (textRenderingMode != 7)) + { + PageItem* textNode = nullptr; + + int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, CommonStrings::None, CommonStrings::None); + textNode = m_doc->Items->at(z); + + // todo: merge this between vector and text implementations. + QTransform mm; + mm.scale(1, -1); + mm.translate(x, -y); + textPath.map(mm); + textPath.map(m_ctm); + textNode->PoLine = textPath.copy(); + setFillAndStrokeForPDF(state, textNode); + // Fill text rendering modes. See above + m_doc->adjustItemSize(textNode); + m_Elements->append(textNode); + if (m_groupStack.count() != 0) { - PageItem* textNode = nullptr; - - - int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, CommonStrings::None, CommonStrings::None); - textNode = m_doc->Items->at(z); - - // todo: merge this between vector and text implementations. - - QTransform mm; - mm.scale(1, -1); - mm.translate(x, -y); - textPath.map(mm); - textPath.map(m_ctm); - textNode->PoLine = textPath.copy(); - setFillAndStrokeForPDF(state, textNode); - // Fill text rendering modes. See above - m_doc->adjustItemSize(textNode); - m_Elements->append(textNode); - if (m_groupStack.count() != 0) - { - m_groupStack.top().Items.append(textNode); - applyMask(textNode); - } + m_groupStack.top().Items.append(textNode); + applyMask(textNode); } - delete fontPath; } + delete fontPath; + } - if (!importTextAsVectors) { // donm't render the char as vectors add it to an array so it can be rendred as a string - addChar->addChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen); + } +} + +void SlaOutputDev::drawChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, POPPLER_CONST_082 Unicode* u, int uLen) +{ + if(importTextAsVectors) + drawCharAsVector(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen); + else + { + // TODO Implement the clipping operations. At least the characters are shown. + int textRenderingMode = state->getRender(); + // Invisible or only used for clipping + if (textRenderingMode == 3) + return; + if (textRenderingMode < 8) + { + m_textRecognition.addChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen); } } } @@ -3444,30 +3444,37 @@ void SlaOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, do void SlaOutputDev::beginTextObject(GfxState *state) { pushGroup(); - if (importTextAsVectors == false && activeTextRegion.lastXY != QPointF(-1, -1)) { - activeTextRegion = TextRegion(); - m_textRegions.push_back(activeTextRegion); - } - else if (activeTextRegion.lastXY == QPointF(-1, -1)) { - qDebug("FIXME:Rogue _lastXY"); + if (importTextAsVectors == false && !m_textRecognition.activeTextRegion.textRegionLines.empty()) { + #ifdef DEBUG_TEXT_IMPORT + qDebug("beginTextObject: m_textRecognition.addTextRegion()"); + #endif + m_textRecognition.addTextRegion(); } - addChar = addCharModes[ADDFIRSTCHAR]; } - +/* + * NOTE: The success == TextRegion::LineType::FAIL test is an invariant test that should never pass. if a rogue glyph is detected then it means there is a bug in the logic probably in TextRegion::addGlyphAtPoint or TextRegion::linearTest or TextRegion::moveToPoint + * TODO: Support merging of text boxes where beginTextObject and endTextObject have been called but really it's looking like it's just a new line + * maybe do a second pass before rendering and implement a merge function in pdfTectRecognition &co. +*/ void SlaOutputDev::endTextObject(GfxState *state) { - if (importTextAsVectors == false && activeTextRegion.lastXY != QPointF(-1, -1)) { + if (importTextAsVectors == false && !m_textRecognition.activeTextRegion.textRegionLines.empty()) { // Add the last glyph to the textregion - if (activeTextRegion.addGlyphAtPoint(activeTextRegion.glyphs.back().position, activeTextRegion.glyphs.back()) == TextRegion::FAIL) { - qDebug("FIXME: Rogue glyph detected, this should never happen because the copuror should move before glyphs in new regions are added."); + QPointF glyphXY = m_textRecognition.activeTextRegion.lastXY; + m_textRecognition.activeTextRegion.lastXY.setX(m_textRecognition.activeTextRegion.lastXY.x() - m_textRecognition.activeTextRegion.glyphs.back().dx); + if (m_textRecognition.activeTextRegion.addGlyphAtPoint(glyphXY, m_textRecognition.activeTextRegion.glyphs.back()) == TextRegion::LineType::FAIL) { + qDebug("FIXME: Rogue glyph detected, this should never happen because the cursor should move before glyphs in new regions are added."); } + #ifdef DEBUG_TEXT_IMPORT + qDebug("endTextObject: renderTextFrame"); + #endif renderTextFrame(); - } else if (activeTextRegion.lastXY == QPointF(-1, -1)) { - qDebug("FIXME:Rogue _lastXY"); + } else if (importTextAsVectors == false && !m_textRecognition.activeTextRegion.textRegionLines.empty()) { + qDebug("FIXME:Rogue textblock"); } - addChar = addCharModes[ADDFIRSTCHAR]; + m_textRecognition.setCharMode(PdfTextRecognition::AddCharMode::ADDFIRSTCHAR); // qDebug() << "SlaOutputDev::endTextObject"; if (!m_clipTextPath.isEmpty()) { @@ -3491,12 +3498,7 @@ void SlaOutputDev::endTextObject(GfxState *state) else ite = gElements.Items.first(); ite->setGroupClipping(false); - if (importTextAsVectors == false) { - ite->setFillTransparency(1.0 - state->getFillOpacity()); - } - else { - ite->setFillTransparency(1.0 - state->getFillOpacity()); - } + ite->setFillTransparency(1.0 - state->getFillOpacity()); ite->setFillBlendmode(getBlendMode(state)); for (int as = 0; as < tmpSel->count(); ++as) { @@ -3937,362 +3939,9 @@ bool SlaOutputDev::checkClip() return ret; } -// TODO: remove mutual dependencies and move the render engine into it's own cc and header files because it's getting hard to navigate the code base. -// PDF never deviates from the line when it comes to colenear -bool TextRegion::coLinera(qreal a, qreal b) { - return abs(a - b) < 1 ? true : false; -} - -// like _colenia but we allow a deviation of upto +-2 rejion font text widths -bool TextRegion::closeToX(qreal x1, qreal x2){ - //TODO: return abs(x1 - x2) <= coreText.mWidth() * 2 ? true : false; - // return x1 - x2 <= modeHeigth ? true : false; //allow infinate overrun but only one char width underrun - return true; -} - -// like _colenia but we allow a deviation of upto 2 rejion font linespaces, but in one direction and half a line space in the other direction -bool TextRegion::closeToY(qreal y1, qreal y2) { - //FIXME: Actually test the correctg magnitudes not the abs value. There shound be a parameter in the ui to set the matching tollerance - return (y2 - y1) >= 0 && y2 - y1 <= lineSpacing * 3 ? true : lineSpacing==-1 ? (y2 - y1) >= 0 && y2 - y1 <= modeHeigth * 5 ? true : false :false; -} - -// lesss than the last y value but bot more than the line spacing less, could also use the base line of the last line to be more accurate -bool TextRegion::adjunctLesser(qreal testY, qreal lastY, qreal baseY) { - return (testY > lastY - && testY <= baseY + lineSpacing - && lastY <= baseY + lineSpacing - && lineSpacing != -1) ? true : false; -} - -// lesss than the last y value but bot more than the line spacing less, could also use the base line of the last line to be more accurate -bool TextRegion::adjunctGreater(qreal testY, qreal lastY, qreal baseY) { - return (testY < lastY - && lastY <= baseY - lineSpacing *0.75 - && lineSpacing != -1) ? true : false; -} - -TextRegion::FRAMEWORKLINETESTS TextRegion::linearTest(QPointF point, bool xInLimits, bool yInLimits) { - //TODO: add a FIRSTPOINT result as well - FRAMEWORKLINETESTS pass = FAIL; - if (coLinera(point.y(), lastXY.y())) - { - if (coLinera(point.x(), lastXY.x())) - { - pass = FIRSTPOINT; - qDebug() << "FIRSTPOINT"; - }else // see if we are continuing along a line or if we can add a new line to take into account this first line may have truncated early, leaving the rest of the lines dangling out x's - if (xInLimits) - { - // this is for item ##16 - // ok, this should only happen when a new glyph is added not when the cursor position is set, but in both cases we can call extend by the point and set the glyph to the current glyph checking that it's not a duplicate - //TODO: textRegionLines.end().extend(point).setGlyph(newGlyph); - pass = SAMELINE; - qDebug() << "SAMELINE " << point << " lastxy:"<< lastXY; - } - } // else see if y is a bit too much off thelastyx line to be linear - else if (adjunctLesser(point.y(), lastXY.y(), lineBaseXY.y())) - { - //TODO: character has gone suprtscript - pass = STYLESUPERSCRIPT; - qDebug() << "STYLESUPERSCRIPT point:" << point << " lastXY:" << lastXY << " lineBaseXY:" << lineBaseXY; - } - else if (adjunctGreater(point.y(), lastXY.y(), lineBaseXY.y())) - { - if (coLinera(point.y(), lineBaseXY.y())) //PDF never deviates from the line when it comes to colenear - { - // were back on track - pass = STYLENORMALRETURN; - //qDebug() << "STYLENORMALRETURN"; - } - else { - //TODO: this character has overflowed the height, or is still superscript just not so much - pass = STYLESUPERSCRIPT; //could be STYLEBELOWBASELINE - qDebug() << "STYLESUPERSCRIPT"; - } - } - else { - //TODO: We need to calculate things like new parargraphs and left hand justification - if (closeToX(textRegioBasenOrigin.x(), point.x())) - { - if (closeToY(point.y(), lastXY.y())) { - //TODO: We need to calculate things like new parargraphs and left hand justification - if ((textRegionLines.size() >= 2) && closeToX(textRegionLines[textRegionLines.size() - 2].width, maxWidth)) - { - //TODO: add a new line and update the deltas - pass = NEWLINE; - qDebug() << "NEWLINE1 point:" << point << " _lastXY:" << lastXY << " origin: " << textRegioBasenOrigin << " modeheight: " << modeHeigth << " this:" << this << " linespacing: " << lineSpacing; - } // we only have the first line so far, so pass without much of a test. - else if (textRegionLines.size() == 1) - { - pass = NEWLINE; - qDebug() << "NEWLINE2 point:" << point << " _lastXY:" << lastXY << " origin: " << textRegioBasenOrigin << " modeheight: " << modeHeigth << " this:" << this << " linespacing: " << lineSpacing; - } - } - } - } - return pass; -} - -// Just perform some basic checks to see if newPoint can reasonably be asscribed to the current textframe. -TextRegion::FRAMEWORKLINETESTS TextRegion::isRegionConcurrent(QPointF newPoint) -{ - if (lineBaseXY == QPointF(-1, -1)) - { - lineBaseXY = newPoint; - } - if (lastXY == QPointF(-1, -1)) - { - lastXY = newPoint; - } - //TODO: I need to write down which ones we want so I can work it all out, for now just some basic fuzzy matching support. - bool xInLimits = false; - if (closeToX(newPoint.x(), lastXY.x())) - { - xInLimits = true; - } - bool yInLimits = false; - if (closeToY(newPoint.y(), lastXY.y())) - { - yInLimits = true; - } - FRAMEWORKLINETESTS pass = linearTest(newPoint, xInLimits, yInLimits); - return pass; -} - - -TextRegion::FRAMEWORKLINETESTS TextRegion::moveToPoint(QPointF newPoint) +void SlaOutputDev::setFillAndStrokeForPDF(GfxState* state, PageItem* textNode) { - // - //qDebug() << "moveToPoint: " << newPoint; - // Do some initilization if we are in a new text region - // we could also update these if glyphindex = -1; - if (lineBaseXY == QPointF(-1, -1) || textRegionLines.size() == 0 || textRegionLines[0].glyphIndex == -1) - { - lineBaseXY = newPoint; - //qDebug() << "newPoint2: " << newPoint; - } - if (lastXY == QPointF(-1, -1) || textRegionLines.size() == 0 || textRegionLines[0].glyphIndex == -1) - { - lastXY = newPoint; - //qDebug() << "newPoint3: " << newPoint; - } - if (modeHeigth == -1) - { - modeHeigth = 1; - } - - //TODO: I need to write down which ones we want so I can work it all out, for now just some basic fuzzy matching support. - //TODO: x limiting should be different for moving as opposed to adding a new glyph because moiving is due to a discontinuity in glyphs - bool xInLimits = false; - if (closeToX(newPoint.x(), lastXY.x())) - { - //qDebug() << "newPoint6: " << newPoint; - xInLimits = true; - } - bool yInLimits = false; - if (closeToY(newPoint.y(), lastXY.y())) - { - //qDebug() << "newPoint7: " << newPoint; - yInLimits = true; - } - //qDebug() << "newPoint8: " << newPoint; - FRAMEWORKLINETESTS pass = linearTest(newPoint, xInLimits, yInLimits); - - //TODO: need to check to see if we are creating a new paragraph or not. basically if the cursor is returned to x origin before it reached x width. this could be returned as part of a matrix by linearTest that specifies exactly how the test ws passed. maybew return an enum with either the mode that passed or a failure value - if (pass != FRAMEWORKLINETESTS::FAIL) - { - // FIXME: only do this under certain circumstances, we can merge two or move boxes together horrizontally and don't need a new region line on the m_activeTextRegion we need one on the segments list on textRegionLines.end() . infact this should be done in the linear test function - // TODO: finish off the parameters of the last textRegionLine and make sure were not just adding a segment - //this really needs font support to work because we can base the size modeheight should be on the size of the font - if (textRegionLines.size() == 0) { - textRegionLines.push_back(TextRegionLine()); - } - TextRegionLine *textRegionLine = &textRegionLines.back(); - if (pass == NEWLINE) - { - //qDebug() << "Newline: "; - if(textRegionLine->glyphIndex != -1) - { - textRegionLines.push_back(TextRegionLine()); - textRegionLine = &textRegionLines.back(); - } - } - else { - //qDebug() << "NewSegment: "; - if (textRegionLine->segments.empty() || textRegionLine->segments.back().glyphIndex != -1) - { - textRegionLine->segments.push_back(TextRegionLine()); - } - textRegionLine = &textRegionLine->segments.back(); - } - // we alweays need to set thease defaults if were adding - - textRegionLine->baseOrigin = newPoint; - //qDebug() << "base olrigin: " << textRegionLine->baseOrigin; - textRegionLine->width = 0; - - // this should be - if (pass == NEWLINE) - { - //FIXME: I don't think it should be conditional I think it should just sets it. - textRegionLine->maxHeight = abs(newPoint.y() - lastXY.y()) > textRegionLine->maxHeight ? abs(newPoint.y() - lastXY.y()) : textRegionLine->maxHeight; - if(abs(lastXY.y() - newPoint.y()) + 1 > lineSpacing) - { - if (textRegionLines.size() == 2) { - lineSpacing = abs(newPoint.y() - lastXY.y()) + 1; - //qDebug() << "setting modeHeight to:" << modeHeigth; - } - } - } - else if (pass == SAMELINE || pass == ENDOFLINE || pass == STYLENORMALRETURN) - { - textRegionLine->maxHeight = textRegionLines.back().maxHeight > textRegionLine->maxHeight ? textRegionLines.back().maxHeight : textRegionLine->maxHeight; - } - else - { - textRegionLine->maxHeight = abs(newPoint.y() - lastXY.y()) > textRegionLine->maxHeight ? abs(newPoint.y() - lastXY.y()) : textRegionLine->maxHeight; - } - maxHeight = abs(textRegioBasenOrigin.y() - newPoint.y()) > maxHeight ? abs(textRegioBasenOrigin.y() - newPoint.y()) : maxHeight; - //FIXME: this should really be the most common height accross all segments and lines. - //textRegionLine->modeHeigth = abs(newPoint.y() - lastXY.y()) > modeHeigth ? abs(newPoint.y() - lastXY.y()) : modeHeigth; - - //TODO: set modeHeigth - // check to see if were a new line or the first line and we have already had a character set on this line - if ((pass == FIRSTPOINT && textRegionLines.size() == 0) || (pass == NEWLINE && (textRegionLines.back().glyphIndex != -1))) { - //FIXME: Therre's a bug here because this will be a duplicate if it's set by thew pass == NEWLINE condition above - textRegionLines.push_back(*textRegionLine); - } // Otherwise see if were adding a new segment, changes is styles of the text etc... should trigger addint a new character so the glyphindex should be gaurenteed to be set if were adding a new segment - else if (textRegionLines.back().glyphIndex != -1 && pass == SAMELINE) { - if (textRegionLines.back().segments.size() > 0) { - textRegionLines.back().segments.back().width = abs(textRegionLines.back().segments.back().baseOrigin.x() - newPoint.x()); - } - //textRegionLines.back().segments.push_back(*textRegionLine); - textRegionLine = &textRegionLines.back(); - textRegionLine->width = abs(textRegionLine->baseOrigin.x() - newPoint.x()); - } - lastXY = newPoint; - } - else - { - //qDebug() << "movetopoint failed"; - } - - return pass; -} - -//TODO:, extract some font heights instesad of using dx all the time -TextRegion::FRAMEWORKLINETESTS TextRegion::addGlyphAtPoint(QPointF newGlyphPoint, PdfGlyph new_glyph) { - - QPointF movedGlyphPoint = QPointF(newGlyphPoint.x() + new_glyph.dx, newGlyphPoint.y() + new_glyph.dy); - //TODO: should probably be more forgiving when adding a glyph in the x direction because it could be several white spaces skipped - //qDebug() << "addGlyphAtPoint start" << newGlyphPoint << " glyph:"<< new_glyph.code; - if (glyphs.size() == 1) - { - // FIXME: do a propper lookup of the height - modeHeigth = new_glyph.dx; - //qDebug() << "addGlyphAtPoint start"; - } - if (lastXY == QPointF(-1, -1)) { - lastXY = newGlyphPoint; - } - if (lineBaseXY == QPointF(-1, -1)) { - lineBaseXY = newGlyphPoint; - } - bool xInLimits = false; - if (closeToX(newGlyphPoint.x(), lastXY.x())) { - xInLimits = true; - } - bool yInLimits = false; - if (closeToY(newGlyphPoint.y(), lastXY.y())) { - yInLimits = true; - } - FRAMEWORKLINETESTS pass = linearTest(newGlyphPoint, xInLimits, yInLimits); - //TODO: Implement this in the caller - // if nothing can be done then write out the textregioin and delete it and create a new trextrext and re-adcfd ther char, set the pos etc... - if (pass != FRAMEWORKLINETESTS::FAIL) { - //TODO: possible don't store the glyphs on the textRegion, well certainly not like this, we only need to check bounbdry and feature positions - //glyphs.push_back(new_glyph); - maxHeight = abs(textRegioBasenOrigin.y() - movedGlyphPoint.y()) + modeHeigth > maxHeight ? abs(textRegioBasenOrigin.y() - movedGlyphPoint.y()) + modeHeigth : maxHeight; - /* - if (textRegionLines.size() == 0) - { - TextRegionLine newTextRegionLine = TextRegionLine(); - newTextRegionLine.glyphIndex = glyphs.size() - 1; - newTextRegionLine.width = new_glyph.dx; - textRegionLines.push_back(newTextRegionLine); - } - */ - TextRegionLine* textRegionLine = nullptr; - //at the moment a new segment only gets added when the line is created. a new segment should also get added if there's any change in style or layout etc...but that feature can be added llater, it's not needed for basic textframe support with no style. - // FIXME: becaused moveTo should always be called first we should always have a textRegionLines - if (textRegionLines.size() == 0) - { - TextRegionLine newTextRegionLine = TextRegionLine(); - newTextRegionLine.baseOrigin = QPointF(textRegioBasenOrigin.x(), newGlyphPoint.y()); - textRegionLines.push_back(newTextRegionLine); - } - textRegionLine = &textRegionLines.back(); - - if (textRegionLine->glyphIndex == -1) - { - textRegionLine->glyphIndex = glyphs.size() - 1; - textRegionLine->baseOrigin = QPointF(textRegioBasenOrigin.x(), newGlyphPoint.y()); - } - - if (textRegionLine->segments.empty() || newGlyphPoint.x() > textRegionLine->baseOrigin.x() + textRegionLine->width && textRegionLine->segments.back().glyphIndex != -1) - { - // add a new segment - TextRegionLine newSegment = TextRegionLine(); - newSegment.glyphIndex = textRegionLine->glyphIndex; - newSegment.width = 0; - newSegment.baseOrigin = QPointF(newGlyphPoint.x(), textRegionLine->baseOrigin.y()); - textRegionLine->segments.push_back(newSegment); - } - // update the text line and segment widths, - TextRegionLine *segment = &textRegionLine->segments.back(); - segment->width = abs(movedGlyphPoint.x() - segment->baseOrigin.x()); - segment->glyphIndex = glyphs.size() - 1; - if (textRegionLines.size() > 1) - { - segment->modeHeigth = abs(newGlyphPoint.y() - textRegionLines[textRegionLines.size() - 2].baseOrigin.y()); - segment->maxHeight = segment->modeHeigth > segment->maxHeight ? segment->modeHeigth : segment->maxHeight; - } - else - { - segment->modeHeigth = new_glyph.dx; - segment->maxHeight = segment->modeHeigth > segment->maxHeight ? segment->modeHeigth : segment->maxHeight; - } - textRegionLine->maxHeight = textRegionLine->maxHeight > segment->maxHeight ? textRegionLine->maxHeight : segment->maxHeight; - textRegionLine->modeHeigth = textRegionLine->maxHeight; //FIXME: this needs to be calculated based on the heights of all the segments - textRegionLine->width = abs(movedGlyphPoint.x() - textRegionLine->baseOrigin.x()); - maxWidth = textRegionLine->width > maxWidth ? textRegionLine->width : maxWidth; - - //FIXME: Check if we are on a new line before setting _lineBaseXY - lineBaseXY = textRegionLine->baseOrigin;// movedGlyphPoint; - lastXY = movedGlyphPoint; - - } - else - { - qDebug() << "addGlyphAtPoint failed"; - } - return pass; -} - -void TextRegion::renderToTextFrame(PageItem* textNode, ParagraphStyle& pStyle) -{ - // nothing clever, just get all the body text in one lump and update the text frame - textNode->setWidthHeight(this->maxWidth, this->maxHeight); - QString bodyText = ""; - for (int glyphIndex = this->textRegionLines.begin()->glyphIndex; glyphIndex <= this->textRegionLines.back().segments.back().glyphIndex; glyphIndex++) { - bodyText += glyphs[glyphIndex].code; - } - textNode->itemText.insertChars(bodyText); - textNode->frameTextEnd(); -} - -void SlaOutputDev::setFillAndStrokeForPDF(GfxState* state, PageItem* textNode) { textNode->ClipEdited = true; textNode->FrameType = 3; @@ -4304,20 +3953,22 @@ void SlaOutputDev::setFillAndStrokeForPDF(GfxState* state, PageItem* textNode) { // Invisible or only used for clipping if (textRenderingMode == 3) return; + // Fill text rendering modes. See above if (textRenderingMode == 0 || textRenderingMode == 2 || textRenderingMode == 4 || textRenderingMode == 6) { CurrColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &CurrFillShade); - if (textNode->isTextFrame()) { //fill colour sets the background colour for the frame not the fill colour fore the text - textNode->setFillTransparency(1.0 - (state->getFillOpacity() > state->getStrokeOpacity() ? state->getFillOpacity() : state->getStrokeOpacity())); - textNode->setLineTransparency(1.0); // this ssets the transparency of the textbox border and we don't want to see it + if (textNode->isTextFrame()) { + textNode->setFillTransparency(1.0 - (state->getFillOpacity() > state->getStrokeOpacity() ? state->getFillOpacity() : state->getStrokeOpacity())); //fill colour sets the background colour for the frame not the fill colour fore the text + textNode->setLineTransparency(1.0); // this sets the transparency of the textbox border and we don't want to see it textNode->setFillColor(CommonStrings::None); textNode->setLineColor(CommonStrings::None); textNode->setLineWidth(0);//line width doesn't effect drawing text, it creates a bounding box state->getTransformedLineWidth()); textNode->setFillShade(CurrFillShade); } - else { + else + { textNode->setFillColor(CurrColorFill); textNode->setFillShade(CurrFillShade); textNode->setFillEvenOdd(false); @@ -4329,16 +3980,17 @@ void SlaOutputDev::setFillAndStrokeForPDF(GfxState* state, PageItem* textNode) { if (textRenderingMode == 1 || textRenderingMode == 2 || textRenderingMode == 5 || textRenderingMode == 6) { CurrColorStroke = getColor(state->getStrokeColorSpace(), state->getStrokeColor(), &CurrStrokeShade); - if (textNode->isTextFrame()) { //fil;l colour sets the background colour for the frame not the fill colour fore the text + if (textNode->isTextFrame()) { //fill color sets the background color for the frame not the fill color fore the text textNode->setFillTransparency(1.0 - (state->getFillOpacity() > state->getStrokeOpacity() ? state->getFillOpacity() : state->getStrokeOpacity())); textNode->setLineTransparency(1.0); // this sets the transparency of the textbox border and we don't want to see it - textNode->setFillColor(CommonStrings::None); //TODO: Check if we ov erride the stroke colour with the fil,l colour when threre is a choice + textNode->setFillColor(CommonStrings::None); //TODO: Check if we override the stroke color with the fill color when there is a choice textNode->setLineColor(CommonStrings::None); textNode->setLineWidth(0);//line width doesn't effect drawing text, it creates a bounding box state->getTransformedLineWidth()); textNode->setFillBlendmode(getBlendMode(state)); textNode->setFillShade(CurrFillShade); } - else { + else + { textNode->setLineColor(CurrColorStroke); textNode->setLineWidth(0);//line width doesn't effect drawing text, it creates a bounding box state->getTransformedLineWidth()); textNode->setFillTransparency(1.0 - state->getFillOpacity() > state->getStrokeOpacity() ? state->getFillOpacity() : state->getStrokeOpacity()); @@ -4349,200 +4001,134 @@ void SlaOutputDev::setFillAndStrokeForPDF(GfxState* state, PageItem* textNode) { } } -/** - * \brief Updates current text position +/* + * Updates current text position and move to a position and or add a new glyph at the previous position. + * NOTE: The success == TextRegion::LineType::FAIL test is an invariant test that should never pass. if a rogue glyph is detected then it means there is a bug in the logic probably in TextRegion::addGlyphAtPoint or TextRegion::linearTest or TextRegion::moveToPoint + * FIXME: render the textframe, this should be done after the document has finished loading the current page so all the layout fix-ups can be put in-place first + * FIXME: textRegion needs to support moveBackOneGlyph instead of my manual implementation in this function. */ -void SlaOutputDev::updateTextPos(GfxState* state) { - QPointF new_position = QPointF(state->getCurX(), state->getCurY()); - //qDebug() << "updateTextPos() new_position: " << new_position << " lastxy: " << activeTextRegion.lastXY << " lineBaseXY: " << activeTextRegion.lineBaseXY << " origin: " << activeTextRegion.textRegioBasenOrigin; - //check to see if we are in a new text region - if (activeTextRegion.textRegioBasenOrigin == QPointF(-1, -1) || activeTextRegion.textRegionLines.size() == 0 || - (activeTextRegion.textRegionLines.size() == 1 && activeTextRegion.textRegionLines.back().glyphIndex == -1) )// && !isRegionConcurrent(new_position))) - { - //FIXME: Actually put this in the correct class - activeTextRegion.textRegioBasenOrigin = new_position; - // this ahould really get picked up by add first glyph, so check if that happens and if it does remove this. also we only want to call for the very first glyph of a new region, not every glyph for the begining of every line. - // don't make an arbitrary call to addGlyphAtPoint, instead pick the glyph up via addFirstGlyph - // we catch end of line glyphs further down anyway. - addChar = addCharModes[ADDFIRSTCHAR]; -# /* FIXME: Do we need this here? is there a better test we can use before calling it, can't we just get it picked up by add first glyph - if (glyphs.size() > 0) - { - addGlyphAtPoint(glyphs.back().position, glyphs.back()); - } - */ +void SlaOutputDev::updateTextPos(GfxState* state) +{ + QPointF newPosition = QPointF(state->getCurX(), state->getCurY()); + TextRegion* activeTextRegion = &m_textRecognition.activeTextRegion; + if (activeTextRegion->isNew() + ) + { + activeTextRegion->textRegioBasenOrigin = newPosition; + m_textRecognition.setCharMode(PdfTextRecognition::AddCharMode::ADDFIRSTCHAR); } else { - // a delayed call using the last glyph that was put onto the stack. it will be a glyph situated on the far side bounds of the text region - // only add if we are on a new line, so the y position will be shifted but the glyph.y and textregion.y should marry - if (activeTextRegion.coLinera(activeTextRegion.lastXY.y(), activeTextRegion.glyphs.back().position.y()) && - !activeTextRegion.coLinera(new_position.y(), activeTextRegion.glyphs.back().position.y()) //&& - //activeTextRegion.closeToX(new_position.x(), activeTextRegion.glyphs.back().position.x()) - ) + // if we've will move to a new line or new text region then update the current text region with the last glyph, this ensures all textlines and textregions have terminating glyphs. + if (m_textRecognition.isNewLineOrRegion(newPosition)) { - if (activeTextRegion.addGlyphAtPoint(activeTextRegion.glyphs.back().position, activeTextRegion.glyphs.back()) == TextRegion::FAIL) { - qDebug("FIXME: Rogue glyph detected, this should never happen because the copuror should move before glyphs in new regions are added."); - /* - // we have an out of place glyph being added. This shouldn't ever really happen as the cursor is always moved before glyphs are added - // still failsafe - // FIXME: This should be done when the document has finished loading so layout fixups can be put inplace - if (activeTextRegion.textRegionLines.size() > 0) - { - renderTextFrame(); - } - - //Create and initilize a new TextRegion - activeTextRegion = TextRegion(); - m_textRegions.push_back(activeTextRegion); - - //initialize m_activeTextRegion based on newGlyphPoint and new_glyph - activeTextRegion.addGlyphAtPoint(glyphs.back().position, glyphs.back()); - addChar = addCharModes[ADDBASICCHAR]; - */ - }; + QPointF glyphPosition = activeTextRegion->lastXY; + activeTextRegion->lastXY.setX(activeTextRegion->lastXY.x() - activeTextRegion->glyphs.back().dx); + if (activeTextRegion->addGlyphAtPoint(glyphPosition, activeTextRegion->glyphs.back()) == TextRegion::LineType::FAIL) + qDebug("FIXME: Rogue glyph detected, this should never happen because the cursor should move before glyphs in new regions are added."); +#ifdef DEBUG_TEXT_IMPORT + else + qDebug() << "Newline should be next"; +#endif } } - TextRegion::FRAMEWORKLINETESTS lineTestResult = activeTextRegion.moveToPoint(new_position); - if (lineTestResult == TextRegion::FAIL) { - //This should never happen now, I could pass the result out and have the caller implement creating a new text rewgion - - // FIXME: redner the textframe, this should be done after the document has finished loading so all the layout fixups can be put inplace first - renderTextFrame(); - - //Create and initilize a new TextRegion - activeTextRegion = TextRegion(); - m_textRegions.push_back(activeTextRegion); - addChar = addCharModes[ADDFIRSTCHAR]; + TextRegion::LineType lineTestResult = activeTextRegion->moveToPoint(newPosition); + if (lineTestResult == TextRegion::LineType::FAIL) + { + #ifdef DEBUG_TEXT_IMPORT + qDebug("updateTextPos: renderTextFrame() + m_textRecognition.addTextRegion()"); + #endif + renderTextFrame(); + m_textRecognition.addTextRegion(); updateTextPos(state); - - /*TOPDO: DXo we need to initlize thease - m_activeTextRegion.textRegioBasenOrigin = newPoint; - m_activeTextRegion._lineBaseXY = newPoint; - m_activeTextRegion._lastXY = newPoint; - */ } } - +/* +* render the textregion to a new PageItem::TextFrame, currently some hackjish defaults have been implemented there are a number of FIXMEs and TODOs +* FIXME: Paragraphs need to be implemented properly this needs to be applied to the charstyle of the default pstyle +* FIXME xcord and ycord need to be set properly based on GfxState and the page transformation matrix +* TODO: Implement paragraph styles +* TODO: Implement character styles and fonts. +* TODO Decide if we should be setting the clipshape of the POoLine values as is the case with other import implementations +*/ void SlaOutputDev::renderTextFrame() { - //TODO: Implement, this should all be based on the framework and using m_activeTextRegion //qDebug() << "_flushText() m_doc->currentPage()->xOffset():" << m_doc->currentPage()->xOffset(); - // Ignore empty strings - if (activeTextRegion.glyphs.empty()) { - // We don't clear the glyphs any more or at least until the whole page has been rendred glyphs.clear(); + auto activeTextRegion = &m_textRecognition.activeTextRegion; + if (activeTextRegion->glyphs.empty()) return; - } - //FIXME: This is redundant, should be using the framework not the first glyph. - //const PdfGlyph& first_glyph = activeTextRegion.glyphs[activeTextRegion.textRegionLines[0].glyphIndex];// (*i); - // TODO: Use the framework for this, not currently supported - /* - int render_mode = first_glyph.render_mode; - // Ignore invisible characters - if (render_mode == 3) { - // We don't clear the glyphs any more or at least until the whole page has been rendred //_glyphs.clear(); - return; - } - */ - //FIXME: Use the framework for positioning not the first glyph - qreal xCoor = m_doc->currentPage()->xOffset() + activeTextRegion.textRegioBasenOrigin.x(); - qreal yCoor = m_doc->currentPage()->initialHeight() - (m_doc->currentPage()->yOffset() + (double)activeTextRegion.textRegioBasenOrigin.y() + activeTextRegion.lineSpacing); // don't know if y is top down or bottom up - double lineWidth = 0.0; - qDebug() << "rendering new frame at:" << xCoor << "," << yCoor << " With lineheight of: " << activeTextRegion.modeHeigth << "Height:" << activeTextRegion.maxHeight << " Width:" << activeTextRegion.maxWidth; - /* colours don't get reset to CommonStrings::None often enough.*/ - int z = m_doc->itemAdd(PageItem::TextFrame, PageItem::Rectangle, xCoor, yCoor, 40, 40, 0, CommonStrings::None, CommonStrings::None /* this->CurrColorStroke*/);//, PageItem::ItemKind::InlineItem); + qreal xCoor = m_doc->currentPage()->xOffset() + activeTextRegion->textRegioBasenOrigin.x(); + qreal yCoor = m_doc->currentPage()->initialHeight() - (m_doc->currentPage()->yOffset() + (double)activeTextRegion->textRegioBasenOrigin.y() + activeTextRegion->lineSpacing); // don't know if y is top down or bottom up + qreal lineWidth = 0.0; + #ifdef DEBUG_TEXT_IMPORT + qDebug() << "rendering new frame at:" << xCoor << "," << yCoor << " With lineheight of: " << activeTextRegion->lineSpacing << "Height:" << activeTextRegion->maxHeight << " Width:" << activeTextRegion->maxWidth; + #endif + int z = m_doc->itemAdd(PageItem::TextFrame, PageItem::Rectangle, xCoor, yCoor, 40, 40, 0, CommonStrings::None, CommonStrings::None ); PageItem* textNode = m_doc->Items->at(z); ParagraphStyle& pStyle = (ParagraphStyle&)textNode->itemText.defaultStyle(); - // set some hackish parameters up at first, line spacing can be calculated from the cursor position changes pStyle.setLineSpacingMode(pStyle.AutomaticLineSpacing); pStyle.setHyphenationMode(pStyle.AutomaticHyphenation); + finishItem(textNode); + //_setFillAndStrokeForPdf(state, text_node); + textNode->ClipEdited = true; + textNode->FrameType = 3; + textNode->setLineEnd(PLineEnd); + textNode->setLineJoin(PLineJoin); + textNode->setTextFlowMode(PageItem::TextFlowDisabled); + textNode->setLineTransparency(1.0); + textNode->setFillColor(CommonStrings::None); + textNode->setLineColor(CommonStrings::None); + textNode->setLineWidth(0); + textNode->setFillShade(CurrFillShade); - // TODO: Implement thease using the framework - finishItem(textNode); - // FIXME: Implement thease using the framework - //_setFillAndStrokeForPdf(state, text_node); - //FIXME: Here's some dummy code for now with sednsible defaults, looks like state wasn't even needed - if (true) - { - textNode->ClipEdited = true; - textNode->FrameType = 3; - textNode->setLineEnd(PLineEnd); - textNode->setLineJoin(PLineJoin); - textNode->setTextFlowMode(PageItem::TextFlowDisabled); - - //textNode->setFillTransparency(1.0); - textNode->setLineTransparency(1.0); // this ssets the transparency of the textbox border and we don't want to see it - textNode->setFillColor(CommonStrings::None); - textNode->setLineColor(CommonStrings::None); - textNode->setLineWidth(0);//line width doesn't effect drawing text, it creates a bounding box state->getTransformedLineWidth()); - textNode->setFillShade(CurrFillShade); - } - - - // Set text matrix... This need to be done so that the globaal world view that we rite out glyphs to is transformed correctly by the context matrix for each glyph, possibly anyhow. - /* FIXME: Setting the text matrix isn't supp;orted at the moment + /* Oliver Stieber 2020-06-11 Set text matrix... This need to be done so that the global world view that we rite out glyphs to is transformed correctly by the context matrix for each glyph, possibly anyhow. + needs the way in which we are handling transformations for the page to be more concrete before this code can be implemented either here or somewhere else + FIXME: Setting the text matrix isn't supported at the moment QTransform text_transform(_text_matrix); text_transform.setMatrix(text_transform.m11(), text_transform.m12(), 0, text_transform.m21(), text_transform.m22(), 0, - first_glyph.position.x(), first_glyph.position.y(), 1); - */ - /* todo, set the global transform + first_glyph.position.x(), first_glyph.position.y(), 1); gchar *transform = sp_svg_transform_write(text_transform); text_node->setAttribute("transform", transform); g_free(transform); - */ - /*set the default charstyle to the style of the glyph, this needss fleshing out a little */ + */ int shade = 100; - //TODO: This needs to come from the framework - //QString CurrColorText = getColor(state->getFillColorSpace(), state->getFillColor(), &shade); - //TODO: replace this with the framework - //applyTextStyleToCharStyle(pStyle.charStyle(), _glyphs[0].style->getFont().family(), CurrColorText, _glyphs[0].style->getFont().pointSizeF());// *_font_scaling); - CharStyle& cStyle = (CharStyle&)pStyle.charStyle(); + /* + * This code sets the font and style in a very simplistic way, it's been commented out as it needs to be updated to be used within PdfTextRecognition &co. + QString CurrColorText = getColor(state->getFillColorSpace(), state->getFillColor(), &shade); + applyTextStyleToCharStyle(pStyle.charStyle(), _glyphs[0].style->getFont().family(), CurrColorText, _glyphs[0].style->getFont().pointSizeF());// *_font_scaling); + */ + CharStyle& cStyle = static_cast(pStyle.charStyle()); cStyle.setScaleH(1000.0); cStyle.setScaleV(1000.0); cStyle.setHyphenChar(SpecialChars::BLANK.unicode()); textNode->itemText.setDefaultStyle(pStyle); textNode->invalid = true; - activeTextRegion.renderToTextFrame(textNode, pStyle); - //FIXME: Paragraphs need to be implemented properly this needs to be applied to the charstyle of the default pstyle + activeTextRegion->renderToTextFrame(textNode); textNode->itemText.insertChars(SpecialChars::PARSEP, true); - //Set the shape so we don't clip all the text away. + /* + * This code can be used to set PoLine instead of setting the FrameShape if setting the PoLine is the more correct way of doing things. + * I have no idea of what the PoLine is at this time except for it changes when the shape is set and appears to be unit scales as opposed to percentage scaled FPointArray boundingBoxShape; boundingBoxShape.resize(0); boundingBoxShape.svgInit(); - - double bbosdoubles[32] = { 0,0 - ,0,0 - ,100,0 - ,100,0 - ,100,0 - ,100,0 - ,100,100 - ,100,100 - ,100,100 - ,100,100 - ,0,100 - ,0,100 - ,0,100 - ,0,100 - ,0,0 - ,0,0 - }; - boundingBoxShape.svgMoveTo(bbosdoubles[0], bbosdoubles[1]); + //doubles to create a shape, it's 100% textframe width by 100% textframe height + + boundingBoxShape.svgMoveTo(TextRegion::boundingBoxShape[0], TextRegion::boundingBoxShape[1]); for (int a = 0; a < 16; a += 2) { - boundingBoxShape.append(FPoint(bbosdoubles[a * 2], bbosdoubles[a * 2 + 1])); + boundingBoxShape.append(FPoint(TextRegion::boundingBoxShape[a * 2], TextRegion::boundingBoxShape[a * 2 + 1])); } boundingBoxShape.scale(textNode->width() / 100.0, textNode->height() / 100.0); - - textNode->SetFrameShape(32, bbosdoubles); + */ + textNode->SetFrameShape(32, TextRegion::boundingBoxShape); textNode->ContourLine = textNode->PoLine.copy(); m_doc->Items->removeLast(); @@ -4552,93 +4138,22 @@ void SlaOutputDev::renderTextFrame() m_groupStack.top().Items.append(textNode); applyMask(textNode); } - } -/*code mostly taken from importodg.cpp which also supports some line styles and more fill options etc...*/ -//FIXME: This needs to be implemented based on the framework -void SlaOutputDev::finishItem(PageItem* item) { +/* +* code mostly taken from importodg.cpp which also supports some line styles and more fill options etc... +*/ +void SlaOutputDev::finishItem(PageItem* item) +{ item->ClipEdited = true; item->FrameType = 3; - - //this requires that PoLine is set - //FPoint wh = getMaxClipF(&item->PoLine); - //item->setWidthHeight(wh.x(), wh.y()); - //item->Clip = flattenPath(item->PoLine, item->Segments); + /*code can be enabled when PoLine is set or when the shape is set as that sets PoLine + FPoint wh = getMaxClipF(&item->PoLine); + item->setWidthHeight(wh.x(), wh.y()); + item->Clip = flattenPath(item->PoLine, item->Segments); + */ item->OldB2 = item->width(); item->OldH2 = item->height(); item->updateClip(); item->OwnPage = m_doc->OnPage(item); - - //item->setFillTransparency(1.0 - state->getFillOpacity() > state->getStrokeOpacity() ? state->getFillOpacity() : state->getStrokeOpacity()); - //item->setLineTransparency(1.0); -} - - -void AddFirstChar::addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) -{ - //qDebug() << "addChar() '" << u << " : " << uLen; - /* - bool is_space = (uLen == 1 && u[0] == 32); - // Skip beginning space - if (is_space) { - return; - } - */ - PdfGlyph new_glyph; - //new_glyph.is_space = false; - new_glyph.position = QPointF(x - originX, y - originY); - new_glyph.dx = dx; - new_glyph.dy = dy; - - m_slaOutputDev->addChar = m_slaOutputDev->addCharModes[SlaOutputDev::ADDBASICCHAR]; - - // Convert the character to UTF-16 since that's our SVG document's encoding - for (int i = 0; i < uLen; i++) { - new_glyph.code += (char16_t)u[i]; - } - - new_glyph.rise = state->getRise(); - m_slaOutputDev->activeTextRegion.glyphs.push_back(new_glyph); - - //only need to be called for the very first point - if (m_slaOutputDev->activeTextRegion.addGlyphAtPoint(QPointF(x, y), new_glyph) == TextRegion::FAIL) { - qDebug("FIXME: Rogue glyph detected, this should never happen because the copuror should move before glyphs in new regions are added."); - } -} - -void AddBasicChar::addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) -{ - //qDebug() << "addChar() '" << u << " : " << uLen; - // TODO: Compleatly gut this function so all that it ends up doing is placing a character and some positioning information on a stack get rid of all the other junk as it's not needed - /* - bool is_space = (uLen == 1 && u[0] == 32); - - // Allow only one space in a row - if (is_space && - (m_slaOutputDev->activeTextRegion.glyphs[m_slaOutputDev->activeTextRegion.glyphs.size() - 1].code == QChar::SpecialCharacter::Space)) { - return; - } - */ - PdfGlyph new_glyph; - //new_glyph.is_space = is_space; - new_glyph.position = QPoint(x - originX, y - originY); - new_glyph.dx = dx; - new_glyph.dy = dy; - - // Convert the character to UTF-16 since that's our SVG document's encoding - for (int i = 0; i < uLen; i++) { - new_glyph.code += (char16_t)u[i]; - } - - new_glyph.rise = state->getRise(); - m_slaOutputDev->activeTextRegion.glyphs.push_back(new_glyph); -} - -void AddCharWithPreviousStyle::addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) -{ -} - -void AddCharWithNewStyle::addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) -{ } diff --git a/scribus/plugins/import/pdf/slaoutput.h b/scribus/plugins/import/pdf/slaoutput.h index 83821b668..e06c77c87 100644 --- a/scribus/plugins/import/pdf/slaoutput.h +++ b/scribus/plugins/import/pdf/slaoutput.h @@ -29,6 +29,7 @@ for which a new license (GPL+exception) is in place. #include "scribusview.h" #include "selection.h" #include "vgradient.h" +#include "pdftextrecognition.h" #if POPPLER_ENCODED_VERSION < POPPLER_VERSION_ENCODE(0, 73, 0) #include @@ -153,73 +154,7 @@ class AnoOutputDev : public OutputDev QStringList *m_importedColors; }; -/* PDF TextBox Framework */ -/* -* Holds all the dtails for each glyph in the text imported from the pdf file. -* -*/ -struct PdfGlyph { - QPointF position; // Absolute glyph coords - double dx; // X advance value - double dy; // Y advance value - double rise; // Text rise parameter - QString code; // UTF-16 coded character but we only store and use UTF-8, the slternstive is const char * for utf8 so far as qt is concerned - bool is_space; -}; - -class TextRegionLine -{ -public: - qreal maxHeight = -1; - qreal modeHeigth = -1; - qreal width = -1; - int glyphIndex = -1; - QPointF baseOrigin = QPointF(-1, -1); - std::vector segments = std::vector(); - -}; - -class TextRegion { -public: - enum FRAMEWORKLINETESTS { - FIRSTPOINT, - SAMELINE, - STYLESUPERSCRIPT, - STYLENORMALRETURN, - STYLEBELOWBASELINE, - NEWLINE, - ENDOFLINE, //TODO: Implement an end of line test - FAIL - }; - - QPointF textRegioBasenOrigin = QPointF(-1, -1); - qreal maxHeight = -1; - qreal modeHeigth = -1; - qreal lineSpacing = -1; - std::vector textRegionLines = std::vector(); - qreal maxWidth = -1; - QPointF lineBaseXY = QPointF(-1, -1); //updated with the best match left value from all the textRegionLines and the best bottom value from the textRegionLines.segments; - QPointF lastXY = QPointF(-1, -1); - static bool coLinera(qreal a, qreal b); - bool closeToX(qreal x1, qreal x2); - bool closeToY(qreal y1, qreal y2); - bool adjunctLesser(qreal testY, qreal lastY, qreal baseY); - bool adjunctGreater(qreal testY, qreal lastY, qreal baseY); - TextRegion::FRAMEWORKLINETESTS linearTest(QPointF point, bool xInLimits, bool yInLimits); - TextRegion::FRAMEWORKLINETESTS isRegionConcurrent(QPointF newPoint); - TextRegion::FRAMEWORKLINETESTS moveToPoint(QPointF newPoint); - TextRegion::FRAMEWORKLINETESTS addGlyphAtPoint(QPointF newGlyphPoint, PdfGlyph new_glyph); - void renderToTextFrame(PageItem* textNode, ParagraphStyle& pStyle); - std::vector glyphs; //this may replace some of the other settings or it may not, certainly not font as text gets flushed if the font changes -}; - -class AddCharInterface -{ -public: - // Pure Virtual Function - virtual void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) = 0; -}; class SlaOutputDev : public OutputDev { @@ -299,7 +234,7 @@ class SlaOutputDev : public OutputDev void endMarkedContent(GfxState *state) override; void markPoint(POPPLER_CONST char *name) override; void markPoint(POPPLER_CONST char *name, Dict *properties) override; - + //----- image drawing void drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, GBool interpolate, GBool inlineImg) override; @@ -337,26 +272,12 @@ class SlaOutputDev : public OutputDev void beginTextObject(GfxState *state) override; void endTextObject(GfxState *state) override; void drawChar(GfxState *state, double /*x*/, double /*y*/, double /*dx*/, double /*dy*/, double /*originX*/, double /*originY*/, CharCode /*code*/, int /*nBytes*/, POPPLER_CONST_082 Unicode * /*u*/, int /*uLen*/) override; + void drawCharAsVector(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, POPPLER_CONST_082 Unicode* u, int uLen); GBool beginType3Char(GfxState * /*state*/, double /*x*/, double /*y*/, double /*dx*/, double /*dy*/, CharCode /*code*/, POPPLER_CONST_082 Unicode * /*u*/, int /*uLen*/) override; void endType3Char(GfxState * /*state*/) override; void type3D0(GfxState * /*state*/, double /*wx*/, double /*wy*/) override; void type3D1(GfxState * /*state*/, double /*wx*/, double /*wy*/, double /*llx*/, double /*lly*/, double /*urx*/, double /*ury*/) override; - //text as text - - AddCharInterface* addChar = nullptr; - - enum ADDCHARMODE { - ADDFIRSTCHAR, - ADDBASICCHAR, - ADDCHARWITHNEWSTYLE, - ADDCHARWITHPREVIOUSSTYLE - }; - - std::map addCharModes; - - TextRegion& activeTextRegion = TextRegion(); //faster than calling back on the vector all the time. - //----- form XObjects void drawForm(Ref /*id*/) override { qDebug() << "Draw Form"; } @@ -390,7 +311,7 @@ class SlaOutputDev : public OutputDev void createImageFrame(QImage& image, GfxState *state, int numColorComponents); - //PDF Textbox framework + //PDF Textbox framework void setFillAndStrokeForPDF(GfxState* state, PageItem* text_node); void updateTextPos(GfxState* state) override; void renderTextFrame(); @@ -462,63 +383,8 @@ class SlaOutputDev : public OutputDev QHash > m_radioMap; QHash m_radioButtons; int m_actPage; - //PDF Textbox framework - std::vector m_textRegions = std::vector(); -}; - -class AddFirstChar : public AddCharInterface -{ - -public: - AddFirstChar(SlaOutputDev *slaOutputDev) - { - m_slaOutputDev = slaOutputDev; - } - void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) override; -private: - SlaOutputDev* m_slaOutputDev = nullptr; -}; - -class AddBasicChar : public AddCharInterface -{ - -public: - AddBasicChar(SlaOutputDev* slaOutputDev) - { - m_slaOutputDev = slaOutputDev; - } - void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) override; -private: - SlaOutputDev* m_slaOutputDev = nullptr; -}; - -// TODO: implement these addchar definitions so that they can handle changes in style, font, text micro positioning, scaling, matrix etc... -class AddCharWithNewStyle : public AddCharInterface -{ - -public: - AddCharWithNewStyle(SlaOutputDev* slaOutputDev) - { - m_slaOutputDev = slaOutputDev; - } - void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) override; -private: - SlaOutputDev* m_slaOutputDev = nullptr; -}; - -// TODO: implement these addchar definitions so that they can handle changes in style, font, text micro positioning, scaling, matrix etc... -class AddCharWithPreviousStyle : public AddCharInterface -{ - -public: - AddCharWithPreviousStyle(SlaOutputDev* slaOutputDev) - { - m_slaOutputDev = slaOutputDev; - } - void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) override; -private: - SlaOutputDev* m_slaOutputDev = nullptr; + PdfTextRecognition m_textRecognition = {}; }; #endif diff --git a/scribus/plugins/import/xps/xpsimportoptions.h b/scribus/plugins/import/xps/xpsimportoptions.h index e921ca70c..dda1485cc 100644 --- a/scribus/plugins/import/xps/xpsimportoptions.h +++ b/scribus/plugins/import/xps/xpsimportoptions.h @@ -19,7 +19,7 @@ class XpsImportOptions : public QDialog Q_OBJECT public: - explicit XpsImportOptions(QWidget *parent = 0); + explicit XpsImportOptions(QWidget* parent = nullptr); ~XpsImportOptions(); void setUpOptions(const QString& fileName, int actPage, int numPages, bool interact); QString getPagesString(); diff --git a/scribus/plugins/imposition/imposition.h b/scribus/plugins/imposition/imposition.h index a236f9f95..c2ee93fc9 100644 --- a/scribus/plugins/imposition/imposition.h +++ b/scribus/plugins/imposition/imposition.h @@ -41,7 +41,7 @@ class Imposition : public QDialog,Ui::ImpositionBase Q_OBJECT public: - Imposition(QWidget* parent = 0, ScribusDoc* doc = 0); + Imposition(QWidget* parent = nullptr, ScribusDoc* doc = 0); virtual ~Imposition(); double unitRatio; diff --git a/scribus/plugins/picbrowser/imagedialog.h b/scribus/plugins/picbrowser/imagedialog.h index 81d4afcdd..b2cc37686 100644 --- a/scribus/plugins/picbrowser/imagedialog.h +++ b/scribus/plugins/picbrowser/imagedialog.h @@ -23,7 +23,7 @@ class Imagedialog : public QDialog, Ui::imagedialog Q_OBJECT public: - Imagedialog ( const QString& imageFile, ScribusDoc* doc, QWidget *parent = 0 ); + Imagedialog ( const QString& imageFile, ScribusDoc* doc, QWidget* parent = nullptr ); void resizeEvent ( QResizeEvent * event ); ScImage image; diff --git a/scribus/plugins/picbrowser/multicombobox.h b/scribus/plugins/picbrowser/multicombobox.h index b281fa429..f86aaea61 100644 --- a/scribus/plugins/picbrowser/multicombobox.h +++ b/scribus/plugins/picbrowser/multicombobox.h @@ -18,7 +18,7 @@ class multiComboboxModel : public QStandardItemModel { Q_OBJECT public: - multiComboboxModel ( QObject* parent = 0 ); + multiComboboxModel ( QObject* parent = nullptr ); Qt::ItemFlags flags ( const QModelIndex& index ) const; }; @@ -27,7 +27,7 @@ class multiView : public QListView { Q_OBJECT public: - multiView ( QWidget* parent = 0 ); + multiView ( QWidget* parent = nullptr ); multiView ( multiCombobox* parent ); bool eventFilter ( QObject* object, QEvent* event ); @@ -40,7 +40,7 @@ class multiCombobox : public QComboBox { Q_OBJECT public: - multiCombobox ( QWidget *parent = 0 ); + multiCombobox ( QWidget* parent = nullptr ); void setCheckstate ( int index, int checked ); int checkstate ( int index ); diff --git a/scribus/plugins/picbrowser/picturebrowser.h b/scribus/plugins/picbrowser/picturebrowser.h index fb82840bf..cb2d69ede 100644 --- a/scribus/plugins/picbrowser/picturebrowser.h +++ b/scribus/plugins/picbrowser/picturebrowser.h @@ -99,7 +99,7 @@ class PictureBrowser : public QDialog, Ui::PictureBrowser Q_OBJECT public: - PictureBrowser ( ScribusDoc* doc, QWidget *parent = 0 ); + PictureBrowser ( ScribusDoc* doc, QWidget* parent = nullptr ); ~PictureBrowser(); void closeEvent(QCloseEvent *e); void changedDocument ( ScribusDoc* doc ); diff --git a/scribus/plugins/picbrowser/previewimage.h b/scribus/plugins/picbrowser/previewimage.h index ba258b5ee..1c3ea70c6 100644 --- a/scribus/plugins/picbrowser/previewimage.h +++ b/scribus/plugins/picbrowser/previewimage.h @@ -142,7 +142,7 @@ class PreviewImagesModel : public QAbstractListModel Q_OBJECT public: - PreviewImagesModel ( QObject *parent = 0 ); + PreviewImagesModel ( QObject* parent = nullptr ); //saves pointer to calling PictureBrowser instance, for later access PreviewImagesModel ( PictureBrowser *parent ); diff --git a/scribus/plugins/scriptplugin/objprinter.cpp b/scribus/plugins/scriptplugin/objprinter.cpp index b344d994c..6fb5b34be 100644 --- a/scribus/plugins/scriptplugin/objprinter.cpp +++ b/scribus/plugins/scriptplugin/objprinter.cpp @@ -442,8 +442,8 @@ static PyObject *Printer_print(Printer *self) bool printDone = false; if (PrinterUtil::getDefaultSettings(prn, options.devMode)) { - ScPrintEngine_GDI winPrint; - printDone = winPrint.print(*currentDoc, options); + ScPrintEngine_GDI winPrint(*currentDoc); + printDone = winPrint.print(options); } if (!printDone) PyErr_SetString(PyExc_SystemError, "Printing failed"); diff --git a/scribus/plugins/scriptplugin/pconsole.h b/scribus/plugins/scriptplugin/pconsole.h index 13cdfc549..784541b97 100644 --- a/scribus/plugins/scriptplugin/pconsole.h +++ b/scribus/plugins/scriptplugin/pconsole.h @@ -30,7 +30,7 @@ class PythonConsole : public QMainWindow, public Ui::PythonConsole Q_OBJECT public: - PythonConsole( QWidget* parent = 0); + PythonConsole( QWidget* parent = nullptr); ~PythonConsole(); void setFonts(); diff --git a/scribus/plugins/scriptplugin/prefs_scripter.h b/scribus/plugins/scriptplugin/prefs_scripter.h index 74daeb2e6..b6ed57678 100644 --- a/scribus/plugins/scriptplugin/prefs_scripter.h +++ b/scribus/plugins/scriptplugin/prefs_scripter.h @@ -17,7 +17,7 @@ class Prefs_Scripter : public Prefs_Pane, Ui::Prefs_Scripter Q_OBJECT public: - Prefs_Scripter(QWidget* parent=0); + Prefs_Scripter(QWidget* parent=nullptr); ~Prefs_Scripter(); void restoreDefaults(struct ApplicationPrefs *prefsData) override; diff --git a/scribus/plugins/scriptplugin_py2x/objprinter.cpp b/scribus/plugins/scriptplugin_py2x/objprinter.cpp index 3f9778fc5..be270ff20 100644 --- a/scribus/plugins/scriptplugin_py2x/objprinter.cpp +++ b/scribus/plugins/scriptplugin_py2x/objprinter.cpp @@ -442,8 +442,8 @@ static PyObject *Printer_print(Printer *self) bool printDone = false; if (PrinterUtil::getDefaultSettings(prn, options.devMode)) { - ScPrintEngine_GDI winPrint; - printDone = winPrint.print(*currentDoc, options); + ScPrintEngine_GDI winPrint(*currentDoc); + printDone = winPrint.print(options); } if (!printDone) PyErr_SetString(PyExc_SystemError, "Printing failed"); diff --git a/scribus/plugins/scriptplugin_py2x/pconsole.h b/scribus/plugins/scriptplugin_py2x/pconsole.h index 9e797a506..c0a18e992 100644 --- a/scribus/plugins/scriptplugin_py2x/pconsole.h +++ b/scribus/plugins/scriptplugin_py2x/pconsole.h @@ -30,7 +30,7 @@ class PythonConsole : public QMainWindow, public Ui::PythonConsole Q_OBJECT public: - PythonConsole( QWidget* parent = 0); + PythonConsole( QWidget* parent = nullptr); ~PythonConsole(); void setFonts(); diff --git a/scribus/plugins/scriptplugin_py2x/prefs_scripter.h b/scribus/plugins/scriptplugin_py2x/prefs_scripter.h index 59a59bb68..eac512d49 100644 --- a/scribus/plugins/scriptplugin_py2x/prefs_scripter.h +++ b/scribus/plugins/scriptplugin_py2x/prefs_scripter.h @@ -17,7 +17,7 @@ class Prefs_Scripter : public Prefs_Pane, Ui::Prefs_Scripter Q_OBJECT public: - Prefs_Scripter(QWidget* parent=0); + Prefs_Scripter(QWidget* parent=nullptr); ~Prefs_Scripter(); void restoreDefaults(struct ApplicationPrefs *prefsData) override; diff --git a/scribus/plugins/short-words/prefs_shortwords.h b/scribus/plugins/short-words/prefs_shortwords.h index ca0e4a184..3a33967e0 100644 --- a/scribus/plugins/short-words/prefs_shortwords.h +++ b/scribus/plugins/short-words/prefs_shortwords.h @@ -16,7 +16,7 @@ class Prefs_ShortWords : public Prefs_Pane, Ui::Prefs_ShortWords Q_OBJECT public: - Prefs_ShortWords(QWidget* parent=0); + Prefs_ShortWords(QWidget* parent=nullptr); ~Prefs_ShortWords(); void restoreDefaults(struct ApplicationPrefs *prefsData) override; diff --git a/scribus/plugins/short-words/swdialog.h b/scribus/plugins/short-words/swdialog.h index 170c127cf..aaba51dec 100644 --- a/scribus/plugins/short-words/swdialog.h +++ b/scribus/plugins/short-words/swdialog.h @@ -40,7 +40,7 @@ class SWDialog : public QDialog, public Ui::SWDialog Q_OBJECT public: - SWDialog(QWidget* parent = 0); + SWDialog(QWidget* parent = nullptr); ~SWDialog(); int actionSelected(); diff --git a/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.cpp b/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.cpp index 8545c133a..fbdd542c8 100644 --- a/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.cpp +++ b/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.cpp @@ -171,7 +171,7 @@ MeshDistortionDialog::MeshDistortionDialog(QWidget* parent, ScribusDoc *doc) : Q if(vi == 0 && ui == 0) base = Geom::Point(w4, w4); double dl = dot((handles[corner+4*i] - base), dir)/dot(dir,dir); - sb2[dim][i][corner] = dl/(ww/2.0)*pow(4.0f,((int)(ui+vi))); + sb2[dim][i][corner] = dl/(ww/2.0)*pow(4.0F,((int)(ui+vi))); } } } @@ -495,7 +495,7 @@ void MeshDistortionDialog::updateMesh(bool gridOnly) if(vi == 0 && ui == 0) base = Geom::Point(w4, w4); double dl = dot((handles[corner+4*i] - base), dir)/dot(dir,dir); - sb2[dim][i][corner] = dl/(ww/2.0)*pow(4.0f,((int)(ui+vi))); + sb2[dim][i][corner] = dl/(ww/2.0)*pow(4.0F,((int)(ui+vi))); } } } diff --git a/scribus/pslib.cpp b/scribus/pslib.cpp index c352b4f74..1b73726f0 100644 --- a/scribus/pslib.cpp +++ b/scribus/pslib.cpp @@ -207,13 +207,16 @@ void PSPainter::drawRect(QRectF rect) void PSPainter::drawLine(QPointF start, QPointF end) { - double h, s, v, k; QVector dum; dum.clear(); m_ps->PS_save(); applyTransform(); if (fillColor().color != CommonStrings::None) { + double h = 0.0; + double s = 0.0; + double v = 0.0; + double k = 0.0; m_ps->PS_setcapjoin(Qt::FlatCap, Qt::MiterJoin); m_ps->PS_setdash(Qt::SolidLine, 0, dum); m_ps->SetColor(fillColor().color,fillColor().shade, &h, &s, &v, &k); diff --git a/scribus/schelptreemodel.h b/scribus/schelptreemodel.h index 3b4701ab0..d023191a4 100644 --- a/scribus/schelptreemodel.h +++ b/scribus/schelptreemodel.h @@ -56,7 +56,7 @@ class ScHelpTreeModel : public TreeModel Q_OBJECT public: - ScHelpTreeModel(const QString &dataFile, const QString &col1name, const QString &col2name, QMap* indexToBuild, QObject *parent = 0); + ScHelpTreeModel(const QString &dataFile, const QString &col1name, const QString &col2name, QMap* indexToBuild, QObject* parent = nullptr); ~ScHelpTreeModel() {}; void addRow(const QString&, const QString&, int i); diff --git a/scribus/scimagecachedir.h b/scribus/scimagecachedir.h index 267f216a0..513ab9550 100644 --- a/scribus/scimagecachedir.h +++ b/scribus/scimagecachedir.h @@ -42,7 +42,7 @@ class ScImageCacheDir : public QObject public: typedef unsigned int AccessCounter; - ScImageCacheDir(const QString& dir, ScImageCacheDir *parent = 0, bool scanFiles = false, const QStringList & suffixList = QStringList()); + ScImageCacheDir(const QString& dir, ScImageCacheDir* parent = nullptr, bool scanFiles = false, const QStringList & suffixList = QStringList()); ~ScImageCacheDir(); ScImageCacheDir *newSubDir(const QString & dir, bool scanFiles = false, const QStringList & suffixList = QStringList()); const QString & name() const { return m_name; } diff --git a/scribus/scimagecachefile.h b/scribus/scimagecachefile.h index eabf46028..f1d915716 100644 --- a/scribus/scimagecachefile.h +++ b/scribus/scimagecachefile.h @@ -39,7 +39,7 @@ class ScImageCacheFile : public QObject Q_OBJECT public: - ScImageCacheFile(const QString & name, ScImageCacheDir *parent = 0); + ScImageCacheFile(const QString & name, ScImageCacheDir* parent = nullptr); ~ScImageCacheFile(); QString path(bool relative = false) const; diff --git a/scribus/sclistboxpixmap.h b/scribus/sclistboxpixmap.h index bdd374019..e6fb4ef97 100644 --- a/scribus/sclistboxpixmap.h +++ b/scribus/sclistboxpixmap.h @@ -94,14 +94,13 @@ void ScListBoxPixmap::paint(QPainter * qpainter, const QSty int yPos = (itemHeight - pmap->height()) / 2; qpainter->drawPixmap(option.rect.x() + 3, option.rect.y() + yPos, *pmap); } + if (option.state & QStyle::State_Selected) - qpainter->setBrush(option.palette.highlightedText()); + qpainter->setPen(QPen(option.palette.highlightedText(), 0)); else - qpainter->setBrush(QBrush(Qt::black)); - qpainter->setPen(Qt::black); + qpainter->setPen(QPen(option.palette.text(), 0)); QString txt(index.data(Qt::DisplayRole).toString()); - if (!txt.isEmpty()) { QFontMetrics fm = qpainter->fontMetrics(); diff --git a/scribus/scprintengine.h b/scribus/scprintengine.h index edf21065f..953c46eaa 100644 --- a/scribus/scprintengine.h +++ b/scribus/scprintengine.h @@ -16,19 +16,19 @@ class ScPrintEngine : public QObject { Q_OBJECT -protected: - - bool m_abort; - QString m_errorMessage; - - ScPrintEngine() { m_abort = false; } - public: + ScPrintEngine(ScribusDoc& doc) : m_doc(doc) {} virtual ~ScPrintEngine() {} - virtual bool print(ScribusDoc& doc, PrintOptions& options) = 0; + + virtual bool print(PrintOptions& options) = 0; virtual const QString& errorMessage(void) { return m_errorMessage; } public slots: void cancelRequested(void) { m_abort = true; } + +protected: + ScribusDoc& m_doc; + bool m_abort { false }; + QString m_errorMessage; }; #endif diff --git a/scribus/scprintengine_gdi.cpp b/scribus/scprintengine_gdi.cpp index 1a48d6056..500281a47 100644 --- a/scribus/scprintengine_gdi.cpp +++ b/scribus/scprintengine_gdi.cpp @@ -62,7 +62,7 @@ typedef struct BYTE data[32768]; } sPSPassthrough; -ScPrintEngine_GDI::ScPrintEngine_GDI(void) : ScPrintEngine() +ScPrintEngine_GDI::ScPrintEngine_GDI(ScribusDoc& doc) : ScPrintEngine(doc) { m_abort = false; m_forceGDI = false; @@ -79,7 +79,7 @@ void ScPrintEngine_GDI::resetData(void) //m_forceGDI = false; } -bool ScPrintEngine_GDI::print(ScribusDoc& doc, PrintOptions& options) +bool ScPrintEngine_GDI::print(PrintOptions& options) { bool toFile; bool success; @@ -96,7 +96,7 @@ bool ScPrintEngine_GDI::print(ScribusDoc& doc, PrintOptions& options) toFile = printerUseFilePort(options.printer); if (toFile) { - QString docName = doc.documentFileName(); + QString docName = m_doc.documentFileName(); diaSelection = docName.right(docName.length() - docName.lastIndexOf("/") - 1); diaSelection = diaSelection.left(diaSelection.indexOf(".")); diaSelection += ".prn"; @@ -106,12 +106,12 @@ bool ScPrintEngine_GDI::print(ScribusDoc& doc, PrintOptions& options) docDir = dirs->get("winprn", prefsDocDir); else docDir = "."; - CustomFDialog dia(doc.scMW()->view, docDir, QObject::tr("Save As"), "Spool Files (*.prn *.ps);;All Files (*)", fdNone); + CustomFDialog dia(m_doc.scMW()->view, docDir, QObject::tr("Save As"), "Spool Files (*.prn *.ps);;All Files (*)", fdNone); dia.setSelection(diaSelection); if (dia.exec() == QDialog::Accepted) { QString selectedFile = dia.selectedFile(); - if (overwrite(doc.scMW()->view, selectedFile)) + if (overwrite(m_doc.scMW()->view, selectedFile)) { dirs->set("winprn", selectedFile.left(selectedFile.lastIndexOf("/"))); fileName = QDir::toNativeSeparators(selectedFile); @@ -122,13 +122,13 @@ bool ScPrintEngine_GDI::print(ScribusDoc& doc, PrintOptions& options) } // Set user options in the DEVmode structure - setDeviceParams(&doc, options, (DEVMODEW*) devMode.data()); + setDeviceParams(options, (DEVMODEW*) devMode.data()); // Create the device context printerDC = CreateDCW(nullptr, (LPCWSTR) printerName.utf16(), nullptr, (DEVMODEW*) devMode.data()); if (printerDC) { - success = printPages(&doc, options, printerDC, (DEVMODEW*) devMode.data(), fileName); + success = printPages(options, printerDC, (DEVMODEW*) devMode.data(), fileName); DeleteDC(printerDC); } else @@ -140,7 +140,7 @@ bool ScPrintEngine_GDI::print(ScribusDoc& doc, PrintOptions& options) return success; } -bool ScPrintEngine_GDI::gdiPrintPreview(ScribusDoc* doc, ScPage* page, QImage* image, PrintOptions& options, double scale) +bool ScPrintEngine_GDI::gdiPrintPreview(ScPage* page, QImage* image, PrintOptions& options, double scale) { bool success = true; HCOLORSPACE hColorSpace = nullptr; @@ -148,7 +148,7 @@ bool ScPrintEngine_GDI::gdiPrintPreview(ScribusDoc* doc, ScPage* page, QImage* i double scalex = 1, scaley = 1; bool rotate = false; - if (!doc || !page || !image) + if (!page || !image) return false; resetData(); @@ -174,7 +174,7 @@ bool ScPrintEngine_GDI::gdiPrintPreview(ScribusDoc* doc, ScPage* page, QImage* i if (options.mirrorV) dy += cliph; // Create the GDI painters - ScPageOutput pageOutput(doc, false); + ScPageOutput pageOutput(&m_doc, false); QRect drawRect(0, 0, imagew, imageh); cairo_surface_t* surface = cairo_image_surface_create_for_data(image->bits(), CAIRO_FORMAT_ARGB32, imagew, imageh, imagew*4); @@ -186,7 +186,7 @@ bool ScPrintEngine_GDI::gdiPrintPreview(ScribusDoc* doc, ScPage* page, QImage* i cairo_surface_destroy(surface); return false; } - ScPainterEx_Cairo painter(context, drawRect, doc, !options.useColor); + ScPainterEx_Cairo painter(context, drawRect, &m_doc, !options.useColor); scalex *= scale; scaley *= scale; @@ -203,7 +203,7 @@ bool ScPrintEngine_GDI::gdiPrintPreview(ScribusDoc* doc, ScPage* page, QImage* i return success; } -bool ScPrintEngine_GDI::printPages(ScribusDoc* doc, PrintOptions& options, HDC printerDC, DEVMODEW* devMode, QString& fileName) +bool ScPrintEngine_GDI::printPages(PrintOptions& options, HDC printerDC, DEVMODEW* devMode, QString& fileName) { int jobId; QScopedPointer progress; @@ -220,7 +220,7 @@ bool ScPrintEngine_GDI::printPages(ScribusDoc* doc, PrintOptions& options, HDC p printPageFunc = (useGDI) ? &ScPrintEngine_GDI::printPage_GDI : &ScPrintEngine_GDI::printPage_PS; // Setup document infos structure - wcsncpy (docName, (const WCHAR*) doc->documentFileName().utf16(), 511); + wcsncpy (docName, (const WCHAR*) m_doc.documentFileName().utf16(), 511); ZeroMemory(&docInfo, sizeof(docInfo)); docInfo.cbSize = sizeof(docInfo); docInfo.lpszDocName = docName; @@ -255,7 +255,7 @@ bool ScPrintEngine_GDI::printPages(ScribusDoc* doc, PrintOptions& options, HDC p bool usingGui = ScCore->usingGUI(); if (usingGui) { - progress.reset(new MultiProgressDialog(QObject::tr("Printing..."), CommonStrings::tr_Cancel, doc->scMW())); + progress.reset(new MultiProgressDialog(QObject::tr("Printing..."), CommonStrings::tr_Cancel, m_doc.scMW())); progress->setOverallTotalSteps(options.pageNumbers.size()); progress->setOverallProgress(0); connect(progress.data(), SIGNAL(canceled()), this, SLOT(cancelRequested())); @@ -266,8 +266,8 @@ bool ScPrintEngine_GDI::printPages(ScribusDoc* doc, PrintOptions& options, HDC p { if (usingGui) progress->setOverallProgress(index); - docPage = doc->Pages->at(options.pageNumbers[index] - 1); - success = (this->*printPageFunc)(doc, docPage, options, printerDC, context); + docPage = m_doc.Pages->at(options.pageNumbers[index] - 1); + success = (this->*printPageFunc)(docPage, options, printerDC, context); ScQApp->processEvents(); if (!success || m_abort) break; @@ -288,7 +288,7 @@ bool ScPrintEngine_GDI::printPages(ScribusDoc* doc, PrintOptions& options, HDC p return success; } -bool ScPrintEngine_GDI::printPage_GDI(ScribusDoc* doc, ScPage* page, PrintOptions& options, HDC printerDC, cairo_t* context) +bool ScPrintEngine_GDI::printPage_GDI(ScPage* page, PrintOptions& options, HDC printerDC, cairo_t* context) { int logPixelsX; int logPixelsY; @@ -311,8 +311,8 @@ bool ScPrintEngine_GDI::printPage_GDI(ScribusDoc* doc, ScPage* page, PrintOption if (isPostscriptPrinter(printerDC)) { success = false; - QString mProf = doc->prefsData().colorPrefs.DCMSset.DefaultSolidColorRGBProfile; - QString pProf = doc->prefsData().colorPrefs.DCMSset.DefaultPrinterProfile; + QString mProf = m_doc.prefsData().colorPrefs.DCMSset.DefaultSolidColorRGBProfile; + QString pProf = m_doc.prefsData().colorPrefs.DCMSset.DefaultPrinterProfile; if (ScCore->MonitorProfiles.contains(mProf) && ScCore->PrinterProfiles.contains(pProf)) { inputProfile = QDir::toNativeSeparators(ScCore->InputProfiles[mProf]); @@ -400,11 +400,11 @@ bool ScPrintEngine_GDI::printPage_GDI(ScribusDoc* doc, ScPage* page, PrintOption // Create the GDI painter MarksOptions marksOptions(options); - ScPageOutput pageOutput(doc, true, 300, true); + ScPageOutput pageOutput(&m_doc, true, 300, true); pageOutput.setMarksOptions(marksOptions); QRect drawRect(0, 0, physicalWidth, physicalHeight); - ScPainterEx_Cairo painter(context, drawRect, doc, !options.useColor); + ScPainterEx_Cairo painter(context, drawRect, &m_doc, !options.useColor); painter.clear(); scalex *= (logPixelsX / 72.0); @@ -425,7 +425,7 @@ bool ScPrintEngine_GDI::printPage_GDI(ScribusDoc* doc, ScPage* page, PrintOption return success; } -bool ScPrintEngine_GDI::printPage_PS(ScribusDoc* doc, ScPage* page, PrintOptions& options, HDC printerDC, cairo_t* /*context*/) +bool ScPrintEngine_GDI::printPage_PS(ScPage* page, PrintOptions& options, HDC printerDC, cairo_t* /*context*/) { bool succeed = false; PrintOptions options2 = options; @@ -437,7 +437,7 @@ bool ScPrintEngine_GDI::printPage_PS(ScribusDoc* doc, ScPage* page, PrintOptions options2.includePDFMarks = false; tempFilePath = ScPaths::tempFileDir() + "/tmp.ps"; - PSLib *dd = new PSLib(doc, options2, PSLib::OutputEPS); + PSLib *dd = new PSLib(&m_doc, options2, PSLib::OutputEPS); ret = dd->createPS(tempFilePath); delete dd; if (ret != 0) return false; @@ -447,8 +447,8 @@ bool ScPrintEngine_GDI::printPage_PS(ScribusDoc* doc, ScPage* page, PrintOptions QString tmp; QStringList opts; QString tempFilePath2 = ScPaths::tempFileDir() + "/tmp2.ps"; - opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(doc->pageWidth()))); - opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(doc->pageHeight()))); + opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(m_doc.pageWidth()))); + opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(m_doc.pageHeight()))); if (QFile::exists(tempFilePath2)) QFile::remove(tempFilePath2); ret = convertPS2PS(tempFilePath, tempFilePath2, opts, options.prnEngine); @@ -476,7 +476,7 @@ bool ScPrintEngine_GDI::printPage_PS(ScribusDoc* doc, ScPage* page, PrintOptions return succeed; } -bool ScPrintEngine_GDI::printPage_PS_Sep(ScribusDoc* doc, ScPage* page, PrintOptions& options, HDC printerDC, cairo_t* context) +bool ScPrintEngine_GDI::printPage_PS_Sep(ScPage* page, PrintOptions& options, HDC printerDC, cairo_t* context) { bool succeed = true; QStringList separations; @@ -488,7 +488,7 @@ bool ScPrintEngine_GDI::printPage_PS_Sep(ScribusDoc* doc, ScPage* page, PrintOpt { PrintOptions tempOptions = options; tempOptions.separationName = separations.at(i); - succeed &= printPage_PS(doc, page, tempOptions, printerDC, context); + succeed &= printPage_PS(page, tempOptions, printerDC, context); if (!succeed) break; } return succeed; @@ -616,7 +616,7 @@ bool ScPrintEngine_GDI::sendPSFile(QString filePath, HDC printerDC, int pageWidt return ((fileSize == bw) && (br >= 0)); } -void ScPrintEngine_GDI::setDeviceParams(ScribusDoc* doc, PrintOptions& options, DEVMODEW* devMode) +void ScPrintEngine_GDI::setDeviceParams(PrintOptions& options, DEVMODEW* devMode) { HANDLE handle; QString printer = options.printer; @@ -633,7 +633,7 @@ void ScPrintEngine_GDI::setDeviceParams(ScribusDoc* doc, PrintOptions& options, } OpenPrinterW((LPWSTR) printer.utf16(), &handle, nullptr); - DocumentPropertiesW((HWND) doc->scMW()->winId(), handle, (LPWSTR) printer.utf16(), devMode, devMode, DM_IN_BUFFER | DM_OUT_BUFFER); + DocumentPropertiesW((HWND) m_doc.scMW()->winId(), handle, (LPWSTR) printer.utf16(), devMode, devMode, DM_IN_BUFFER | DM_OUT_BUFFER); ClosePrinter(handle); } diff --git a/scribus/scprintengine_gdi.h b/scribus/scprintengine_gdi.h index 9341f77a9..90289c712 100644 --- a/scribus/scprintengine_gdi.h +++ b/scribus/scprintengine_gdi.h @@ -22,7 +22,7 @@ class SCRIBUS_API ScPrintEngine_GDI : public ScPrintEngine { public: - ScPrintEngine_GDI(void); + ScPrintEngine_GDI(ScribusDoc& doc); /*! \brief Force use of gdi even on ps printers \param force if gdi should be forced @@ -36,7 +36,7 @@ class SCRIBUS_API ScPrintEngine_GDI : public ScPrintEngine \retval bool return true if no error occurred \author Jean Ghali */ - virtual bool print(ScribusDoc& doc, PrintOptions& options); + bool print(PrintOptions& options) override; /*! \brief Draw print preview to an image using gdi method \param doc the document whose page is to be preview @@ -47,7 +47,7 @@ class SCRIBUS_API ScPrintEngine_GDI : public ScPrintEngine \retval bool true on success \author Jean Ghali */ - bool gdiPrintPreview( ScribusDoc* doc, ScPage* page, QImage* image, PrintOptions& options, double scale = 1.0 ); + bool gdiPrintPreview(ScPage* page, QImage* image, PrintOptions& options, double scale = 1.0); /*! \brief Get the default printer name \retval QString the default printer name on success or an empty string @@ -57,11 +57,11 @@ class SCRIBUS_API ScPrintEngine_GDI : public ScPrintEngine protected: - bool m_forceGDI; + bool m_forceGDI { false }; void resetData(void); - typedef bool (ScPrintEngine_GDI::*PrintPageFunc) (ScribusDoc* doc, ScPage* page, PrintOptions& options, HDC printerDC, cairo_t* context); + typedef bool (ScPrintEngine_GDI::*PrintPageFunc) (ScPage* page, PrintOptions& options, HDC printerDC, cairo_t* context); /*! \brief Print selected pages to a printer or a file \param doc the document whose pages are to be printer @@ -72,7 +72,7 @@ class SCRIBUS_API ScPrintEngine_GDI : public ScPrintEngine \retval bool true on success \author Jean Ghali */ - bool printPages(ScribusDoc* doc, PrintOptions& options, HDC printerDC, DEVMODEW* devMode, QString& fileName); + bool printPages(PrintOptions& options, HDC printerDC, DEVMODEW* devMode, QString& fileName); /*! \brief Print a page to a gdi printer Print a page using GDI drawing code ( works on all printers : PS, PCL, GDI... ) @@ -84,7 +84,7 @@ class SCRIBUS_API ScPrintEngine_GDI : public ScPrintEngine \retval bool true on success \author Jean Ghali */ - bool printPage_GDI(ScribusDoc* doc, ScPage* page, PrintOptions& options, HDC printerDC, cairo_t* context); + bool printPage_GDI(ScPage* page, PrintOptions& options, HDC printerDC, cairo_t* context); /*! \brief Print a page to a PostScript printer using passthroughs Print a page using PS drawing code and PS passthroughs ( works on PS printers only ) @@ -96,7 +96,7 @@ class SCRIBUS_API ScPrintEngine_GDI : public ScPrintEngine \retval bool true on success \author Jean Ghali */ - bool printPage_PS (ScribusDoc* doc, ScPage* page, PrintOptions& options, HDC printerDC, cairo_t* context); + bool printPage_PS (ScPage* page, PrintOptions& options, HDC printerDC, cairo_t* context); /*! \brief Print a page separations to a PostScript printer using passthroughs Print a page using PS drawing code and PS passthroughs ( works on PS printers only ) @@ -108,7 +108,7 @@ class SCRIBUS_API ScPrintEngine_GDI : public ScPrintEngine \retval bool true on success \author Jean Ghali */ - bool printPage_PS_Sep(ScribusDoc* doc, ScPage* page, PrintOptions& options, HDC printerDC, cairo_t* context); + bool printPage_PS_Sep(ScPage* page, PrintOptions& options, HDC printerDC, cairo_t* context); /*! \brief Send a file to printer using PostScript Passthrough Send a postscript file to a printer using ps passthrough ( works on PS printers only ) @@ -128,7 +128,7 @@ class SCRIBUS_API ScPrintEngine_GDI : public ScPrintEngine \param devMode pointer to a DEVMODE structure \author Jean Ghali */ - void setDeviceParams(ScribusDoc* doc, PrintOptions& options, DEVMODEW* devMode); + void setDeviceParams(PrintOptions& options, DEVMODEW* devMode); /*! \brief Get support for PostScript Passthrough Get ps passthrough support and escape code diff --git a/scribus/scprintengine_pdf.cpp b/scribus/scprintengine_pdf.cpp new file mode 100644 index 000000000..1440e2545 --- /dev/null +++ b/scribus/scprintengine_pdf.cpp @@ -0,0 +1,180 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ + +#include "filewatcher.h" +#include "pageitemiterator.h" +#include "pdflib.h" +#include "pdflib_core.h" +#include "prefsmanager.h" +#include "scpaths.h" +#include "scprintengine_pdf.h" +#include "scribusstructs.h" +#include "scribuscore.h" +#include "scribusdoc.h" +#include "util_file.h" +#include "util_ghostscript.h" + +ScPrintEngine_PDF::ScPrintEngine_PDF(ScribusDoc& doc) : + ScPrintEngine(doc), + m_prefsManager(PrefsManager::instance()) +{ + +} + +bool ScPrintEngine_PDF::print(PrintOptions& options) +{ + QString fileName(options.filename); + + if (!options.toFile) + fileName = ScPaths::tempFileDir() + "/tmp.pdf"; + fileName = QDir::toNativeSeparators(fileName); + + // Write the PS to a file + QString errorMessage; + + int pdfCreationRetVal = createPDFFile(fileName, options, errorMessage); + if (pdfCreationRetVal != 0) + { + QFile::remove(fileName); + if (pdfCreationRetVal == 2) // Aborted by user + return true; + m_errorMessage = errorMessage; + return false; + } + if (options.toFile) + return true; + + // Print and delete the PS file + QByteArray cmd; + if (options.useAltPrintCommand) + { + cmd += options.printerCommand; + cmd += " "; + cmd += fileName; + system(cmd.data()); + } + else + { + QByteArray cc; + cmd += "lpr -P '"; + cmd += options.printer; + cmd += "'"; + if (options.copies > 1) + cmd += " -#" + cc.setNum(options.copies); + cmd += options.printerOptions; + cmd += " " + fileName; + system(cmd.data()); + } + // Disabled that for now, as kprinter won't work otherwise + // leaving that file around doesn't harm, as it will be overwritten the next time. + // unlink(filename); + + return true; +} + +int ScPrintEngine_PDF::createPDFFile(const QString& fileName, const PrintOptions& options, QString& errorMessage) +{ + PDFOptions pdfOptions; + + pdfOptions.Version = PDFVersion::PDF_14; + pdfOptions.FontEmbedding = PDFOptions::EmbedFonts; + setupFontEmbedding(pdfOptions); + + pdfOptions.doClip = options.doClip; + pdfOptions.MirrorH = options.mirrorH; + pdfOptions.MirrorV = options.mirrorV; + pdfOptions.PresentMode = false; + pdfOptions.Encrypt = false; // Disable PDF encryption for printing + pdfOptions.Thumbnails = false; //Disable thumbnails too + + if (options.useColor) + { + pdfOptions.isGrayscale = false; + pdfOptions.UseRGB = false; + pdfOptions.UseProfiles = true; + pdfOptions.UseProfiles2 = true; + } + else + { + pdfOptions.isGrayscale = true; + pdfOptions.UseRGB = false; + pdfOptions.UseProfiles = false; + pdfOptions.UseProfiles2 = false; + } + pdfOptions.SolidProf = m_doc.colorPrefs().DCMSset.DefaultSolidColorRGBProfile; + pdfOptions.ImageProf = m_doc.colorPrefs().DCMSset.DefaultImageRGBProfile; + pdfOptions.PrintProf = m_doc.colorPrefs().DCMSset.DefaultPrinterProfile; + pdfOptions.UseSpotColors = options.useSpotColors; + + pdfOptions.cropMarks = options.colorMarks; + pdfOptions.bleedMarks = options.bleedMarks; + pdfOptions.registrationMarks = options.registrationMarks; + pdfOptions.colorMarks = options.colorMarks; + pdfOptions.markLength = options.markLength; + pdfOptions.markOffset = options.markOffset; + pdfOptions.bleeds = options.bleeds; + + // Embed all fonts + + // Generate PDF + QString errorString; + + ScCore->fileWatcher->forceScan(); + ScCore->fileWatcher->stop(); + PDFlib pdflib(m_doc, pdfOptions); + bool success = pdflib.doExport(fileName, options.pageNumbers, QMap()); + if (!success) + errorMessage = pdflib.errorMessage(); + ScCore->fileWatcher->start(); + + if (!success) + return 1; + if (pdflib.exportAborted()) + return 2; + return 0; +} + +void ScPrintEngine_PDF::setupFontEmbedding(PDFOptions& options) +{ + QMap usedFonts = m_doc.reorganiseFonts(); + QStringList docFonts = usedFonts.keys(); + + options.OutlineList.clear(); + options.EmbedList.clear(); + options.SubsetList.clear(); + + // Build a list of all fonts used in Annotations + QMap annotationFonts; + + int pageItOptions = PageItemIterator::IterateInGroups | PageItemIterator::IterateInDocItems | PageItemIterator::IterateInMasterItems | PageItemIterator::IterateInFrameItems; + for (PageItemIterator it(&m_doc, pageItOptions); *it; ++it) + { + PageItem *currItem = *it; + if (((currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::PathText)) && (currItem->isAnnotation())) + { + int annotType = currItem->annotation().Type(); + bool mustEmbed = ((annotType >= Annotation::Button) && (annotType <= Annotation::Listbox) && (annotType != Annotation::Checkbox)); + if (currItem->itemText.length() > 0 || mustEmbed) + annotationFonts.insert(currItem->itemText.defaultStyle().charStyle().font().replacementName(), QString()); + } + } + + const auto& allFonts = m_prefsManager.appPrefs.fontPrefs.AvailFonts; + PDFVersion pdfVer = options.Version; + + for (int i = 0; i < docFonts.count(); ++i) + { + QString fontName = docFonts.at(i); + const ScFace fontFace = allFonts[fontName]; + if (!fontFace.subset() && (!fontFace.isOTF() || pdfVer.supportsEmbeddedOpenTypeFonts())) + options.EmbedList.append(fontName); + else if (annotationFonts.contains(fontName)) + options.EmbedList.append(fontName); + else + options.SubsetList.append(fontName); + } +} diff --git a/scribus/scprintengine_pdf.h b/scribus/scprintengine_pdf.h new file mode 100644 index 000000000..326c6e943 --- /dev/null +++ b/scribus/scprintengine_pdf.h @@ -0,0 +1,28 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#ifndef SCPRINTENGINE_PDF_H +#define SCPRINTENGINE_PDF_H + +#include "pdfoptions.h" +#include "scprintengine.h" + +class ScPrintEngine_PDF : public ScPrintEngine +{ +public: + ScPrintEngine_PDF(ScribusDoc& doc); + ~ScPrintEngine_PDF() {} + + bool print(PrintOptions& options) override; + +protected: + PrefsManager& m_prefsManager; + + int createPDFFile(const QString& fileName, const PrintOptions& options, QString& errorMessage); + void setupFontEmbedding(PDFOptions& options); +}; + +#endif diff --git a/scribus/scprintengine_ps.cpp b/scribus/scprintengine_ps.cpp index f015bfaa7..2e14ce73d 100644 --- a/scribus/scprintengine_ps.cpp +++ b/scribus/scprintengine_ps.cpp @@ -14,11 +14,16 @@ for which a new license (GPL+exception) is in place. #include "util_file.h" #include "util_ghostscript.h" -bool ScPrintEngine_PS::print(ScribusDoc& doc, PrintOptions& options) +ScPrintEngine_PS::ScPrintEngine_PS(ScribusDoc& doc) + : ScPrintEngine(doc) +{ + +} + +bool ScPrintEngine_PS::print(PrintOptions& options) { - bool retw = false; QString filename(options.filename); - PSLib *dd = new PSLib(&doc, options, PSLib::OutputPS); + PSLib *dd = new PSLib(&m_doc, options, PSLib::OutputPS); if (dd == nullptr) return false; @@ -42,39 +47,38 @@ bool ScPrintEngine_PS::print(ScribusDoc& doc, PrintOptions& options) // use gs to convert our PS to a lower version QString tmp; QStringList opts; - opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(doc.pageWidth())) ); - opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(doc.pageHeight())) ); + opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(m_doc.pageWidth())) ); + opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(m_doc.pageHeight())) ); convertPS2PS(filename, filename + ".tmp", opts, options.prnEngine); moveFile(filename + ".tmp", filename); } - if (!options.toFile) + if (options.toFile) + return true; + + // Print and delete the PS file + QByteArray cmd; + if (options.useAltPrintCommand) + { + cmd += options.printerCommand; + cmd += " "; + cmd += filename; + system(cmd.data()); + } + else { - // print and delete the PS file - QByteArray cmd; - if (options.useAltPrintCommand) - { - cmd += options.printerCommand; - cmd += " "; - cmd += filename; - system(cmd.data()); - } - else - { - QByteArray cc; - cmd += "lpr -P '"; - cmd += options.printer; - cmd += "'"; - if (options.copies > 1) - cmd += " -#" + cc.setNum(options.copies); - cmd += options.printerOptions; - cmd += " "+filename; - system(cmd.data()); - } - // Disabled that for now, as kprinter won't work otherwise - // leaving that file around doesn't harm, as it will be overwritten the next time. - // unlink(filename); + QByteArray cc; + cmd += "lpr -P '"; + cmd += options.printer; + cmd += "'"; + if (options.copies > 1) + cmd += " -#" + cc.setNum(options.copies); + cmd += options.printerOptions; + cmd += " " + filename; + system(cmd.data()); } + // Disabled that for now, as kprinter won't work otherwise + // leaving that file around doesn't harm, as it will be overwritten the next time. + // unlink(filename); - retw = true; - return retw; + return true; } diff --git a/scribus/scprintengine_ps.h b/scribus/scprintengine_ps.h index bbf8b7f63..4ae80c5b0 100644 --- a/scribus/scprintengine_ps.h +++ b/scribus/scprintengine_ps.h @@ -12,8 +12,10 @@ for which a new license (GPL+exception) is in place. class ScPrintEngine_PS : public ScPrintEngine { public: + ScPrintEngine_PS(ScribusDoc& doc); ~ScPrintEngine_PS() {} - virtual bool print(ScribusDoc& doc, PrintOptions& options); + + bool print(PrintOptions& options) override; }; #endif diff --git a/scribus/scribus.cpp b/scribus/scribus.cpp index c4529ce9e..8fda269bf 100644 --- a/scribus/scribus.cpp +++ b/scribus/scribus.cpp @@ -4592,22 +4592,16 @@ bool ScribusMainWindow::doPrint(PrintOptions &options, QString& error) ScCore->fileWatcher->stop(); ScPrintEngine* prnEngine = nullptr; #if defined(_WIN32) - SHORT shiftState = GetKeyState( VK_SHIFT ); - bool forceGDI = ( shiftState & 0x8000 ) ? true : false; if (doc->Print_Options.toFile) - prnEngine = dynamic_cast(new ScPrintEngine_PS()); + prnEngine = dynamic_cast(new ScPrintEngine_PS(*doc)); else - { - ScPrintEngine_GDI* gdiEngine = new ScPrintEngine_GDI(); - gdiEngine->setForceGDI( forceGDI ); - prnEngine = dynamic_cast(gdiEngine); - } + prnEngine = dynamic_cast(new ScPrintEngine_GDI(*doc)); #else - prnEngine = dynamic_cast(new ScPrintEngine_PS()); + prnEngine = dynamic_cast(new ScPrintEngine_PS(*doc)); #endif if (prnEngine) { - printDone = prnEngine->print(*doc, options); + printDone = prnEngine->print(options); if (!printDone) error = prnEngine->errorMessage(); delete prnEngine; diff --git a/scribus/scribus.css b/scribus/scribus.css index 957644a9d..3a4950eaa 100644 --- a/scribus/scribus.css +++ b/scribus/scribus.css @@ -8,9 +8,6 @@ eg. ___downArrow___ PageSelector QComboBox { border: 1px solid gray; height: 20px; width: 3em; } PageSelector QComboBox::down-arrow { image: url(___downArrow___); width: 12px; height: 12px; } PageSelector QComboBox::down-arrow:on { top: 1px; left: 1px; } -PageSelector QComboBox:editable { background: white; } -PageSelector QComboBox:!editable, PageSelector QComboBox::drop-down:editable { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #E1E1E1, stop: 0.4 #DDDDDD, stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);} -PageSelector QComboBox:!editable:on, PageSelector QComboBox::drop-down:editable:on { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D3D3D3, stop: 0.4 #D8D8D8, stop: 0.5 #DDDDDD, stop: 1.0 #E1E1E1); } PageSelector QComboBox:on { padding-top: 3px; padding-left: 4px; } PageSelector QComboBox::drop-down { subcontrol-origin: padding; subcontrol-position: top right; width: 15px; border-left-width: 1px; border-left-color: darkgray; border-left-style: solid; border-top-right-radius: 3px; border-bottom-right-radius: 3px; } @@ -38,18 +35,12 @@ QSpinBox#zoomSpinBox { height: 20px; width: 3em; padding-right: 15px; } QComboBox#layerMenu { border: 1px solid gray; height: 20px; width:6em; } QComboBox#layerMenu::down-arrow { image: url(___downArrow___); width: 12px; height: 12px;} QComboBox#layerMenu::down-arrow:on { top: 1px; left: 1px; } -QComboBox#layerMenu:editable { background: white; } -QComboBox#layerMenu:!editable, QComboBox#layerMenu::drop-down:editable { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #E1E1E1, stop: 0.4 #DDDDDD, stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);} -QComboBox#layerMenu:!editable:on, QComboBox#layerMenu::drop-down:editable:on { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D3D3D3, stop: 0.4 #D8D8D8, stop: 0.5 #DDDDDD, stop: 1.0 #E1E1E1); } QComboBox#layerMenu:on { padding-top: 3px; padding-left: 4px; } QComboBox#layerMenu::drop-down { subcontrol-origin: padding; subcontrol-position: top right; width: 15px; border-left-width: 1px; border-left-color: darkgray; border-left-style: solid; border-top-right-radius: 3px; border-bottom-right-radius: 3px; } QComboBox#unitSwitcher { border: 1px solid gray; height: 20px; width:2em; } QComboBox#unitSwitcher::down-arrow { image: url(___downArrow___); width: 12px; height: 12px;} QComboBox#unitSwitcher::down-arrow:on { top: 1px; left: 1px; } -QComboBox#unitSwitcher:editable { background: white; } -QComboBox#unitSwitcher:!editable, QComboBox#unitSwitcher::drop-down:editable { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #E1E1E1, stop: 0.4 #DDDDDD, stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);} -QComboBox#unitSwitcher:!editable:on, QComboBox#unitSwitcher::drop-down:editable:on { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D3D3D3, stop: 0.4 #D8D8D8, stop: 0.5 #DDDDDD, stop: 1.0 #E1E1E1); } QComboBox#unitSwitcher:on { padding-top: 3px; padding-left: 4px; } QComboBox#unitSwitcher::drop-down { subcontrol-origin: padding; subcontrol-position: top right; width: 15px; border-left-width: 1px; border-left-color: darkgray; border-left-style: solid; border-top-right-radius: 3px; border-bottom-right-radius: 3px; } diff --git a/scribus/scribusdoc.cpp b/scribus/scribusdoc.cpp index f87d1647b..ba75e8725 100644 --- a/scribus/scribusdoc.cpp +++ b/scribus/scribusdoc.cpp @@ -14098,7 +14098,7 @@ bool ScribusDoc::sizeItem(double newW, double newH, PageItem *pi, bool fromMP, b } if (currItem->isLine()) { - int ph = static_cast(qMax(1.0, currItem->lineWidth() / 2.0)); + //int ph = static_cast(qMax(1.0, currItem->lineWidth() / 2.0)); if (!fromMP) { FPoint g(currItem->xPos(), currItem->yPos()); diff --git a/scribus/third_party/rtf-qt/rtfreader.h b/scribus/third_party/rtf-qt/rtfreader.h index 1caf9b217..4304160a3 100644 --- a/scribus/third_party/rtf-qt/rtfreader.h +++ b/scribus/third_party/rtf-qt/rtfreader.h @@ -54,7 +54,7 @@ namespace RtfReader /** Normal constructor */ - explicit Reader( QObject *parent = 0 ); + explicit Reader( QObject* parent = nullptr ); /** Open a document diff --git a/scribus/tt/simpletreemodel/treeitem.h b/scribus/tt/simpletreemodel/treeitem.h index 1198c1821..9e60e09ae 100644 --- a/scribus/tt/simpletreemodel/treeitem.h +++ b/scribus/tt/simpletreemodel/treeitem.h @@ -48,7 +48,7 @@ class TreeItem { public: - TreeItem(const QList &data, TreeItem *parent = 0); + TreeItem(const QList &data, TreeItem* parent = nullptr); ~TreeItem(); void appendChild(TreeItem *item); diff --git a/scribus/tt/simpletreemodel/treemodel.h b/scribus/tt/simpletreemodel/treemodel.h index fa98a0e9d..2b03765e4 100644 --- a/scribus/tt/simpletreemodel/treemodel.h +++ b/scribus/tt/simpletreemodel/treemodel.h @@ -54,8 +54,8 @@ class TreeModel : public QAbstractItemModel Q_OBJECT public: - TreeModel(const QString &data, QObject *parent = 0); - TreeModel(QObject *parent = 0); //Scribus Added for ScHelpTreeModel + TreeModel(const QString &data, QObject* parent = nullptr); + TreeModel(QObject* parent = nullptr); //Scribus Added for ScHelpTreeModel ~TreeModel(); QVariant data(const QModelIndex &index, int role) const; diff --git a/scribus/ui/AdapterWidget.h b/scribus/ui/AdapterWidget.h index 7ad7ebfdc..a797b1357 100644 --- a/scribus/ui/AdapterWidget.h +++ b/scribus/ui/AdapterWidget.h @@ -25,7 +25,7 @@ class AdapterWidget : public QGLWidget { Q_OBJECT public: - AdapterWidget ( QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0); + AdapterWidget ( QWidget* parent = nullptr, const char * name = 0, const QGLWidget * shareWidget = 0); virtual ~AdapterWidget() {} @@ -53,7 +53,7 @@ class AdapterWidget : public QGLWidget class ViewerQT : public osgViewer::Viewer, public AdapterWidget { public: - ViewerQT ( QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0) : AdapterWidget ( parent, name, shareWidget) + ViewerQT ( QWidget* parent = nullptr, const char * name = 0, const QGLWidget * shareWidget = 0) : AdapterWidget ( parent, name, shareWidget) { getCamera()->setViewport ( new osg::Viewport ( 0,0,width(),height() ) ); getCamera()->setProjectionMatrixAsPerspective ( 30.0f, static_cast ( width() ) /static_cast ( height() ), 1.0f, 10000.0f ); diff --git a/scribus/ui/aligndistribute.h b/scribus/ui/aligndistribute.h index 71d5e514a..924c046ab 100644 --- a/scribus/ui/aligndistribute.h +++ b/scribus/ui/aligndistribute.h @@ -56,7 +56,7 @@ class SCRIBUS_API AlignDistributePalette : public ScDockPalette, Ui::AlignDistri Q_OBJECT public: - AlignDistributePalette( QWidget* parent = 0, const char* name = 0); + AlignDistributePalette( QWidget* parent = nullptr, const char* name = 0); ~AlignDistributePalette(); virtual void setDoc( ScribusDoc* newDoc ); diff --git a/scribus/ui/applytemplatedialog.h b/scribus/ui/applytemplatedialog.h index 1f73f63ef..b348809f7 100644 --- a/scribus/ui/applytemplatedialog.h +++ b/scribus/ui/applytemplatedialog.h @@ -39,7 +39,7 @@ class SCRIBUS_API ApplyMasterPageDialog : public QDialog Q_OBJECT public: - ApplyMasterPageDialog( QWidget* parent = 0 ); + ApplyMasterPageDialog( QWidget* parent = nullptr ); ~ApplyMasterPageDialog(); virtual void changeEvent(QEvent *e); diff --git a/scribus/ui/colorcombo.h b/scribus/ui/colorcombo.h index 53715be9f..cefb411db 100644 --- a/scribus/ui/colorcombo.h +++ b/scribus/ui/colorcombo.h @@ -43,9 +43,9 @@ class SCRIBUS_API ColorCombo : public QComboBox fancyPixmaps }; - ColorCombo( QWidget* parent=0 ); - ColorCombo( ColorCombo::PixmapType type, QWidget* parent=0 ); - ColorCombo( bool rw, QWidget* parent=0 ); + ColorCombo( QWidget* parent=nullptr ); + ColorCombo( ColorCombo::PixmapType type, QWidget* parent=nullptr ); + ColorCombo( bool rw, QWidget* parent=nullptr ); QString currentColor() const; diff --git a/scribus/ui/colorlistbox.h b/scribus/ui/colorlistbox.h index 7b0215f10..ab9f878f4 100644 --- a/scribus/ui/colorlistbox.h +++ b/scribus/ui/colorlistbox.h @@ -46,8 +46,8 @@ class SCRIBUS_API ColorListBox : public QListView /*! \brief Standard QListBox like constructor. Just there are initialized pixmaps for icon drawing. */ - ColorListBox(QWidget * parent = 0); - ColorListBox(ColorListBox::PixmapType type, QWidget * parent = 0); + ColorListBox(QWidget* parent = nullptr); + ColorListBox(ColorListBox::PixmapType type, QWidget* parent = nullptr); ~ColorListBox(); virtual void changeEvent(QEvent *e); diff --git a/scribus/ui/colorlistmodel.h b/scribus/ui/colorlistmodel.h index 8f5bc65e4..debe511ea 100644 --- a/scribus/ui/colorlistmodel.h +++ b/scribus/ui/colorlistmodel.h @@ -36,7 +36,7 @@ class SCRIBUS_API ColorListModel : public QAbstractItemModel public: //! Constructor - ColorListModel(QObject *parent = 0); + ColorListModel(QObject* parent = nullptr); enum SortRule { diff --git a/scribus/ui/contextmenu.h b/scribus/ui/contextmenu.h index 2faf0c169..d8c7082cd 100644 --- a/scribus/ui/contextmenu.h +++ b/scribus/ui/contextmenu.h @@ -30,8 +30,8 @@ class ContextMenu : public QMenu { Q_OBJECT public: - ContextMenu(Selection &sel, ScribusMainWindow *actionsParent, ScribusDoc* doc, QWidget* parent=0); - ContextMenu(ScribusMainWindow *actionsParent, ScribusDoc* doc, double mx, double my, QWidget* parent=0); + ContextMenu(Selection &sel, ScribusMainWindow *actionsParent, ScribusDoc* doc, QWidget* parent=nullptr); + ContextMenu(ScribusMainWindow *actionsParent, ScribusDoc* doc, double mx, double my, QWidget* parent=nullptr); ~ContextMenu(); protected: diff --git a/scribus/ui/copypagetomasterpagedialog.h b/scribus/ui/copypagetomasterpagedialog.h index c697250b9..c53914ece 100644 --- a/scribus/ui/copypagetomasterpagedialog.h +++ b/scribus/ui/copypagetomasterpagedialog.h @@ -15,7 +15,7 @@ class SCRIBUS_API CopyPageToMasterPageDialog : public QDialog, public Ui::CopyPa { Q_OBJECT public: - CopyPageToMasterPageDialog(int existingMasterNamesCount, const QStringList& pageLocations, int currentLocation = -1, QWidget *parent = 0); + CopyPageToMasterPageDialog(int existingMasterNamesCount, const QStringList& pageLocations, int currentLocation = -1, QWidget* parent = nullptr); ~CopyPageToMasterPageDialog(); void values(QString &pageName, bool ©AppliedMaster, int &pageLocation) const; diff --git a/scribus/ui/cpalette.cpp b/scribus/ui/cpalette.cpp index fe63e7aa6..db57ab622 100644 --- a/scribus/ui/cpalette.cpp +++ b/scribus/ui/cpalette.cpp @@ -1024,7 +1024,7 @@ void ColorPalette::showGradient(int number) else if (number == 11) { stackedWidget_2->setCurrentIndex(2); - if ((currentItem->selectedMeshPointX > -1) && (currentItem->selectedMeshPointY > -1l)) + if ((currentItem->selectedMeshPointX > -1) && (currentItem->selectedMeshPointY > -1L)) { MeshPoint mp = currentItem->meshGradientArray[currentItem->selectedMeshPointX][currentItem->selectedMeshPointY]; setCurrentComboItem(colorMeshPoint, mp.colorName); @@ -1181,8 +1181,8 @@ void ColorPalette::slotGrad(int number) else if (gradientType->currentIndex() == 5) { stackedWidget_2->setCurrentIndex(2); - if ((currentItem->selectedMeshPointX > -1) && (currentItem->selectedMeshPointY > -1l)) - { + if ((currentItem->selectedMeshPointX > -1) && + (currentItem->selectedMeshPointY > -1L)) { MeshPoint mp = currentItem->meshGradientArray[currentItem->selectedMeshPointX][currentItem->selectedMeshPointY]; setCurrentComboItem(colorMeshPoint, mp.colorName); shadeMeshPoint->setValue(mp.shade); @@ -1276,7 +1276,7 @@ void ColorPalette::slotGradType(int type) else if (type == 5) { stackedWidget_2->setCurrentIndex(2); - if ((currentItem->selectedMeshPointX > -1) && (currentItem->selectedMeshPointY > -1l)) + if ((currentItem->selectedMeshPointX > -1) && (currentItem->selectedMeshPointY > -1L)) { MeshPoint mp = currentItem->meshGradientArray[currentItem->selectedMeshPointX][currentItem->selectedMeshPointY]; setCurrentComboItem(colorMeshPoint, mp.colorName); diff --git a/scribus/ui/cxfimportdialog.h b/scribus/ui/cxfimportdialog.h index 593676ba7..e1d2e407c 100644 --- a/scribus/ui/cxfimportdialog.h +++ b/scribus/ui/cxfimportdialog.h @@ -19,7 +19,7 @@ class CxfImportDialog : public QDialog, Ui::CxfImportDialogBase Q_OBJECT public: - CxfImportDialog(QWidget* parent = 0); + CxfImportDialog(QWidget* parent = nullptr); QList priorities() const; diff --git a/scribus/ui/fontcombo.cpp b/scribus/ui/fontcombo.cpp index 82125bb9a..969763f45 100644 --- a/scribus/ui/fontcombo.cpp +++ b/scribus/ui/fontcombo.cpp @@ -540,6 +540,8 @@ void FontFamilyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op if (hasLatin) font = font2; + pixPainter.setPen(QPen(option.palette.text(), 0)); + invpixPainter.setBrush(option.palette.highlight()); invpixPainter.setPen(Qt::NoPen); invpixPainter.drawRect(0, 0, option.rect.width(), option.rect.height()); diff --git a/scribus/ui/fontcombo.h b/scribus/ui/fontcombo.h index 11036222b..512f6d774 100644 --- a/scribus/ui/fontcombo.h +++ b/scribus/ui/fontcombo.h @@ -137,7 +137,7 @@ class FontComboValidator : public QValidator Q_OBJECT public: - FontComboValidator(QObject* parent = 0); + FontComboValidator(QObject* parent = nullptr); virtual State validate(QString & input, int & pos) const; }; #endif diff --git a/scribus/ui/fontembeddingcombo.h b/scribus/ui/fontembeddingcombo.h index 208dcf756..4b914c4b7 100644 --- a/scribus/ui/fontembeddingcombo.h +++ b/scribus/ui/fontembeddingcombo.h @@ -23,7 +23,7 @@ class SCRIBUS_API FontEmbeddingCombo : public QComboBox Q_OBJECT public: - FontEmbeddingCombo(QWidget* parent=0); + FontEmbeddingCombo(QWidget* parent=nullptr); ~FontEmbeddingCombo(); PDFOptions::PDFFontEmbedding embeddingMode() const; diff --git a/scribus/ui/fontembeddingmodel.h b/scribus/ui/fontembeddingmodel.h index f30eb5924..186c9f448 100644 --- a/scribus/ui/fontembeddingmodel.h +++ b/scribus/ui/fontembeddingmodel.h @@ -20,7 +20,7 @@ class SCRIBUS_API FontEmbeddingModel : public QAbstractItemModel public: //! Constructor - FontEmbeddingModel(QObject *parent = 0); + FontEmbeddingModel(QObject* parent = nullptr); //! Remove all colors from list; void clear(); diff --git a/scribus/ui/fontlistview.h b/scribus/ui/fontlistview.h index 8c1f8bc7c..10ed47b70 100644 --- a/scribus/ui/fontlistview.h +++ b/scribus/ui/fontlistview.h @@ -22,7 +22,7 @@ class SCRIBUS_API FontListView : public QTableView Q_OBJECT public: - FontListView(QWidget * parent = 0); + FontListView(QWidget* parent = nullptr); void setModel(QAbstractItemModel * model); void setFonts(const SCFonts& f); diff --git a/scribus/ui/inserttablecolumnsdialog.h b/scribus/ui/inserttablecolumnsdialog.h index 13f40b4b6..52187805a 100644 --- a/scribus/ui/inserttablecolumnsdialog.h +++ b/scribus/ui/inserttablecolumnsdialog.h @@ -29,7 +29,7 @@ class InsertTableColumnsDialog : public QDialog, private Ui::InsertTableColumnsD public: /// Constructs a new dialog for inserting columns. @a appMode is the current application mode. - explicit InsertTableColumnsDialog(int appMode, QWidget *parent = 0); + explicit InsertTableColumnsDialog(int appMode, QWidget* parent = nullptr); /// Returns the number of columns the user entered. int numberOfColumns() const { return numColumns->value(); } diff --git a/scribus/ui/inserttablerowsdialog.h b/scribus/ui/inserttablerowsdialog.h index 3d691d3c6..6f670e5d4 100644 --- a/scribus/ui/inserttablerowsdialog.h +++ b/scribus/ui/inserttablerowsdialog.h @@ -29,7 +29,7 @@ class InsertTableRowsDialog : public QDialog, private Ui::InsertTableRowsDialog public: /// Constructs a new dialog for inserting rows. @a appMode is the current application mode. - explicit InsertTableRowsDialog(int appMode, QWidget *parent = 0); + explicit InsertTableRowsDialog(int appMode, QWidget* parent = nullptr); /// Returns the number of rows the user entered. int numberOfRows() const { return numRows->value(); } diff --git a/scribus/ui/inspage.cpp b/scribus/ui/inspage.cpp index 8c4300f92..17004a21e 100644 --- a/scribus/ui/inspage.cpp +++ b/scribus/ui/inspage.cpp @@ -296,9 +296,9 @@ InsPage::InsPage( QWidget* parent, ScribusDoc* currentDoc, int currentPage, int m_unitRatio = m_doc->unitRatio(); // signals and slots connections - connect( insWhereData, SIGNAL( activated(int) ), this, SLOT( insWherePageDataDisable(int) ) ); - connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); - connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) ); + connect(insWhereData, SIGNAL( activated(int) ), this, SLOT( insWherePageDataDisable(int) ) ); + connect(okButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect(cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) ); connect(orientationQComboBox, SIGNAL(activated(int)), this, SLOT(setOrientation(int))); connect(sizeQComboBox, SIGNAL(activated(const QString &)), this, SLOT(setSize(const QString &))); connect(overrideMPSizingCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableSizingControls(int))); @@ -348,10 +348,10 @@ void InsPage::setOrientation(int ori) QStringList InsPage::getMasterPages() const { QStringList ret; - for (int n = 0; n < masterPageCombos.count(); ++n) + for (int i = 0; i < masterPageCombos.count(); ++i) { - int currentIndex = masterPageCombos.at(n)->currentIndex(); - QVariant pageVar = masterPageCombos.at(n)->itemData(currentIndex); + int currentIndex = masterPageCombos.at(i)->currentIndex(); + QVariant pageVar = masterPageCombos.at(i)->itemData(currentIndex); ret.append(pageVar.toString()); } return ret; diff --git a/scribus/ui/linecombo.cpp b/scribus/ui/linecombo.cpp index bfd5ed282..81a56489a 100644 --- a/scribus/ui/linecombo.cpp +++ b/scribus/ui/linecombo.cpp @@ -21,6 +21,10 @@ for which a new license (GPL+exception) is in place. * * ***************************************************************************/ +#include +#include +#include + #include "linecombo.h" #include "util.h" @@ -40,12 +44,31 @@ LineCombo::LineCombo(QWidget* pa) : QComboBox(pa) updateList(); } +void LineCombo::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::StyleChange) + styleChange(); + else if (e->type() == QEvent::ThemeChange) + themeChange(); + QComboBox::changeEvent(e); +} + +void LineCombo::styleChange() +{ + QSignalBlocker sigBlocker(this); + for (int i = 0; i < 37; ++i) + setItemData(i, QIcon(createIcon(i)), Qt::DecorationRole); +} + +void LineCombo::themeChange() +{ + styleChange(); +} + void LineCombo::updateList() { - for (int a = 0; a < 37; a++) - { - addItem(QIcon(createIcon(a)), ""); - } + for (int i = 0; i < 37; i++) + addItem(QIcon(createIcon(i)), QString()); } QPixmap LineCombo::createIcon(int type) @@ -63,7 +86,8 @@ QPixmap LineCombo::createIcon(int type) getDashArray(type + 1, 1, m_array); pen.setDashPattern(m_array); } - pen.setColor(Qt::black); + const QPalette& pal = this->palette(); + pen.setColor(pal.text().color()); pen.setWidth(3); pen.setCapStyle(Qt::FlatCap); p.setPen(pen); diff --git a/scribus/ui/linecombo.h b/scribus/ui/linecombo.h index 9da7f9d6d..c46cb4074 100644 --- a/scribus/ui/linecombo.h +++ b/scribus/ui/linecombo.h @@ -27,6 +27,8 @@ for which a new license (GPL+exception) is in place. #include #include +class QEvent; + #include "scribusapi.h" #include "sclistboxpixmap.h" @@ -37,11 +39,19 @@ for which a new license (GPL+exception) is in place. class SCRIBUS_API LineCombo : public QComboBox { Q_OBJECT + public: LineCombo(QWidget* pa); ~LineCombo() {} + void updateList(); + +protected: QPixmap createIcon(int type); + + void changeEvent(QEvent *e) override; + void styleChange(); + void themeChange(); }; #endif diff --git a/scribus/ui/loremipsum.h b/scribus/ui/loremipsum.h index b45fe7a77..1dd7946ae 100644 --- a/scribus/ui/loremipsum.h +++ b/scribus/ui/loremipsum.h @@ -87,7 +87,7 @@ class SCRIBUS_API LoremManager : public QDialog public: /*! Reads all XML files in cfg directory. */ - LoremManager(ScribusDoc* doc, QWidget* parent = 0); + LoremManager(ScribusDoc* doc, QWidget* parent = nullptr); /*! Apply created LI into a frame \param name filename of the selected LI diff --git a/scribus/ui/marginpresetlayout.h b/scribus/ui/marginpresetlayout.h index 6f5ae4eeb..191cb60ca 100644 --- a/scribus/ui/marginpresetlayout.h +++ b/scribus/ui/marginpresetlayout.h @@ -22,7 +22,7 @@ class SCRIBUS_API PresetLayout: public QComboBox public: /*! \brief QComboBox like constructor. Values/names are set here. Tooltip etc. too. */ - PresetLayout(QWidget *parent = 0); + PresetLayout(QWidget* parent = nullptr); ~PresetLayout(){}; /*! \brief Compute the margins here. diff --git a/scribus/ui/markinsert.h b/scribus/ui/markinsert.h index 6a6a69090..e1cea33b3 100644 --- a/scribus/ui/markinsert.h +++ b/scribus/ui/markinsert.h @@ -13,10 +13,10 @@ class SCRIBUS_API MarkInsert : public QDialog Q_OBJECT public: - MarkInsert(const QList&, QWidget *parent = 0) : QDialog(parent) {} - MarkInsert(const Mark*, QWidget *parent = 0) : QDialog(parent) {} - MarkInsert(const QList&, QWidget *parent = 0) : QDialog(parent) {} - MarkInsert(QWidget *parent = 0) : QDialog(parent) {} + MarkInsert(const QList&, QWidget* parent = nullptr) : QDialog(parent) {} + MarkInsert(const Mark*, QWidget* parent = nullptr) : QDialog(parent) {} + MarkInsert(const QList&, QWidget* parent = nullptr) : QDialog(parent) {} + MarkInsert(QWidget* parent = nullptr) : QDialog(parent) {} ~MarkInsert() {} virtual void values(QString &label) {} diff --git a/scribus/ui/markvariabletext.h b/scribus/ui/markvariabletext.h index d2343746e..16b7ca30e 100644 --- a/scribus/ui/markvariabletext.h +++ b/scribus/ui/markvariabletext.h @@ -10,8 +10,8 @@ class SCRIBUS_API MarkVariableText : public MarkInsert, private Ui::MarkVariable Q_OBJECT public: - explicit MarkVariableText(const QList&, QWidget *parent = 0); - explicit MarkVariableText(const Mark*, QWidget *parent = 0); + explicit MarkVariableText(const QList&, QWidget* parent = nullptr); + explicit MarkVariableText(const Mark*, QWidget* parent = nullptr); ~MarkVariableText(); Mark* values(QString& label, QString& text) override; diff --git a/scribus/ui/notesstyleseditor.h b/scribus/ui/notesstyleseditor.h index 2b4299310..44b3308b4 100644 --- a/scribus/ui/notesstyleseditor.h +++ b/scribus/ui/notesstyleseditor.h @@ -14,7 +14,7 @@ class SCRIBUS_API NotesStylesEditor : public ScrPaletteBase, private Ui::NotesSt Q_OBJECT public: - explicit NotesStylesEditor(QWidget *parent = 0, const char *name = "notesStylesEditor"); + explicit NotesStylesEditor(QWidget* parent = nullptr, const char *name = "notesStylesEditor"); ~NotesStylesEditor(); virtual void changeEvent(QEvent *e); diff --git a/scribus/ui/numformatcombo.h b/scribus/ui/numformatcombo.h index e257c44ec..af832287b 100644 --- a/scribus/ui/numformatcombo.h +++ b/scribus/ui/numformatcombo.h @@ -22,7 +22,7 @@ class SCRIBUS_API NumFormatCombo : public QComboBox Q_OBJECT public: - NumFormatCombo(QWidget* parent=0); + NumFormatCombo(QWidget* parent=nullptr); NumFormatCombo(QWidget* parent, bool showNone); NumFormat currentFormat() const; diff --git a/scribus/ui/pageitemattributes.h b/scribus/ui/pageitemattributes.h index 0e8c051a2..5eaacb5a2 100644 --- a/scribus/ui/pageitemattributes.h +++ b/scribus/ui/pageitemattributes.h @@ -13,7 +13,7 @@ class PageItemAttributes : public QDialog, Ui::PageItemAttributes { Q_OBJECT public: - PageItemAttributes( QWidget* parent = 0, const char* name = 0, bool modal = false); + PageItemAttributes( QWidget* parent = nullptr, const char* name = 0, bool modal = false); ~PageItemAttributes(); virtual ObjAttrVector * getNewAttributes(); diff --git a/scribus/ui/pageitempositionsetter.h b/scribus/ui/pageitempositionsetter.h index 595a5c216..14d261ae2 100644 --- a/scribus/ui/pageitempositionsetter.h +++ b/scribus/ui/pageitempositionsetter.h @@ -35,7 +35,7 @@ class PageItemPositionSetter : public PageItemSetterBase, private Ui::PositionSe Selection* m_select; public: - PageItemPositionSetter(QWidget * parent = 0); + PageItemPositionSetter(QWidget* parent = nullptr); void changeItem(Selection* sel); PageItemSetterBase* clone(); diff --git a/scribus/ui/pageitemrotationsetter.h b/scribus/ui/pageitemrotationsetter.h index 2ea587c7b..e9d13d171 100644 --- a/scribus/ui/pageitemrotationsetter.h +++ b/scribus/ui/pageitemrotationsetter.h @@ -32,7 +32,7 @@ class PageItemRotationSetter : public PageItemSetterBase, private Ui::RotationWi Selection * m_select; public: - PageItemRotationSetter(QWidget * parent = 0); + PageItemRotationSetter(QWidget* parent = nullptr); void changeItem(Selection* sel); PageItemSetterBase * clone(); diff --git a/scribus/ui/pageitemsetterbase.h b/scribus/ui/pageitemsetterbase.h index 60d354f3b..ebe1b65d1 100644 --- a/scribus/ui/pageitemsetterbase.h +++ b/scribus/ui/pageitemsetterbase.h @@ -46,7 +46,7 @@ class PageItemSetterBase : public QWidget /** * Default constructor */ - PageItemSetterBase(QWidget * parent = 0); + PageItemSetterBase(QWidget* parent = nullptr); /** * Reset parameters and internal state to reflect properties of diff --git a/scribus/ui/pdfversioncombo.h b/scribus/ui/pdfversioncombo.h index 5a0c11063..ab7d7f00e 100644 --- a/scribus/ui/pdfversioncombo.h +++ b/scribus/ui/pdfversioncombo.h @@ -24,7 +24,7 @@ class SCRIBUS_API PdfVersionCombo : public QComboBox Q_OBJECT public: - PdfVersionCombo(QWidget* parent=0); + PdfVersionCombo(QWidget* parent=nullptr); ~PdfVersionCombo(); PDFVersion version() const; diff --git a/scribus/ui/pdfversionmodel.h b/scribus/ui/pdfversionmodel.h index 5a18eceef..952eef92c 100644 --- a/scribus/ui/pdfversionmodel.h +++ b/scribus/ui/pdfversionmodel.h @@ -20,7 +20,7 @@ class SCRIBUS_API PdfVersionModel : public QAbstractItemModel public: //! Constructor - PdfVersionModel(QObject *parent = 0); + PdfVersionModel(QObject* parent = nullptr); enum PdfVersionItem { diff --git a/scribus/ui/printpreview.cpp b/scribus/ui/printpreview.cpp index 07a1b89b3..4ce42a015 100644 --- a/scribus/ui/printpreview.cpp +++ b/scribus/ui/printpreview.cpp @@ -482,7 +482,7 @@ int PrintPreview::RenderPreview(int pageIndex, int res) { QImage image; ScPage* page; - ScPrintEngine_GDI winPrint; + ScPrintEngine_GDI winPrint(*doc); PrintOptions options; page = doc->Pages->at(pageIndex); options.copies = 1; @@ -496,7 +496,7 @@ int PrintPreview::RenderPreview(int pageIndex, int res) options.toFile = false; options.useColor = !useGray->isChecked(); options.useSpotColors = false; - bool done = winPrint.gdiPrintPreview(doc, page, &image, options, res / 72.0); + bool done = winPrint.gdiPrintPreview(page, &image, options, res / 72.0); if (done) image.save( ScPaths::tempFileDir() + "/sc.png", "PNG" ); return (done ? 0 : 1); diff --git a/scribus/ui/propertiespalette_table.h b/scribus/ui/propertiespalette_table.h index f1c259fce..8bb9dfb32 100644 --- a/scribus/ui/propertiespalette_table.h +++ b/scribus/ui/propertiespalette_table.h @@ -32,7 +32,7 @@ class SCRIBUS_API PropertiesPalette_Table : public QWidget, Ui::PropertiesPalett Q_OBJECT public: - explicit PropertiesPalette_Table(QWidget *parent = 0); + explicit PropertiesPalette_Table(QWidget* parent = nullptr); ~PropertiesPalette_Table() {} /// Update the list of colors. diff --git a/scribus/ui/propertywidget_dropcap.h b/scribus/ui/propertywidget_dropcap.h index 9f4324513..1b1d86e5c 100644 --- a/scribus/ui/propertywidget_dropcap.h +++ b/scribus/ui/propertywidget_dropcap.h @@ -14,7 +14,7 @@ class PropertyWidget_DropCap : public QFrame, private Ui::PropertyWidget_DropCap Q_OBJECT public: - PropertyWidget_DropCap(QWidget *parent = 0); + PropertyWidget_DropCap(QWidget* parent = nullptr); ~PropertyWidget_DropCap() {} void updateStyle(const ParagraphStyle& newCurrent); @@ -38,7 +38,7 @@ public slots: void setMainWindow(ScribusMainWindow *mw); void setDoc(ScribusDoc *doc); - void handleAppModeChanged(int oldMode, int mode); + void handleAppModeChanged(int oldMode, int mode); void handleSelectionChanged(); void handleUpdateRequest(int); diff --git a/scribus/ui/propertywidget_pareffect.h b/scribus/ui/propertywidget_pareffect.h index db84cccf3..1223dc69d 100644 --- a/scribus/ui/propertywidget_pareffect.h +++ b/scribus/ui/propertywidget_pareffect.h @@ -18,7 +18,7 @@ class PropertyWidget_ParEffect : public QFrame, private Ui::PropertyWidget_ParEf Q_OBJECT public: - PropertyWidget_ParEffect(QWidget *parent = 0); + PropertyWidget_ParEffect(QWidget* parent = nullptr); ~PropertyWidget_ParEffect() {} void updateStyle(const ParagraphStyle& newPStyle); diff --git a/scribus/ui/query.h b/scribus/ui/query.h index 388896864..89e5e6307 100644 --- a/scribus/ui/query.h +++ b/scribus/ui/query.h @@ -23,7 +23,7 @@ class SCRIBUS_API Query : public QDialog Q_OBJECT public: - Query(QWidget* parent=0, const char* name=nullptr, bool modal = false, const QString& text=0, const QString& titel=0 ); + Query(QWidget* parent=nullptr, const char* name=nullptr, bool modal = false, const QString& text=0, const QString& titel=0 ); ~Query() {}; QString getEditText() const; diff --git a/scribus/ui/resourcemanagerlicense.h b/scribus/ui/resourcemanagerlicense.h index 2183c6920..29c582a98 100644 --- a/scribus/ui/resourcemanagerlicense.h +++ b/scribus/ui/resourcemanagerlicense.h @@ -37,7 +37,7 @@ class SCRIBUS_API ResourceManagerLicense : public QDialog, Ui::ResourceManagerLi Q_OBJECT public: - ResourceManagerLicense(QWidget * parent = 0, Qt::WindowFlags f = 0); + ResourceManagerLicense(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); ~ResourceManagerLicense() {}; void setText(const QString& s); diff --git a/scribus/ui/sccolorslider.h b/scribus/ui/sccolorslider.h index 8839a7105..125965075 100644 --- a/scribus/ui/sccolorslider.h +++ b/scribus/ui/sccolorslider.h @@ -19,7 +19,7 @@ class SCRIBUS_API ScColorSlider : public QSlider Q_OBJECT public: - ScColorSlider(QWidget* parent = 0); + ScColorSlider(QWidget* parent = nullptr); virtual void paintEvent(QPaintEvent * p); }; diff --git a/scribus/ui/scdockpalette.h b/scribus/ui/scdockpalette.h index e4f31792d..d39209bd5 100644 --- a/scribus/ui/scdockpalette.h +++ b/scribus/ui/scdockpalette.h @@ -40,7 +40,7 @@ class SCRIBUS_API ScDockPalette : public QDockWidget Q_OBJECT public: - ScDockPalette( QWidget * parent = nullptr, const QString& prefsContext = QString(), Qt::WindowFlags f = 0 ); + ScDockPalette( QWidget * parent = nullptr, const QString& prefsContext = QString(), Qt::WindowFlags f = Qt::WindowFlags() ); ~ScDockPalette() {} /** @brief Sample way to grab keystrokes, simply calls superclass at this point */ //virtual void keyPressEvent(QKeyEvent *keyEvent); diff --git a/scribus/ui/scinputdialog.h b/scribus/ui/scinputdialog.h index 63a0120f3..52037d99b 100644 --- a/scribus/ui/scinputdialog.h +++ b/scribus/ui/scinputdialog.h @@ -27,7 +27,7 @@ class ScInputDialog : public QDialog Q_OBJECT public: - ScInputDialog( QWidget* parent = 0, const char* name = 0, bool modal = false); + ScInputDialog( QWidget* parent = nullptr, const char* name = 0, bool modal = false); ~ScInputDialog(){}; virtual void changeEvent(QEvent *e); @@ -40,7 +40,7 @@ class ScInputDialog : public QDialog static double getDouble(const QString &caption, const QString &label, double num = 0, double from = -2147483647, double to = 2147483647, int decimals = 1, const QString& suffix = "", bool *ok = 0, - QWidget *parent = 0, const char *name = 0 ); + QWidget* parent = nullptr, const char *name = 0 ); protected: QVBoxLayout* ScInputDialogLayout; diff --git a/scribus/ui/scprogressbar.h b/scribus/ui/scprogressbar.h index 5f14c2793..608a3d093 100644 --- a/scribus/ui/scprogressbar.h +++ b/scribus/ui/scprogressbar.h @@ -33,8 +33,8 @@ class ScProgressBar : public QProgressBar Q_OBJECT public: - ScProgressBar( bool showNumbers, QWidget *parent=0); - ScProgressBar( bool showNumbers, int totalSteps, QWidget* parent=0); + ScProgressBar( bool showNumbers, QWidget* parent=nullptr); + ScProgressBar( bool showNumbers, int totalSteps, QWidget* parent=nullptr); virtual bool setIndicator( QString & indicator, int progress, int totalSteps ); ~ScProgressBar(); diff --git a/scribus/ui/scrpalettebase.h b/scribus/ui/scrpalettebase.h index 1b48b2517..1ff57993b 100644 --- a/scribus/ui/scrpalettebase.h +++ b/scribus/ui/scrpalettebase.h @@ -40,7 +40,7 @@ class SCRIBUS_API ScrPaletteBase : public QDialog Q_OBJECT public: - ScrPaletteBase( QWidget * parent = nullptr, const QString& prefsContext = QString(), bool modal = false, Qt::WindowFlags f = nullptr); + ScrPaletteBase( QWidget * parent = nullptr, const QString& prefsContext = QString(), bool modal = false, Qt::WindowFlags f = Qt::WindowFlags()); ~ScrPaletteBase() {} /** @brief Sample way to grab keystrokes, simply calls superclass at this point */ //virtual void keyPressEvent(QKeyEvent *keyEvent); diff --git a/scribus/ui/sctablewidget.h b/scribus/ui/sctablewidget.h index f1d7620c9..a9d1b418b 100644 --- a/scribus/ui/sctablewidget.h +++ b/scribus/ui/sctablewidget.h @@ -18,8 +18,8 @@ class ScTableWidget : public QTableWidget Q_OBJECT public: - ScTableWidget ( QWidget * parent = 0 ); - ScTableWidget ( int rows, int columns, QWidget * parent = 0 ); + ScTableWidget ( QWidget* parent = nullptr ); + ScTableWidget ( int rows, int columns, QWidget* parent = nullptr ); ~ScTableWidget (); void setCellWidget ( int row, int column, QWidget * widget ); void removeCellWidget ( int row, int column ); diff --git a/scribus/ui/shortcutwidget.h b/scribus/ui/shortcutwidget.h index 316a2d905..bd7781276 100644 --- a/scribus/ui/shortcutwidget.h +++ b/scribus/ui/shortcutwidget.h @@ -23,7 +23,7 @@ class ShortcutWidget : public QWidget, public Ui::ShortcutWidget Q_OBJECT public: - ShortcutWidget(QWidget *parent = 0); + ShortcutWidget(QWidget* parent = nullptr); ~ShortcutWidget(); diff --git a/scribus/ui/smcellstylewidget.h b/scribus/ui/smcellstylewidget.h index 3e98ec2df..530bcfc80 100644 --- a/scribus/ui/smcellstylewidget.h +++ b/scribus/ui/smcellstylewidget.h @@ -26,7 +26,7 @@ class SMCellStyleWidget : public QWidget, public Ui::SMCellStyleWidget public: /// Constructor. - SMCellStyleWidget(QWidget *parent = 0); + SMCellStyleWidget(QWidget* parent = nullptr); /// Destructor. ~SMCellStyleWidget(); diff --git a/scribus/ui/smcstylewidget.h b/scribus/ui/smcstylewidget.h index 3208dd507..6dd3e1cc1 100644 --- a/scribus/ui/smcstylewidget.h +++ b/scribus/ui/smcstylewidget.h @@ -19,7 +19,7 @@ class SMCStyleWidget : public QWidget, public Ui::SMCStyleWidget { Q_OBJECT public: - SMCStyleWidget(QWidget *parent = 0); + SMCStyleWidget(QWidget* parent = nullptr); ~SMCStyleWidget(); virtual void changeEvent(QEvent *e); diff --git a/scribus/ui/smtablestylewidget.h b/scribus/ui/smtablestylewidget.h index bb53ff9aa..2e1471e85 100644 --- a/scribus/ui/smtablestylewidget.h +++ b/scribus/ui/smtablestylewidget.h @@ -25,7 +25,7 @@ class SMTableStyleWidget : public QWidget, public Ui::SMTableStyleWidget Q_OBJECT public: /// Constructor. - SMTableStyleWidget(QWidget *parent = 0); + SMTableStyleWidget(QWidget* parent = nullptr); /// Destructor. ~SMTableStyleWidget(); diff --git a/scribus/ui/smtextstyles.cpp b/scribus/ui/smtextstyles.cpp index c69755f7e..26b8301ff 100644 --- a/scribus/ui/smtextstyles.cpp +++ b/scribus/ui/smtextstyles.cpp @@ -319,11 +319,7 @@ void SMParagraphStyle::setDefaultStyle(bool ids) m_selection[0]->setDefaultStyle(ids); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } QString SMParagraphStyle::shortcut(const QString &stylename) const @@ -355,11 +351,7 @@ void SMParagraphStyle::setShortcut(const QString &shortcut) m_selection[0]->setShortcut(shortcut); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::deleteStyles(const QList &removeList) @@ -453,11 +445,7 @@ void SMParagraphStyle::nameChanged(const QString &newName) if (oldName != newName) m_deleted.append(RemoveItem(oldName, newName)); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::languageChange() @@ -696,11 +684,7 @@ void SMParagraphStyle::slotLineSpacingMode(int mode) for (int i = 0; i < m_selection.count(); ++i) m_selection[i]->setLineSpacingMode(lsm); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotLineSpacing() @@ -718,11 +702,7 @@ void SMParagraphStyle::slotLineSpacing() m_selection[i]->setLineSpacing(value); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotSpaceAbove() @@ -740,11 +720,7 @@ void SMParagraphStyle::slotSpaceAbove() m_selection[i]->setGapBefore(value); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotSpaceBelow() @@ -762,11 +738,7 @@ void SMParagraphStyle::slotSpaceBelow() m_selection[i]->setGapAfter(value); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotAlignment() @@ -779,11 +751,7 @@ void SMParagraphStyle::slotAlignment() for (int i = 0; i < m_selection.count(); ++i) m_selection[i]->setAlignment(style); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotDirection() @@ -796,11 +764,7 @@ void SMParagraphStyle::slotDirection() for (int i = 0; i < m_selection.count(); ++i) m_selection[i]->setDirection(style); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotOpticalMargin(int i) @@ -813,34 +777,21 @@ void SMParagraphStyle::slotOpticalMargin(int i) // for (int i = 0; i < m_selection.count(); ++i) // m_selection[i]->setOpticalMargins(omt); // -// if (!m_selectionIsDirty) -// { -// m_selectionIsDirty = true; -// emit selectionDirty(); -// } +// slotSelectionDirty(); } void SMParagraphStyle::slotOpticalMarginSelector() { int omt(ParagraphStyle::OM_None); - if (false)//(m_pwidget->optMarginCombo->useParentValue()) - { - } - else - { -// if (m_pwidget->optMarginRadioNone->isChecked()) omt = aragraphStyle::OM_None; - if (m_pwidget->optMarginRadioRight->isChecked()) omt = ParagraphStyle::OM_RightHangingPunct; - else if (m_pwidget->optMarginRadioLeft->isChecked()) omt = ParagraphStyle::OM_LeftHangingPunct; - else if (m_pwidget->optMarginRadioBoth->isChecked()) omt = ParagraphStyle::OM_Default; - for (int i = 0; i < m_selection.count(); ++i) - m_selection[i]->setOpticalMargins(omt); - } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + if (m_pwidget->optMarginRadioRight->isChecked()) omt = ParagraphStyle::OM_RightHangingPunct; + else if (m_pwidget->optMarginRadioLeft->isChecked()) omt = ParagraphStyle::OM_LeftHangingPunct; + else if (m_pwidget->optMarginRadioBoth->isChecked()) omt = ParagraphStyle::OM_Default; + + for (int i = 0; i < m_selection.count(); ++i) + m_selection[i]->setOpticalMargins(omt); + + slotSelectionDirty(); } void SMParagraphStyle::slotParentOpticalMargin() @@ -848,11 +799,7 @@ void SMParagraphStyle::slotParentOpticalMargin() for (int i = 0; i < m_selection.count(); ++i) m_selection[i]->resetOpticalMargins(); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotMinSpace() @@ -867,11 +814,7 @@ void SMParagraphStyle::slotMinSpace() m_selection[i]->setMinWordTracking(ms / 100.0); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotMinGlyphExt() @@ -886,11 +829,7 @@ void SMParagraphStyle::slotMinGlyphExt() m_selection[i]->setMinGlyphExtension(mge / 100.0); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotMaxGlyphExt() @@ -905,11 +844,7 @@ void SMParagraphStyle::slotMaxGlyphExt() m_selection[i]->setMaxGlyphExtension(mge / 100.0); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotConsecutiveLines() @@ -923,11 +858,8 @@ void SMParagraphStyle::slotConsecutiveLines() for (int i = 0; i < m_selection.count(); ++i) m_selection[i]->setHyphenConsecutiveLines(cL); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + + slotSelectionDirty(); } void SMParagraphStyle::slotDropCap(bool isOn) @@ -942,11 +874,7 @@ void SMParagraphStyle::slotDropCap(bool isOn) } } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotParentParaEffects() @@ -958,11 +886,7 @@ void SMParagraphStyle::slotParentParaEffects() m_selection[i]->resetHasNum(); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotDropCapLines(int lines) @@ -974,11 +898,7 @@ void SMParagraphStyle::slotDropCapLines(int lines) for (int i = 0; i < m_selection.count(); ++i) m_selection[i]->setDropCapLines(lines); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotParEffectOffset() @@ -997,11 +917,7 @@ void SMParagraphStyle::slotParEffectOffset() m_selection[i]->setParEffectOffset(value); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotParEffectIndent(bool isOn) @@ -1015,11 +931,7 @@ void SMParagraphStyle::slotParEffectIndent(bool isOn) m_selection[i]->setParEffectIndent(isOn); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotParEffectCharStyle(int index) @@ -1036,11 +948,7 @@ void SMParagraphStyle::slotParEffectCharStyle(int index) for (int i = 0; i < m_selection.count(); ++i) m_selection[i]->setPeCharStyleName(name); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotBullet(bool isOn) @@ -1056,11 +964,7 @@ void SMParagraphStyle::slotBullet(bool isOn) } } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotBulletStr(const QString &str) @@ -1074,11 +978,7 @@ void SMParagraphStyle::slotBulletStr(const QString &str) for (int i = 0; i < m_selection.count(); ++i) m_selection[i]->setBulletStr(bstr); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotNumeration(bool isOn) @@ -1093,20 +993,15 @@ void SMParagraphStyle::slotNumeration(bool isOn) } } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotNumName(const QString &str) { - QString bstr(str); if (!str.isEmpty()) { for (int i = 0; i < m_selection.count(); ++i) - m_selection[i]->setNumName(bstr); + m_selection[i]->setNumName(str); m_pwidget->numComboBox->setCurrentItem(m_pwidget->numComboBox->findText(m_selection[0]->numName())); m_pwidget->numLevelSpin->setValue(m_selection[0]->numLevel()+1); NumStruct * numS = m_doc->numerations.value(m_selection[0]->numName()); @@ -1117,11 +1012,7 @@ void SMParagraphStyle::slotNumName(const QString &str) m_doc->flag_NumUpdateRequest = true; } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotNumNew() @@ -1134,20 +1025,15 @@ void SMParagraphStyle::slotNumNew() m_doc->flag_NumUpdateRequest = true; } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotSelectionDirty() { - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + if (m_selectionIsDirty) + return; + m_selectionIsDirty = true; + emit selectionDirty(); } void SMParagraphStyle::slotNumFormat(int) @@ -1162,11 +1048,7 @@ void SMParagraphStyle::slotNumFormat(int) m_selection[i]->setNumFormat(numFormat); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotNumLevel(int level) @@ -1182,11 +1064,8 @@ void SMParagraphStyle::slotNumLevel(int level) if (level == 0) slotNumHigher(false); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + + slotSelectionDirty(); } void SMParagraphStyle::slotNumPrefix(const QString &str) @@ -1194,11 +1073,7 @@ void SMParagraphStyle::slotNumPrefix(const QString &str) for (int i = 0; i < m_selection.count(); ++i) m_selection[i]->setNumPrefix(str); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotNumSuffix(const QString &str) @@ -1206,11 +1081,7 @@ void SMParagraphStyle::slotNumSuffix(const QString &str) for (int i = 0; i < m_selection.count(); ++i) m_selection[i]->setNumSuffix(str); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotNumStart(int start) @@ -1222,11 +1093,7 @@ void SMParagraphStyle::slotNumStart(int start) for (int i = 0; i < m_selection.count(); ++i) m_selection[i]->setNumStart(start); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotNumRestart(int restart) @@ -1240,11 +1107,7 @@ void SMParagraphStyle::slotNumRestart(int restart) for (int i = 0; i < m_selection.count(); ++i) m_selection[i]->setNumRestart(restartRange); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotNumOther(bool isOn) @@ -1258,11 +1121,7 @@ void SMParagraphStyle::slotNumOther(bool isOn) m_selection[i]->setNumOther(isOn); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotNumHigher(bool isOn) @@ -1276,11 +1135,7 @@ void SMParagraphStyle::slotNumHigher(bool isOn) m_selection[i]->setNumHigher(isOn); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } @@ -1296,11 +1151,7 @@ void SMParagraphStyle::handleKeepLinesStart() m_selection[i]->setKeepLinesStart (value); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::handleKeepLinesEnd() @@ -1315,11 +1166,7 @@ void SMParagraphStyle::handleKeepLinesEnd() m_selection[i]->setKeepLinesEnd (value); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::handleKeepTogether() @@ -1334,11 +1181,7 @@ void SMParagraphStyle::handleKeepTogether() m_selection[i]->setKeepTogether (value); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::handleKeepWithNext() @@ -1353,11 +1196,7 @@ void SMParagraphStyle::handleKeepWithNext() m_selection[i]->setKeepWithNext (value); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotTabRuler() @@ -1374,11 +1213,7 @@ void SMParagraphStyle::slotTabRuler() m_selection[i]->setTabValues(newTabs); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotLeftIndent() @@ -1397,11 +1232,7 @@ void SMParagraphStyle::slotLeftIndent() m_selection[i]->setLeftMargin(value); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotRightIndent() @@ -1420,11 +1251,7 @@ void SMParagraphStyle::slotRightIndent() m_selection[i]->setRightMargin(value); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotFirstLine() @@ -1443,11 +1270,7 @@ void SMParagraphStyle::slotFirstLine() m_selection[i]->setFirstIndent(value); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotFontSize() @@ -1467,11 +1290,7 @@ void SMParagraphStyle::slotFontSize() } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotEffects(int e) @@ -1531,12 +1350,7 @@ void SMParagraphStyle::slotEffects(int e) } } - - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotEffectProperties() @@ -1573,11 +1387,7 @@ void SMParagraphStyle::slotEffectProperties() m_selection[i]->charStyle().setStrikethruWidth(qRound(slw)); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotFillColor() @@ -1593,11 +1403,7 @@ void SMParagraphStyle::slotFillColor() m_selection[i]->charStyle().setFillColor(col); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotFillShade() @@ -1612,11 +1418,7 @@ void SMParagraphStyle::slotFillShade() m_selection[i]->charStyle().setFillShade(fs); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotBackPColor() @@ -1632,11 +1434,7 @@ void SMParagraphStyle::slotBackPColor() m_selection[i]->setBackgroundColor(col); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotBackPShade() @@ -1651,11 +1449,7 @@ void SMParagraphStyle::slotBackPShade() m_selection[i]->setBackgroundShade(fs); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotBackColor() @@ -1671,11 +1465,7 @@ void SMParagraphStyle::slotBackColor() m_selection[i]->charStyle().setBackColor(col); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotBackShade() @@ -1690,11 +1480,7 @@ void SMParagraphStyle::slotBackShade() m_selection[i]->charStyle().setBackShade(fs); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotStrokeColor() @@ -1710,11 +1496,7 @@ void SMParagraphStyle::slotStrokeColor() m_selection[i]->charStyle().setStrokeColor(col); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotStrokeShade() @@ -1730,11 +1512,7 @@ void SMParagraphStyle::slotStrokeShade() m_selection[i]->charStyle().setStrokeShade(ss); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotLanguage() @@ -1755,11 +1533,7 @@ void SMParagraphStyle::slotLanguage() m_selection[i]->charStyle().setLanguage(language); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotWordMin() @@ -1775,11 +1549,7 @@ void SMParagraphStyle::slotWordMin() m_selection[i]->charStyle().setHyphenWordMin(wm); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotHyphenChar() @@ -1795,11 +1565,7 @@ void SMParagraphStyle::slotHyphenChar() m_selection[i]->charStyle().setHyphenChar(ch); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotScaleH() @@ -1817,11 +1583,7 @@ void SMParagraphStyle::slotScaleH() m_selection[i]->charStyle().setScaleH(qRound(value)); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotScaleV() @@ -1839,11 +1601,7 @@ void SMParagraphStyle::slotScaleV() m_selection[i]->charStyle().setScaleV(qRound(value)); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotTracking() @@ -1861,11 +1619,7 @@ void SMParagraphStyle::slotTracking() m_selection[i]->charStyle().setTracking(qRound(value)); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotWordTracking() @@ -1883,11 +1637,7 @@ void SMParagraphStyle::slotWordTracking() m_selection[i]->charStyle().setWordTracking(value); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotBaselineOffset() @@ -1905,11 +1655,7 @@ void SMParagraphStyle::slotBaselineOffset() m_selection[i]->charStyle().setBaselineOffset(qRound(value)); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotFont(const QString& s) @@ -1924,11 +1670,7 @@ void SMParagraphStyle::slotFont(const QString& s) m_selection[i]->charStyle().setFont(sf); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotParentChanged(const QString &parent) @@ -1967,11 +1709,7 @@ void SMParagraphStyle::slotParentChanged(const QString &parent) selected(sel); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotCharParentChanged(const QString &parent) @@ -1991,11 +1729,7 @@ void SMParagraphStyle::slotCharParentChanged(const QString &parent) selected(sel); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotFontFeatures() @@ -2010,11 +1744,7 @@ void SMParagraphStyle::slotFontFeatures() m_selection[i]->charStyle().setFontFeatures(fontfeatures); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMParagraphStyle::slotCharStylesDeleted(const QList &removeList) @@ -2316,11 +2046,7 @@ void SMCharacterStyle::setDefaultStyle(bool ids) m_selection[0]->setDefaultStyle(ids); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } QString SMCharacterStyle::shortcut(const QString &stylename) const @@ -2350,11 +2076,7 @@ void SMCharacterStyle::setShortcut(const QString &shortcut) m_selection[0]->setShortcut(shortcut); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::deleteStyles(const QList &removeList) @@ -2454,11 +2176,7 @@ void SMCharacterStyle::nameChanged(const QString &newName) emit charStylesDeleted(deletedStyles); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::languageChange() @@ -2566,11 +2284,7 @@ void SMCharacterStyle::slotFontSize() m_selection[i]->setFontSize(qRound(value)); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotEffects(int e) @@ -2630,12 +2344,7 @@ void SMCharacterStyle::slotEffects(int e) } } - - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotEffectProperties() @@ -2672,11 +2381,7 @@ void SMCharacterStyle::slotEffectProperties() m_selection[i]->setStrikethruWidth(qRound(slw)); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotFillColor() @@ -2692,11 +2397,7 @@ void SMCharacterStyle::slotFillColor() m_selection[i]->setFillColor(col); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotFillShade() @@ -2711,11 +2412,7 @@ void SMCharacterStyle::slotFillShade() m_selection[i]->setFillShade(fs); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotBackColor() @@ -2731,11 +2428,7 @@ void SMCharacterStyle::slotBackColor() m_selection[i]->setBackColor(col); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotBackShade() @@ -2750,11 +2443,7 @@ void SMCharacterStyle::slotBackShade() m_selection[i]->setBackShade(fs); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotStrokeColor() @@ -2770,11 +2459,7 @@ void SMCharacterStyle::slotStrokeColor() m_selection[i]->setStrokeColor(col); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotStrokeShade() @@ -2789,11 +2474,7 @@ void SMCharacterStyle::slotStrokeShade() m_selection[i]->setStrokeShade(ss); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotLanguage() @@ -2812,12 +2493,7 @@ void SMCharacterStyle::slotLanguage() m_selection[i]->setLanguage(language); } - - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotScaleH() @@ -2836,12 +2512,7 @@ void SMCharacterStyle::slotScaleH() m_selection[i]->setScaleH(qRound(value)); } - - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotScaleV() @@ -2860,12 +2531,7 @@ void SMCharacterStyle::slotScaleV() m_selection[i]->setScaleV(qRound(value)); } - - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotTracking() @@ -2884,11 +2550,7 @@ void SMCharacterStyle::slotTracking() m_selection[i]->setTracking(qRound(value)); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotWordTracking() @@ -2907,11 +2569,7 @@ void SMCharacterStyle::slotWordTracking() m_selection[i]->setWordTracking(value); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotBaselineOffset() @@ -2930,11 +2588,7 @@ void SMCharacterStyle::slotBaselineOffset() m_selection[i]->setBaselineOffset(qRound(value)); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotHyphenChar() @@ -2950,11 +2604,7 @@ void SMCharacterStyle::slotHyphenChar() m_selection[i]->setHyphenChar(ch); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotSmallestWord() @@ -2969,11 +2619,7 @@ void SMCharacterStyle::slotSmallestWord() m_selection[i]->setHyphenWordMin(sw); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotFont(const QString& s) @@ -2988,11 +2634,7 @@ void SMCharacterStyle::slotFont(const QString& s) m_selection[i]->setFont(sf); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotParentChanged(const QString &parent) @@ -3030,11 +2672,7 @@ void SMCharacterStyle::slotParentChanged(const QString &parent) selected(sel); - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + slotSelectionDirty(); } void SMCharacterStyle::slotFontFeatures() @@ -3049,11 +2687,16 @@ void SMCharacterStyle::slotFontFeatures() for (int i = 0; i < m_selection.count(); ++i) m_selection[i]->setFontFeatures(fontfeatures); } - if (!m_selectionIsDirty) - { - m_selectionIsDirty = true; - emit selectionDirty(); - } + + slotSelectionDirty(); +} + +void SMCharacterStyle::slotSelectionDirty() +{ + if (m_selectionIsDirty) + return; + m_selectionIsDirty = true; + emit selectionDirty(); } SMCharacterStyle::~SMCharacterStyle() diff --git a/scribus/ui/smtextstyles.h b/scribus/ui/smtextstyles.h index abac4e527..6d5f3ed10 100644 --- a/scribus/ui/smtextstyles.h +++ b/scribus/ui/smtextstyles.h @@ -208,6 +208,7 @@ private slots: void slotFont(const QString& s); void slotParentChanged(const QString &parent); void slotFontFeatures(); + void slotSelectionDirty(); }; #endif diff --git a/scribus/ui/splash.h b/scribus/ui/splash.h index 36971e612..4b8908fdb 100644 --- a/scribus/ui/splash.h +++ b/scribus/ui/splash.h @@ -24,7 +24,7 @@ class SCRIBUS_API ScSplashScreen : public QSplashScreen \author Franz Schmid \brief Constructor for SplashScreen */ - ScSplashScreen ( const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = 0 ); + ScSplashScreen ( const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = Qt::WindowFlags() ); ~ScSplashScreen() {} /*! \author Franz Schmid diff --git a/scribus/ui/stylemanager.h b/scribus/ui/stylemanager.h index 07c5fa19d..5fff3f04b 100644 --- a/scribus/ui/stylemanager.h +++ b/scribus/ui/stylemanager.h @@ -25,7 +25,7 @@ class SCRIBUS_API StyleManager : public ScrPaletteBase, Ui::StyleManager { Q_OBJECT public: - StyleManager(QWidget *parent = 0, const char *name = "StyleManager"); + StyleManager(QWidget* parent = nullptr, const char *name = "StyleManager"); ~StyleManager(); virtual void changeEvent(QEvent *e); diff --git a/scribus/ui/tablecolumnwidthsdialog.h b/scribus/ui/tablecolumnwidthsdialog.h index be5842c36..6c284569b 100644 --- a/scribus/ui/tablecolumnwidthsdialog.h +++ b/scribus/ui/tablecolumnwidthsdialog.h @@ -21,7 +21,7 @@ class TableColumnWidthsDialog : public QDialog, private Ui::TableColumnWidthsDia Q_OBJECT public: /// Constructs a new dialog. The dialog will use the unit of @a doc. - explicit TableColumnWidthsDialog(ScribusDoc* doc, QWidget *parent = 0); + explicit TableColumnWidthsDialog(ScribusDoc* doc, QWidget* parent = nullptr); /// Returns the column width the user entered. double columnWidth() const; diff --git a/scribus/ui/tablerowheightsdialog.h b/scribus/ui/tablerowheightsdialog.h index 6d7e7924d..8c2a0967e 100644 --- a/scribus/ui/tablerowheightsdialog.h +++ b/scribus/ui/tablerowheightsdialog.h @@ -21,7 +21,7 @@ class TableRowHeightsDialog : public QDialog, private Ui::TableRowHeightsDialog Q_OBJECT public: /// Constructs a new dialog. The dialog will use the unit of @a doc. - explicit TableRowHeightsDialog(ScribusDoc* doc, QWidget *parent = 0); + explicit TableRowHeightsDialog(ScribusDoc* doc, QWidget* parent = nullptr); /// Returns the row height the user entered. double rowHeight() const; diff --git a/scribus/ui/unicodesearch.h b/scribus/ui/unicodesearch.h index 8201f8e4d..bcfa5656c 100644 --- a/scribus/ui/unicodesearch.h +++ b/scribus/ui/unicodesearch.h @@ -31,7 +31,7 @@ class SCRIBUS_API UnicodeSearch : public QDialog, public Ui::UnicodeSearch /*! \brief QDialog like constructor \param parent standard qt widget */ - UnicodeSearch(QWidget* parent = 0); + UnicodeSearch(QWidget* parent = nullptr); ~UnicodeSearch(); signals: @@ -71,7 +71,7 @@ class UnicodeSearchModel : public QAbstractTableModel Q_OBJECT public: - UnicodeSearchModel(QObject * parent = 0); + UnicodeSearchModel(QObject* parent = nullptr); ~UnicodeSearchModel(); int rowCount(const QModelIndex & parent = QModelIndex()) const; diff --git a/scribus/undogui.h b/scribus/undogui.h index fea5c9b67..ea833912e 100644 --- a/scribus/undogui.h +++ b/scribus/undogui.h @@ -67,7 +67,7 @@ class SCRIBUS_API UndoGui : public ScDockPalette * @param name Name of the object * @param f widget flags */ - UndoGui(QWidget* parent = 0, const char* name = "UndoGui", Qt::WindowFlags f = 0); + UndoGui(QWidget* parent = nullptr, const char* name = "UndoGui", Qt::WindowFlags f = Qt::WindowFlags()); /** @brief Destroys the widget */ virtual ~UndoGui() {} @@ -164,7 +164,7 @@ class SCRIBUS_API UndoWidget : public UndoGui void updateRedoMenu(); public: /** @brief Creates a new UndoWidget instance. */ - UndoWidget(QWidget* parent = 0, const char* name = 0); + UndoWidget(QWidget* parent = nullptr, const char* name = 0); /** @brief Destroys the widget */ virtual ~UndoWidget(); @@ -317,7 +317,7 @@ class SCRIBUS_API UndoPalette : public UndoGui QPixmap *targetPixmap, QPixmap *actionPixmap, bool isUndoAction, - QListWidget * parent = 0); + QListWidget* parent = nullptr); ~UndoItem(); /*void paint(QPainter *painter); int height(const QListWidget*) const; @@ -344,7 +344,7 @@ private slots: * Creates a new UndoPalette instance. After creation of an UndoPalette it must * be registered to the UndoManager with UndoManager's registerGui() method. */ - UndoPalette(QWidget* parent = 0, const char* name = 0); + UndoPalette(QWidget* parent = nullptr, const char* name = 0); /** @brief Destroys the widget */ ~UndoPalette(); diff --git a/win32/msvc2015/scribus-main/Scribus.vcxproj b/win32/msvc2015/scribus-main/Scribus.vcxproj index e61d39a83..917f3323e 100644 --- a/win32/msvc2015/scribus-main/Scribus.vcxproj +++ b/win32/msvc2015/scribus-main/Scribus.vcxproj @@ -347,6 +347,7 @@ + @@ -891,6 +892,7 @@ + diff --git a/win32/msvc2015/scribus-main/Scribus.vcxproj.filters b/win32/msvc2015/scribus-main/Scribus.vcxproj.filters index 14b3109a8..cfe7f9305 100644 --- a/win32/msvc2015/scribus-main/Scribus.vcxproj.filters +++ b/win32/msvc2015/scribus-main/Scribus.vcxproj.filters @@ -806,13 +806,7 @@ Header Files - - Header Files - - - Header Files - - + Header Files @@ -2524,6 +2518,9 @@ Source Files + + Source Files + @@ -4169,6 +4166,15 @@ Header Files + + Header Files + + + Header Files + + + Header Files + diff --git a/win32/msvc2017/scribus-main/Scribus.vcxproj b/win32/msvc2017/scribus-main/Scribus.vcxproj index ff0331899..04e2fc2d8 100644 --- a/win32/msvc2017/scribus-main/Scribus.vcxproj +++ b/win32/msvc2017/scribus-main/Scribus.vcxproj @@ -347,6 +347,7 @@ + @@ -891,6 +892,7 @@ + diff --git a/win32/msvc2017/scribus-main/Scribus.vcxproj.filters b/win32/msvc2017/scribus-main/Scribus.vcxproj.filters index 14b3109a8..cfe7f9305 100644 --- a/win32/msvc2017/scribus-main/Scribus.vcxproj.filters +++ b/win32/msvc2017/scribus-main/Scribus.vcxproj.filters @@ -806,13 +806,7 @@ Header Files - - Header Files - - - Header Files - - + Header Files @@ -2524,6 +2518,9 @@ Source Files + + Source Files + @@ -4169,6 +4166,15 @@ Header Files + + Header Files + + + Header Files + + + Header Files +