Index: scribus/pdflib_core.cpp =================================================================== --- scribus/pdflib_core.cpp (revision 27864) +++ scribus/pdflib_core.cpp (working copy) @@ -658,7 +658,9 @@ QMap pageNsMpa; for (uint a = 0; a < pageNs.size(); ++a) { - pageNsMpa.insert(doc.MasterNames[doc.DocPages.at(pageNs[a] - 1)->masterPageName()], 0); + const int masterIndex = doc.appliedMasterPageIndex(doc.DocPages.at(pageNs[a] - 1)); + if (masterIndex >= 0) + pageNsMpa.insert(masterIndex, 0); } if (usingGUI) { @@ -2577,22 +2579,18 @@ QByteArray tmpOut; ActPageP = pag; PageItem* ite; - QList PItems; + const QList PItems = doc.masterItemsForMasterPage(pag); ScLayer ll; ll.isPrintable = false; ll.ID = 0; Content.clear(); - double bLeft, bRight, bBottom, bTop; - getBleeds(pag, bLeft, bRight, bBottom, bTop); - pageData.AObjects.clear(); for (int la = 0; la < doc.Layers.count(); ++la) { doc.Layers.levelToLayer(ll, la); - PItems = doc.MasterItems; if (!ll.isPrintable && !Options.exportsLayers()) continue; @@ -2604,21 +2602,10 @@ ite = PItems.at(a); if (ite->m_layerID != ll.ID) continue; - double x = pag->xOffset() - bLeft; - double y = pag->yOffset() - bTop; - double w = pag->width() + bLeft + bRight; - double h1 = pag->height() + bBottom + bTop; - double ilw= ite->visualLineWidth(); - double x2 = ite->BoundingX - ilw / 2.0; - double y2 = ite->BoundingY - ilw / 2.0; - double w2 = ite->BoundingW + ilw; - double h2 = ite->BoundingH + ilw; - if (!QRectF(x2, y2, w2, h2).intersects(QRectF(x, y, w, h1))) + if (!masterItemIntersectsPage(pag, ite)) continue; if (ite->ChangedMasterItem) continue; - if ((!pag->pageNameEmpty()) && (ite->OwnPage != pag->pageNr()) && (ite->OwnPage != -1)) - continue; PutPage("q\n"); if ((ite->doOverprint) && (!Options.UseRGB)) { @@ -3785,38 +3772,52 @@ bool PDFLibCore::PDF_ProcessMasterElements(const ScLayer& layer, const ScPage* pag, uint PNr) { - PageItem* ite; QByteArray content, output; -// QList PItems; - if (pag->masterPageNameEmpty()) + const int masterIndex = doc.appliedMasterPageIndex(pag); + if (masterIndex < 0) return true; - if (doc.MasterItems.count() <= 0) + const ScPage* masterPage = doc.MasterPages.at(masterIndex); + const QList masterItems = doc.masterItemsForAppliedPage(pag); + if (masterItems.isEmpty()) return true; - const ScPage* mPage = doc.MasterPages.at(doc.MasterNames[doc.DocPages.at(PNr)->masterPageName()]); - int mPageIndex = doc.MasterPages.indexOf((ScPage* const) mPage) + 1; if (!Options.MirrorH) PutPage("1 0 0 1 0 0 cm\n"); if (!layer.isPrintable && !Options.exportsLayers()) return true; + const bool clipLogicalSpread = doc.isMasterSpread(masterPage->masterPageId()); + if (clipLogicalSpread) + { + double bleedLeft = 0.0; + double bleedRight = 0.0; + double bleedBottom = 0.0; + double bleedTop = 0.0; + getBleeds(pag, bleedLeft, bleedRight, bleedBottom, bleedTop); + PutPage("q\n"); + PutPage(FToStr(-bleedLeft) + " " + FToStr(-bleedBottom) + " " + + FToStr(pag->width() + bleedLeft + bleedRight) + " " + + FToStr(pag->height() + bleedBottom + bleedTop) + " re W n\n"); + } + if (Options.exportsLayers()) PutPage("/OC /" + OCGEntries[layer.Name].Name + " BDC\n"); - for (int i = 0; i < pag->FromMaster.count() && !abortExport; ++i) + for (PageItem* item : masterItems) { - ite = pag->FromMaster.at(i); + if (abortExport) + break; if (usingGUI) QApplication::processEvents(); - if ((ite->m_layerID != layer.ID) || (!ite->printEnabled())) + if ((item->m_layerID != layer.ID) || (!item->printEnabled())) continue; - if ((!pag->pageNameEmpty()) && (ite->OwnPage != pag->pageNr()) && (ite->OwnPage != -1)) + if (!masterItemIntersectsPage(masterPage, item)) continue; QByteArray name = QByteArray("/master_page_obj_%1_%2") - .replace("%1", Pdf::toPdf(mPageIndex)) - .replace("%2", Pdf::toPdf(qHash(ite))); - if (!ite->isTextContainer()) + .replace("%1", Pdf::toPdf(masterIndex + 1)) + .replace("%2", Pdf::toPdf(qHash(item))); + if (!item->isTextContainer()) { if (((layer.transparency != 1) || (layer.blendMode != 0)) && Options.supportsTransparency()) content += (name + " Do\n"); @@ -3825,21 +3826,22 @@ continue; } - double oldX = ite->xPos(); - double oldY = ite->yPos(); - double oldBX = ite->BoundingX; - double oldBY = ite->BoundingY; - ite->setXPos(ite->xPos() - mPage->xOffset() + pag->xOffset(), true); - ite->setYPos(ite->yPos() - mPage->yOffset() + pag->yOffset(), true); - if (!PDF_ProcessItem(output, ite, pag, pag->pageNr())) + double oldX = item->xPos(); + double oldY = item->yPos(); + double oldBX = item->BoundingX; + double oldBY = item->BoundingY; + item->setXPos(item->xPos() - masterPage->xOffset() + pag->xOffset(), true); + item->setYPos(item->yPos() - masterPage->yOffset() + pag->yOffset(), true); + const bool processed = PDF_ProcessItem(output, item, pag, pag->pageNr()); + item->setXYPos(oldX, oldY, true); + item->BoundingX = oldBX; + item->BoundingY = oldBY; + if (!processed) return false; if (((layer.transparency != 1) || (layer.blendMode != 0)) && Options.supportsTransparency()) content += output; else PutPage(output); - ite->setXYPos(oldX, oldY, true); - ite->BoundingX = oldBX; - ite->BoundingY = oldBY; } // Couldn't we use Write_TransparencyGroup() here? if (((layer.transparency != 1) || (layer.blendMode != 0)) && Options.supportsTransparency()) @@ -3855,9 +3857,9 @@ QByteArray ShName = ResNam + QByteArray::number(ResCount); ResCount++; Transpar[ShName] = writeGState("/CA " + FToStr(layer.transparency) + "\n" - + "/ca " + FToStr(layer.transparency) + "\n" - + "/SMask /None\n/AIS false\n/OPM 1\n" - + "/BM /" + blendMode(layer.blendMode) + "\n"); + + "/ca " + FToStr(layer.transparency) + "\n" + + "/SMask /None\n/AIS false\n/OPM 1\n" + + "/BM /" + blendMode(layer.blendMode) + "\n"); PdfId formObject = writer.newObject(); writer.startObj(formObject); PutDoc("<<\n/Type /XObject\n/Subtype /Form\n/FormType 1\n"); @@ -3885,7 +3887,8 @@ } if (Options.exportsLayers()) PutPage("EMC\n"); - + if (clipLogicalSpread) + PutPage("Q\n"); return true; } @@ -6091,6 +6094,26 @@ return tmp; } +bool PDFLibCore::masterItemIntersectsPage(const ScPage* page, const PageItem* item) const +{ + double bleedLeft = 0.0; + double bleedRight = 0.0; + double bleedBottom = 0.0; + double bleedTop = 0.0; + getBleeds(page, bleedLeft, bleedRight, bleedBottom, bleedTop); + + const QRectF pageRect(page->xOffset() - bleedLeft, + page->yOffset() - bleedTop, + page->width() + bleedLeft + bleedRight, + page->height() + bleedBottom + bleedTop); + const double lineWidth = item->visualLineWidth(); + const QRectF itemRect(item->BoundingX - lineWidth / 2.0, + item->BoundingY - lineWidth / 2.0, + item->BoundingW + lineWidth, + item->BoundingH + lineWidth); + return itemRect.intersects(pageRect); +} + void PDFLibCore::getBleeds(const ScPage* page, double &left, double &right) const { MarginStruct values; Index: scribus/pdflib_core.h =================================================================== --- scribus/pdflib_core.h (revision 27864) +++ scribus/pdflib_core.h (working copy) @@ -223,6 +223,7 @@ QByteArray Write_TransparencyGroup(double trans, int blend, QByteArray &data, const PageItem *controlItem = 0); QByteArray setTextSt(PageItem *ite, uint PNr, const ScPage* pag); + bool masterItemIntersectsPage(const ScPage* page, const PageItem* item) const; void getBleeds(const ScPage* page, double &left, double &right) const; void getBleeds(const ScPage* page, double &left, double &right, double &bottom, double& top) const; Index: scribus/plugins/export/svgexplugin/svgexplugin.cpp =================================================================== --- scribus/plugins/export/svgexplugin/svgexplugin.cpp (revision 27864) +++ scribus/plugins/export/svgexplugin/svgexplugin.cpp (working copy) @@ -257,10 +257,11 @@ m_Doc->Layers.levelToLayer(ll, la); if (ll.isPrintable) { - page = m_Doc->MasterPages.at(m_Doc->MasterNames[m_Doc->currentPage()->masterPageName()]); - processPageLayer(page, ll); page = m_Doc->currentPage(); - processPageLayer(page, ll); + const int masterIndex = m_Doc->appliedMasterPageIndex(page); + if (masterIndex >= 0) + processPageLayer(m_Doc->MasterPages.at(masterIndex), ll, page); + processPageLayer(page, ll, page); } } if(Options.compressFile) @@ -291,16 +292,15 @@ return true; } -void SVGExPlug::processPageLayer(ScPage *page, const ScLayer& layer) +void SVGExPlug::processPageLayer(ScPage *page, const ScLayer& layer, const ScPage* outputPage) { QDomElement layerGroup; - PageItem *item; QList items; ScPage* SavedAct = m_Doc->currentPage(); if (page->pageNameEmpty()) items = m_Doc->DocItems; else - items = m_Doc->MasterItems; + items = m_Doc->masterItemsForMasterPage(page); if (items.isEmpty()) return; if (!layer.isPrintable) @@ -313,24 +313,33 @@ layerGroup.setAttribute("inkscape:groupmode", "layer"); if (layer.transparency != 1.0) layerGroup.setAttribute("opacity", FToStr(layer.transparency)); - for (int j = 0; j < items.count(); ++j) + + // True-spread master items are emitted in target-page coordinates; keep only this physical output page. + const bool clipMasterSpread = !page->pageNameEmpty() && m_Doc->isMasterSpread(page->masterPageId()); + if (clipMasterSpread && outputPage) + { + const QString clipId = "Clip" + IToStr(m_clipCount++); + QDomElement clipPath = m_domDoc.createElement("clipPath"); + clipPath.setAttribute("id", clipId); + clipPath.setAttribute("clipPathUnits", "userSpaceOnUse"); + QDomElement clipRect = m_domDoc.createElement("rect"); + clipRect.setAttribute("x", "0"); + clipRect.setAttribute("y", "0"); + clipRect.setAttribute("width", FToStr(outputPage->width())); + clipRect.setAttribute("height", FToStr(outputPage->height())); + clipPath.appendChild(clipRect); + m_globalDefs.appendChild(clipPath); + layerGroup.setAttribute("clip-path", "url(#" + clipId + ")"); + } + + const QRectF pageRect(page->xOffset(), page->yOffset(), page->width(), page->height()); + for (PageItem* item : items) { - item = items.at(j); if (item->m_layerID != layer.ID) continue; if (!item->printEnabled()) continue; - double x = page->xOffset(); - double y = page->yOffset(); - double w = page->width(); - double h = page->height(); - double x2 = item->BoundingX; - double y2 = item->BoundingY; - double w2 = item->BoundingW; - double h2 = item->BoundingH; - if (!(qMax(x, x2) <= qMin(x + w, x2 + w2) && qMax(y, y2) <= qMin(y + h, y2 + h2))) - continue; - if ((!page->pageNameEmpty()) && (item->OwnPage != page->pageNr()) && (item->OwnPage != -1)) + if (!pageRect.intersects(item->getVisualBoundingRect())) continue; processItemOnPage(item->xPos()-page->xOffset(), item->yPos()-page->yOffset(), item, &layerGroup); } Index: scribus/plugins/export/svgexplugin/svgexplugin.h =================================================================== --- scribus/plugins/export/svgexplugin/svgexplugin.h (revision 27864) +++ scribus/plugins/export/svgexplugin/svgexplugin.h (working copy) @@ -91,7 +91,7 @@ \brief Process a page to export to SVG format \param Seite Page * */ - void processPageLayer(ScPage *page, const ScLayer& layer); + void processPageLayer(ScPage *page, const ScLayer& layer, const ScPage* outputPage); void processItemOnPage(double xOffset, double yOffset, PageItem *Item, QDomElement *parentElem); void paintBorder(const TableBorder& border, const QPointF& start, const QPointF& end, const QPointF& startOffsetFactors, const QPointF& endOffsetFactors, QDomElement &ob); QString processDropShadow(const PageItem *Item); Index: scribus/plugins/export/xpsexport/xpsexplugin.cpp =================================================================== --- scribus/plugins/export/xpsexport/xpsexplugin.cpp (revision 27864) +++ scribus/plugins/export/xpsexport/xpsexplugin.cpp (working copy) @@ -360,22 +360,22 @@ m_Doc->Layers.levelToLayer(ll, i); if (ll.isPrintable) { - ScPage *mpage = m_Doc->MasterPages.at(m_Doc->MasterNames[Page->masterPageName()]); - writePageLayer(doc_root, rel_root, mpage, ll); - writePageLayer(doc_root, rel_root, Page, ll); + const int masterIndex = m_Doc->appliedMasterPageIndex(Page); + if (masterIndex >= 0) + writePageLayer(doc_root, rel_root, m_Doc->MasterPages.at(masterIndex), ll, Page); + writePageLayer(doc_root, rel_root, Page, ll, Page); } } } -void XPSExPlug::writePageLayer(QDomElement &doc_root, QDomElement &rel_root, ScPage *page, ScLayer& layer) +void XPSExPlug::writePageLayer(QDomElement &doc_root, QDomElement &rel_root, ScPage *page, ScLayer& layer, const ScPage* outputPage) { - PageItem *item; QList items; ScPage* SavedAct = m_Doc->currentPage(); if (page->pageNameEmpty()) items = m_Doc->DocItems; else - items = m_Doc->MasterItems; + items = m_Doc->masterItemsForMasterPage(page); if (items.count() == 0) return; if (!layer.isPrintable) @@ -384,25 +384,26 @@ QDomElement layerGroup = p_docu.createElement("Canvas"); if (layer.transparency != 1.0) layerGroup.setAttribute("Opacity", layer.transparency); - for (int j = 0; j < items.count(); ++j) + + // True-spread master items are emitted in target-page coordinates; keep only this physical output page. + const bool clipMasterSpread = !page->pageNameEmpty() && m_Doc->isMasterSpread(page->masterPageId()); + if (clipMasterSpread && outputPage) + { + const double clipWidth = outputPage->width() * conversionFactor; + const double clipHeight = outputPage->height() * conversionFactor; + const QString clipPath = QString("F 1 M0,0 L%1,0 L%1,%2 L0,%2 Z") + .arg(FToStr(clipWidth)).arg(FToStr(clipHeight)); + layerGroup.setAttribute("Clip", clipPath); + } + + const QRectF pageRect(page->xOffset(), page->yOffset(), page->width(), page->height()); + for (PageItem* item : items) { - item = items.at(j); if (item->m_layerID != layer.ID) continue; if (!item->printEnabled()) continue; - double x = page->xOffset(); - double y = page->yOffset(); - double w = page->width(); - double h = page->height(); - double lw = item->visualLineWidth(); - double x2 = item->BoundingX - lw / 2.0; - double y2 = item->BoundingY - lw / 2.0; - double w2 = item->BoundingW + lw; - double h2 = item->BoundingH + lw; - if (!QRectF(x2, y2, w2, h2).intersects(QRectF(x, y, w, h))) - continue; - if ((!page->pageNameEmpty()) && (item->OwnPage != static_cast(page->pageNr())) && (item->OwnPage != -1)) + if (!pageRect.intersects(item->getVisualBoundingRect())) continue; writeItemOnPage(item->xPos() - page->xOffset(), item->yPos() - page->yOffset(), item, layerGroup, rel_root); } Index: scribus/plugins/export/xpsexport/xpsexplugin.h =================================================================== --- scribus/plugins/export/xpsexport/xpsexplugin.h (revision 27864) +++ scribus/plugins/export/xpsexport/xpsexplugin.h (working copy) @@ -84,7 +84,7 @@ private: void writePages(QDomElement &root); void writePage(QDomElement &doc_root, QDomElement &rel_root, ScPage *Page); - void writePageLayer(QDomElement &doc_root, QDomElement &rel_root, ScPage *page, ScLayer& layer); + void writePageLayer(QDomElement &doc_root, QDomElement &rel_root, ScPage *page, ScLayer& layer, const ScPage* outputPage); void writeItemOnPage(double xOffset, double yOffset, PageItem *Item, QDomElement &parentElem, QDomElement &rel_root); void handleImageFallBack(PageItem *Item, QDomElement &parentElem, QDomElement &rel_root); void processPolyItem(double xOffset, double yOffset, PageItem *Item, QDomElement &parentElem, QDomElement &rel_root); Index: scribus/pslib.cpp =================================================================== --- scribus/pslib.cpp (revision 27864) +++ scribus/pslib.cpp (working copy) @@ -701,7 +701,9 @@ progressDialog->setProgress("EMP", ap); QCoreApplication::processEvents(); } - if (m_Doc->MasterItems.count() <= 0) + ScPage* masterPage = m_Doc->MasterPages.at(ap); + const QList masterItems = m_Doc->masterItemsForMasterPage(masterPage); + if (masterItems.isEmpty()) continue; ScLayer ll; @@ -712,35 +714,23 @@ m_Doc->Layers.levelToLayer(ll, layerLevel); if (!ll.isPrintable) continue; - for (int api = 0; api < m_Doc->MasterItems.count() && !abortExport; ++api) + for (PageItem* item : masterItems) { - PageItem *it = m_Doc->MasterItems.at(api); + if (abortExport) + break; if (progressDialog) QCoreApplication::processEvents(); - if ((it->m_layerID != ll.ID) || (!it->printEnabled())) - continue; - double bLeft, bRight, bBottom, bTop; - GetBleeds(m_Doc->MasterPages.at(ap), bLeft, bRight, bBottom, bTop); - double x1 = m_Doc->MasterPages.at(ap)->xOffset() - bLeft; - double y1 = m_Doc->MasterPages.at(ap)->yOffset() - bTop; - double w1 = m_Doc->MasterPages.at(ap)->width() + bLeft + bRight; - double h1 = m_Doc->MasterPages.at(ap)->height()+ bBottom + bTop; - double lw = it->visualLineWidth(); - double x2 = it->BoundingX - lw / 2.0; - double y2 = it->BoundingY - lw / 2.0; - double w2 = qMax(it->BoundingW + lw, 1.0); - double h2 = qMax(it->BoundingH + lw, 1.0); - if (!QRectF(x2, y2, w2, h2).intersects(QRectF(x1, y1, w1, h1))) + if ((item->m_layerID != ll.ID) || (!item->printEnabled())) continue; - if ((it->OwnPage != m_Doc->MasterPages.at(ap)->pageNr()) && (it->OwnPage != -1)) + if (!masterItemIntersectsPage(masterPage, item)) continue; - if ((m_optimization == OptimizeSize) && it->isImageFrame() && it->imageIsAvailable && (!it->Pfile.isEmpty()) && it->printEnabled() && (!Options.outputSeparations) && Options.useColor) + if ((m_optimization == OptimizeSize) && item->isImageFrame() && item->imageIsAvailable && (!item->Pfile.isEmpty()) && item->printEnabled() && (!Options.outputSeparations) && Options.useColor) { - errorOccured = !PS_ImageData(it, it->Pfile, it->itemName(), it->ImageProfile, it->UseEmbedded); + errorOccured = !PS_ImageData(item, item->Pfile, item->itemName(), item->ImageProfile, item->UseEmbedded); if (errorOccured) break; } - PS_TemplateStart(QString("mp_obj_%1_%2").arg(ap).arg(qHash(it))); - ProcessItem(m_Doc->MasterPages.at(ap), it, ap+1, true); + PS_TemplateStart(QString("mp_obj_%1_%2").arg(ap).arg(qHash(item))); + ProcessItem(masterPage, item, ap+1, true); PS_TemplateEnd(); } if (errorOccured) break; @@ -1761,7 +1751,7 @@ m_Doc->Layers.levelToLayer(ll, lam); if (!ll.isPrintable) continue; - if (!page->masterPageNameEmpty() && !abortExport && !errorOccured) + if ((m_Doc->appliedMasterPageIndex(page) >= 0) && !abortExport && !errorOccured) { errorOccured |= !ProcessMasterPageLayer(page, ll, a + 1); } @@ -2647,97 +2637,128 @@ if (!layer.isPrintable) return true; - ScPage* mPage = m_Doc->MasterPages.at(m_Doc->MasterNames.value(page->masterPageName())); - for (int am = 0; am < page->FromMaster.count() && !abortExport; ++am) + const int masterIndex = m_Doc->appliedMasterPageIndex(page); + if (masterIndex < 0) + return true; + ScPage* masterPage = m_Doc->MasterPages.at(masterIndex); + const QList masterItems = m_Doc->masterItemsForAppliedPage(page); + if (masterItems.isEmpty()) + return true; + + const bool clipLogicalSpread = m_Doc->isMasterSpread(masterPage->masterPageId()); + if (clipLogicalSpread) + { + double bleedLeft = 0.0; + double bleedRight = 0.0; + double bleedBottom = 0.0; + double bleedTop = 0.0; + GetBleeds(page, bleedLeft, bleedRight, bleedBottom, bleedTop); + const double clipLeft = -bleedLeft; + const double clipRight = page->width() + bleedRight; + PS_save(); + PS_moveto(clipLeft, -bleedBottom); + PS_lineto(clipRight, -bleedBottom); + PS_lineto(clipRight, page->height() + bleedTop); + PS_lineto(clipLeft, page->height() + bleedTop); + PS_closepath(); + PS_clip(false); + } + + for (PageItem* item : masterItems) { - PageItem *ite = page->FromMaster.at(am); + if (abortExport) + break; if (progressDialog) QCoreApplication::processEvents(); - if ((ite->m_layerID != layer.ID) || (!ite->printEnabled())) + if ((item->m_layerID != layer.ID) || (!item->printEnabled())) continue; - if (!ite->isTextContainer()) + if (!item->isTextContainer()) { - int mpIndex = m_Doc->MasterNames.value(page->masterPageName()); - PS_UseTemplate(QString("mp_obj_%1_%2").arg(mpIndex).arg(qHash(ite))); + // Template setup culls items that do not touch this physical master half. + // Apply the same test here so a projected spread never references a + // template that was intentionally not generated for the target half. + if (!masterItemIntersectsPage(masterPage, item)) + continue; + PS_UseTemplate(QString("mp_obj_%1_%2").arg(masterIndex).arg(qHash(item))); } - else if (!ite->isTextFrame()) + else if (!item->isTextFrame()) { PS_save(); // JG : replace what seems mostly duplicate code by corresponding function call (#3936) - success &= ProcessItem(mPage, ite, PNr, false, false, true); + success &= ProcessItem(masterPage, item, PNr, false, false, true); PS_restore(); } - else // if (ite->isTextFrame()) + else // if (item->isTextFrame()) { PS_save(); - if (ite->doOverprint) + if (item->doOverprint) { PutStream("true setoverprint\n"); PutStream("true setoverprintmode\n"); } - if (ite->fillColor() != CommonStrings::None) + if (item->fillColor() != CommonStrings::None) { - SetColor(ite->fillColor(), ite->fillShade(), &h, &s, &v, &k); + SetColor(item->fillColor(), item->fillShade(), &h, &s, &v, &k); PS_setcmykcolor_fill(h, s, v, k); } - PS_translate(ite->xPos() - mPage->xOffset(), mPage->height() - (ite->yPos() - mPage->yOffset())); - if (ite->rotation() != 0) - PS_rotate(-ite->rotation()); - if ((ite->fillColor() != CommonStrings::None) || (ite->GrType != 0)) + PS_translate(item->xPos() - masterPage->xOffset(), masterPage->height() - (item->yPos() - masterPage->yOffset())); + if (item->rotation() != 0) + PS_rotate(-item->rotation()); + if ((item->fillColor() != CommonStrings::None) || (item->GrType != 0)) { - SetClipPath(ite->PoLine); + SetClipPath(item->PoLine); PS_closepath(); - if (ite->GrType == Gradient_Hatch) - PS_HatchFill(ite); - else if (ite->GrType != 0) - HandleGradientFillStroke(ite, false); + if (item->GrType == Gradient_Hatch) + PS_HatchFill(item); + else if (item->GrType != 0) + HandleGradientFillStroke(item, false); else - putColor(ite->fillColor(), ite->fillShade(), true); + putColor(item->fillColor(), item->fillShade(), true); } - if (ite->imageFlippedH()) + if (item->imageFlippedH()) { - PS_translate(ite->width(), 0); + PS_translate(item->width(), 0); PS_scale(-1, 1); } - if (ite->imageFlippedV()) + if (item->imageFlippedV()) { - PS_translate(0, -ite->height()); + PS_translate(0, -item->height()); PS_scale(1, -1); } - if (ite->itemText.length() != 0) - setTextSt(ite, PNr - 1, mPage, true); - if ((ite->lineColor() != CommonStrings::None) || (!ite->NamedLStyle.isEmpty()) || (!ite->strokePattern().isEmpty()) || (ite->GrTypeStroke > 0)) - { - PS_setlinewidth(ite->lineWidth()); - PS_setcapjoin(ite->PLineEnd, ite->PLineJoin); - PS_setdash(ite->PLineArt, ite->DashOffset, ite->DashValues); - if (ite->NamedLStyle.isEmpty()) // && (ite->lineWidth() != 0.0)) + if (item->itemText.length() != 0) + setTextSt(item, PNr - 1, masterPage, true); + if ((item->lineColor() != CommonStrings::None) || (!item->NamedLStyle.isEmpty()) || (!item->strokePattern().isEmpty()) || (item->GrTypeStroke > 0)) + { + PS_setlinewidth(item->lineWidth()); + PS_setcapjoin(item->PLineEnd, item->PLineJoin); + PS_setdash(item->PLineArt, item->DashOffset, item->DashValues); + if (item->NamedLStyle.isEmpty()) // && (item->lineWidth() != 0.0)) { - const ScPattern* strokePattern = m_Doc->checkedPattern(ite->strokePattern()); - if (strokePattern && (ite->patternStrokePath)) + const ScPattern* strokePattern = m_Doc->checkedPattern(item->strokePattern()); + if (strokePattern && (item->patternStrokePath)) { - QPainterPath path = ite->PoLine.toQPainterPath(false); - HandleBrushPattern(ite, path, page, PNr, true); + QPainterPath path = item->PoLine.toQPainterPath(false); + HandleBrushPattern(item, path, page, PNr, true); } else { - SetClipPath(ite->PoLine); + SetClipPath(item->PoLine); PS_closepath(); if (strokePattern) - HandleStrokePattern(ite); - else if (ite->GrTypeStroke > 0) - HandleGradientFillStroke(ite); - else if (ite->lineColor() != CommonStrings::None) + HandleStrokePattern(item); + else if (item->GrTypeStroke > 0) + HandleGradientFillStroke(item); + else if (item->lineColor() != CommonStrings::None) { - SetColor(ite->lineColor(), ite->lineShade(), &h, &s, &v, &k); + SetColor(item->lineColor(), item->lineShade(), &h, &s, &v, &k); PS_setcmykcolor_stroke(h, s, v, k); - putColor(ite->lineColor(), ite->lineShade(), false); + putColor(item->lineColor(), item->lineShade(), false); } } } else { - MultiLine ml = m_Doc->docLineStyles.value(ite->NamedLStyle); + MultiLine ml = m_Doc->docLineStyles.value(item->NamedLStyle); for (int it = ml.size() - 1; it > -1; it--) { if (ml[it].Color != CommonStrings::None) //&& (ml[it].Width != 0)) @@ -2747,7 +2768,7 @@ PS_setlinewidth(ml[it].Width); PS_setcapjoin(static_cast(ml[it].LineEnd), static_cast(ml[it].LineJoin)); PS_setdash(static_cast(ml[it].Dash), 0, dum); - SetClipPath(ite->PoLine); + SetClipPath(item->PoLine); PS_closepath(); putColor(ml[it].Color, ml[it].Shade, false); } @@ -2759,6 +2780,9 @@ if (!success) break; } + + if (clipLogicalSpread) + PS_restore(); return success; } @@ -4221,7 +4245,27 @@ } } -void PSLib::GetBleeds(ScPage* page, double& left, double& right) +bool PSLib::masterItemIntersectsPage(const ScPage* page, const PageItem* item) +{ + double bleedLeft = 0.0; + double bleedRight = 0.0; + double bleedBottom = 0.0; + double bleedTop = 0.0; + GetBleeds(page, bleedLeft, bleedRight, bleedBottom, bleedTop); + + const QRectF pageRect(page->xOffset() - bleedLeft, + page->yOffset() - bleedTop, + page->width() + bleedLeft + bleedRight, + page->height() + bleedBottom + bleedTop); + const double lineWidth = item->visualLineWidth(); + const QRectF itemRect(item->BoundingX - lineWidth / 2.0, + item->BoundingY - lineWidth / 2.0, + qMax(item->BoundingW + lineWidth, 1.0), + qMax(item->BoundingH + lineWidth, 1.0)); + return itemRect.intersects(pageRect); +} + +void PSLib::GetBleeds(const ScPage* page, double& left, double& right) { MarginStruct values; m_Doc->getBleeds(page, Options.bleeds, values); @@ -4229,7 +4273,7 @@ right = values.right(); } -void PSLib::GetBleeds(ScPage* page, double& left, double& right, double& bottom, double& top) +void PSLib::GetBleeds(const ScPage* page, double& left, double& right, double& bottom, double& top) { MarginStruct values; m_Doc->getBleeds(page, Options.bleeds, values); Index: scribus/pslib.h =================================================================== --- scribus/pslib.h (revision 27864) +++ scribus/pslib.h (working copy) @@ -137,8 +137,8 @@ virtual void drawArrow(PageItem *ite, QTransform &arrowTrans, int arrowIndex); virtual void putColor(const QString& color, double shade, bool fill); virtual void putColorNoDraw(const QString& color, double shade); - virtual void GetBleeds(ScPage* page, double& left, double& right); - virtual void GetBleeds(ScPage* page, double& left, double& right, double& bottom, double& top); + virtual void GetBleeds(const ScPage* page, double& left, double& right); + virtual void GetBleeds(const ScPage* page, double& left, double& right, double& bottom, double& top); virtual void SetClipPath(const FPointArray &points, bool poly = true); virtual void SetPathAndClip(const FPointArray &points, bool clipRule); virtual void HandleBrushPattern(PageItem *item, QPainterPath &path, ScPage* a, uint PNr, bool master); @@ -162,6 +162,7 @@ bool PutImageDataToStream(const QByteArray& image); bool PutInterleavedImageMaskToStream(const QByteArray& image, const QByteArray& mask, bool gray); + bool masterItemIntersectsPage(const ScPage* page, const PageItem* item); void WriteASCII85Bytes(const QByteArray& array); void WriteASCII85Bytes(const unsigned char* array, int length); Index: scribus/scpageoutput.cpp =================================================================== --- scribus/scpageoutput.cpp (revision 27864) +++ scribus/scpageoutput.cpp (working copy) @@ -101,22 +101,42 @@ void ScPageOutput::drawMasterItems(ScPainterExBase *painter, ScPage *page, const ScLayer& layer, const QRect& clip) { - if (page->masterPageNameEmpty()) + if (!layer.isViewable || !layer.isPrintable) return; - if (page->FromMaster.count() <= 0) + + const int masterIndex = m_doc->appliedMasterPageIndex(page); + if (masterIndex < 0) return; - if (!layer.isViewable || !layer.isPrintable) + const ScPage* masterPage = m_doc->MasterPages.at(masterIndex); + const QList masterItems = m_doc->masterItemsForAppliedPage(page); + if (masterItems.isEmpty()) return; - ScPage* masterPage = m_doc->MasterPages.at(m_doc->MasterNames[page->masterPageName()]); - int pageFromMasterCount = page->FromMaster.count(); - for (int i = 0; i < pageFromMasterCount; ++i) + const bool clipAtSpine = m_doc->isMasterSpread(masterPage->masterPageId()); + if (clipAtSpine) + { + QRectF projectionClip(QPointF(m_doc->minCanvasCoordinate.x(), m_doc->minCanvasCoordinate.y()), + QPointF(m_doc->maxCanvasCoordinate.x(), m_doc->maxCanvasCoordinate.y())); + projectionClip = projectionClip.normalized(); + if (masterPage->masterPageSide() == MasterPageSide::Left) + projectionClip.setRight(qMin(projectionClip.right(), page->xOffset() + page->width())); + else if (masterPage->masterPageSide() == MasterPageSide::Right) + projectionClip.setLeft(qMax(projectionClip.left(), page->xOffset())); + + painter->save(); + painter->newPath(); + painter->moveTo(projectionClip.left(), projectionClip.top()); + painter->lineTo(projectionClip.right(), projectionClip.top()); + painter->lineTo(projectionClip.right(), projectionClip.bottom()); + painter->lineTo(projectionClip.left(), projectionClip.bottom()); + painter->lineTo(projectionClip.left(), projectionClip.top()); + painter->setClipPath(); + } + + for (PageItem* currItem : masterItems) { - PageItem* currItem = page->FromMaster.at(i); if (currItem->m_layerID != layer.ID) continue; - if ((currItem->OwnPage != -1) && (currItem->OwnPage != masterPage->pageNr())) - continue; if (!currItem->printEnabled()) continue; int savedOwnPage = currItem->OwnPage; @@ -142,6 +162,9 @@ currItem->BoundingY = OldBY; } } + + if (clipAtSpine) + painter->restore(); } void ScPageOutput::drawPageItems(ScPainterExBase *painter, ScPage *page, const ScLayer& layer, const QRect& clip) Index: scribus/scribusdoc.cpp =================================================================== --- scribus/scribusdoc.cpp (revision 27864) +++ scribus/scribusdoc.cpp (working copy) @@ -3018,13 +3018,29 @@ if (masterId.isNull() || !isMasterSpread(masterId)) return page->FromMaster; - // Keep FromMaster owner-based for existing output paths. Canvas projections need - // the complete logical spread; the target half is selected by spine clipping. + return masterItemsForMasterPage(masterPage); +} + +QList ScribusDoc::masterItemsForMasterPage(const ScPage* masterPage) const +{ + QList items; + if (!masterPage) + return items; + + const QUuid masterId = masterPage->masterPageId(); + const bool logicalSpread = !masterId.isNull() && isMasterSpread(masterId); for (PageItem* item : std::as_const(MasterItems)) { - const bool sameLogicalMaster = (!item->masterPageId().isNull() && item->masterPageId() == masterId) - || (item->masterPageId().isNull() && item->OnMasterPage == masterPage->pageName()); - if (sameLogicalMaster) + if (logicalSpread) + { + const bool sameLogicalMaster = (!item->masterPageId().isNull() && item->masterPageId() == masterId) + || (item->masterPageId().isNull() && item->OnMasterPage == masterPage->pageName()); + if (sameLogicalMaster) + items.append(item); + continue; + } + + if (item->OwnPage == masterPage->pageNr() || item->OwnPage == -1) items.append(item); } return items; Index: scribus/scribusdoc.h =================================================================== --- scribus/scribusdoc.h (revision 27864) +++ scribus/scribusdoc.h (working copy) @@ -276,6 +276,8 @@ bool isMasterSpread(const QUuid& masterId) const; int appliedMasterPageIndex(const ScPage* page) const; QList masterItemsForAppliedPage(const ScPage* page) const; + //! Returns physical-master items for a normal master, or all items in the logical spread for a true-spread half. + QList masterItemsForMasterPage(const ScPage* masterPage) const; MasterPageSide matchingMasterPageSide(const QUuid& masterId, int pageNumber) const; bool documentSpreadPages(int pageNumber, int& leftPage, int& rightPage) const; void preserveMasterPageMarginsForLayoutChange(int oldPagePositioning);